parallelize-webpack-unplugin
TypeScript icon, indicating that this package has built-in type declarations

0.1.2 • Public • Published

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:

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 and transformInclude only determine the module id, ignoring resourceQuery
  • loadInclude and transformInclude 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),
  ],
}

Package Sidebar

Install

npm i parallelize-webpack-unplugin

Weekly Downloads

30

Version

0.1.2

License

ISC

Unpacked Size

11.4 kB

Total Files

11

Last publish

Collaborators

  • cyansalt