parallelize-webpack-unplugin
v0.1.2
Published
Use unplugin with thread-loader in webpack
Downloads
9
Maintainers
Readme
parallelize-webpack-unplugin
Use unplugin with thread-loader in webpack.
Why You Need It
Many unplugin-based plugins will prompt you that they do not support use with thread-loaders
(sometimes reflected in the parallel
configuration of the Vue CLI). For example:
unplugin-vue2-script-setup
unplugin-vue-macros
, also known as@vue-macros/reactivity-transform
thread-loader
explains this. Since the loaders need to be executed within the worker process, it is not possible to access the compiler instance as with the loader which unplugin is injecting.
This module supports the conversion of unplugin-based plugins that satisfy the constraints into a form that supports thread-loader
. Specifically:
- The plugin is instantiated without side effects, i.e. the return value of the function passed to
createUnplugin
avoids the use of closure variables - The plugin does not rely on metadata in the context during instantiation, rather
meta.webpack.compiler
loadInclude
andtransformInclude
only determine the moduleid
, ignoringresourceQuery
loadInclude
andtransformInclude
cannot include external modules
Most plugins satisfy the above conditions and can therefore be transformed.
Usage
npm i -D parallelize-webpack-unplugin
This module exports a parallelize
method for converting unplugin-based plugins:
const { parallelize } = require('parallelize-webpack-unplugin')
// To get a new unplugin plugin
parallelize('/path/to/my-unplugin-plugin')
You can just
// webpack.config.js
- const { default: MyUnpluginPlugin } = require('/path/to/my-unplugin-plugin/webpack')
module.exports = {
plugins: [
- MyUnpluginPlugin(options),
+ parallelize('/path/to/my-unplugin-plugin')(options),
],
}