When using rspack with Lazy Compilation,
the CLI (rspack dev) correctly applies lazy compilation settings
However, when running the dev server programmatically via the API (new RspackDevServer(options, compiler)),
all Lazy Compilation settings appear to be ignored.
With lazyCompilation: true,
only index.html and main.js should be emitted on initial build.
Then its dynamic imports should compile on demand when the browser requests them.
Entry chunks & imports are all are compiled and emitted eagerly at startup, as if lazyCompilation were ignored.
This repo provides both multiCompiler and single-compiler configs, each with CLI and API scripts.
src/
index.js # app1 entry - dynamic import('./render.js')
app2.js # app2 entry - dynamic import('./render.js')
render.js # shared module (dynamically imported)
render.css # CSS imported by render.js
rspack.config.mjs # multiCompiler array config (app1 + app2)
rspack.config.single.mjs # single compiler config (app1 only)
dev-server.mjs # API dev server - multiCompiler
dev-server.single.mjs # API dev server - single compiler
An AssetEmitLogger plugin is included in both configs.
It hooks into compiler.hooks.assetEmitted and compiler.hooks.done to log when assets are written and when compilation finishes.
pnpm install| Script | Config | Method |
|---|---|---|
pnpm dev:cli |
multiCompiler | CLI |
pnpm dev:api |
multiCompiler | API |
pnpm dev:cli:single |
single compiler | CLI |
pnpm dev:api:single |
single compiler | API |
pnpm dev:cli:test |
single compiler using test option |
CLI |
pnpm dev:api:test |
single compiler using test option |
API |
All scripts start a dev server on port 3000. Stop one before starting another.
pnpm dev:cliWatch the terminal. With working lazy compilation, only index.html and main.js should be emitted on initial build:
● ━━━━━━━━━━━━━━━━━━━━━━━━━ (93%) sealing asset processing
● ━━━━━━━━━━━━━━━━━━━━━━━━━ (93%) sealing after asset optimization
[app1] asset emitted: index.html
● ━━━━━━━━━━━━━━━━━━━━━━━━━ (100%) emitting after emit
● ━━━━━━━━━━━━━━━━━━━━━━━━━ (98%) emitting emit
[app2] asset emitted: index.html
[app2] asset emitted: main.js
● ━━━━━━━━━━━━━━━━━━━━━━━━━ (100%) emitting after emit
● ━━━━━━━━━━━━━━━━━━━━━━━━━ (100%) emitting after emit
[app2] compilation finished in 64 ms
Dynamic imports (src_render_js.js, src_render_js.css) compile later when the browser requests them.
pnpm dev:apiWatch the terminal. All assets are emitted immediately at startup — entry compilation is not deferred:
[app1] asset emitted: index.html
[app1] asset emitted: src_render_js.js
[app1] asset emitted: src_render_js.css
[app1] asset emitted: main.js
[app2] asset emitted: index.html
[app2] asset emitted: src_render_js.css
[app2] asset emitted: src_render_js.js
[app2] asset emitted: main.js
[app1] compilation finished in 41 ms
[app2] compilation finished in 42 ms
The single-compiler variants (dev:cli:single / dev:api:single & dev:cli:test / dev:api:test) exhibit the same behavior.