webpack-post-compile-plugin
raw JSON → 1.2.3 verified Sat May 09 auth: no javascript
A webpack plugin that post-compiles specified node_modules packages (e.g., those listed in `compileDependencies` or marked with `postCompile`) using the same loaders as your application source, enabling trasformation of dependencies like Babel or TypeScript. Version 1.2.3 is current; active development with infrequent releases. Compared to alternatives like `webpack-loader`, it uses `package.json` config to declare which packages need post-compilation, supporting micromatch patterns (>=1.0.0) and multiple configuration methods. Requires Webpack >=3.
Common errors
error Error: Cannot find module 'micromatch' ↓
cause Micromatch is a dependency of the plugin but may not be installed if npm deduplicates or if the package is missing.
fix
Run
npm install micromatch@^4.0.0 or reinstall the package. error Module not found: Error: Can't resolve 'some-module' ↓
cause Loader is not processing the node_modules package because the loader rule excludes node_modules.
fix
Adjust the loader rule to include the package:
include: [path.resolve(__dirname, 'node_modules/some-module')]. error TypeError: PostCompilePlugin is not a constructor ↓
cause Using `PostCompilePlugin()` without `new` or importing incorrectly.
fix
Use
new PostCompilePlugin(). Warnings
breaking Version 1.0.0 changed `postCompile` option from boolean to string/array patterns using micromatch. Existing configs using `true` still work but pattern matching behavior may differ. ↓
fix Update config to use micromatch patterns if needed, or keep boolean `true`.
deprecated Options `dependencies` and `dependenciesKey` may be deprecated in future versions; prefer `compileDependencies`. ↓
fix Use `compileDependencies` or `compilePaths` options.
gotcha The plugin does not automatically exclude node_modules from loaders; you must configure the loader rule to include the post-compiled packages. ↓
fix Use a positive `include` pattern in the loader rule that matches the packages you want to compile (e.g., include the app directory and then exclude only non-post-compile node_modules).
gotcha The plugin only processes packages that are direct dependencies of your app, not transitive dependencies, unless they also have `postCompile` or are listed in `compileDependencies`. ↓
fix List all transitive dependencies that need post-compilation in `compileDependencies` or ensure they have `postCompile` in their package.json.
Install
npm install webpack-post-compile-plugin yarn add webpack-post-compile-plugin pnpm add webpack-post-compile-plugin Imports
- PostCompilePlugin wrong
import PostCompilePlugin from 'webpack-post-compile-plugin'correctconst PostCompilePlugin = require('webpack-post-compile-plugin') - PostCompilePlugin
const PostCompilePlugin = require('webpack-post-compile-plugin').default - PostCompilePlugin wrong
PostCompilePlugin()correctnew PostCompilePlugin({ /* options */ })
Quickstart
// webpack.config.js
const PostCompilePlugin = require('webpack-post-compile-plugin');
const path = require('path');
module.exports = {
entry: './src/index.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules\/(?!your-pkg)/,
use: {
loader: 'babel-loader'
}
}
]
},
plugins: [
new PostCompilePlugin({
compileDependencies: ['your-pkg']
})
]
};
// In package.json of your-pkg: { "postCompile": true }