v1.2: spack: Yet another asset bundler
#
Features#
Compact outputJust like rollup, spack emits compact output.
a.js
:
lib.js
becomes
Because swc
was designed with this type of merging in mind, files are merged without any problems even if the same name exists in multiple files.
#
Tree shakingJust like other modern bundlers, spack
can remove unused exports.
#
Import deglobbingTo aid tree shaking, spack
deglobs import if possible.
behaves exactly same as
Note that all side effects are preserved.
#
Common js supportAs almost all modules on npm are published as common js module, spack supports importing common js module. Also, spack emits compact output compared to webpack.
If the lib
above is common js module, it's transcompiled as
#
OptimizationsCurrently swc
does
- global inlining (e.g.
process.env.NODE_ENV
) - inlining
- constant propagation
- dead code elimination
Actually the tree shaking described above is implemented using the dead code elimination pass. Currently, spack / swc can deduce
into
#
High performanceAs always, performance is a first-class citizen. It's very fast because it uses all cpu cores, and optimized by llvm.
#
swc integrationYou can use es2018, module import / export-s and some staged proposals without installing any additional dependency.
#
Multiple entriesspack.config.js
:
#
Built-in chunkingLet's suppose that we have the same config as above. If android.ts
and web.ts
both references a file, it will be extracted as a separate chunk and web.ts
and amdroid.ts
will import it.
#
Type annotation for config filespack
provides type annotations for the config. You can get assists from ide just by wrappping your configuration object with config
. Note that it's just an identity function with type annoatations.
spack.config.js
:
#
Fine configIf you want to bundle everything in each bundle, you can provide an array of configurations.
e.g.
results in two full bundle (desktop.js
, mobile.js
), while
results in chunking. In this case, the output will be desktop.js
, mobile.js
, common-[hash].js
, assuming there's a common dependency.
#
Roadmap (spack)#
webpack-compatible plugin apispack will provide webpack-compatible apis, so you will be able to use webpack loaders and plugins without changing the plugin. All you need to do will be changing file name and imports.
I couldn't implement this because currently there's no way to wait for a promise to be resolved from rust code. I'll implement this feature as soon as possible after neon#73 or node-bidgen#37 is fixed. (I'm open to switchig from neon to node-bindgen).
#
dynamic imports (and code splitting)#826)#
minification (I think this is one of the core features of a bundler. I'll implement it soon.