babel-transform-webpack-plugin
Version:
A webpack plugin to transform javascript chunks using babel.
63 lines (46 loc) • 2.13 kB
Markdown
[](https://996.icu/#/en_US)
[](https://github.com/996icu/996.ICU/blob/master/LICENSE)

[](https://badge.fury.io/js/babel-transform-webpack-plugin)
A Webpack plugin to transform javascript chunk with `Babel@7` and it compatible with `webpack@5` and `webpack@4`.
- `babel-loader` is a loader, it will transform the file before it is passed to the next loader.
- `babel-transform-webpack-plugin` is a plugin, it will transform the javascript chunk that is bundled by the webpack.
If you want to transform the javascript chunk after it is bundled by the webpack, you can use this plugin.
eg. you want to use `babel-plugin-transform-fs-promises` to transform the final javascript chunk to use `require('fs').promises` instead of `require('fs/promises')` in the final bundle.
```bash
npm install @babel/core babel-transform-webpack-plugin --save
```
```js
// import via esm
import { BabelTransformPlugin } from "babel-transform-webpack-plugin";
// import via cjs
const { BabelTransformPlugin } = require("babel-transform-webpack-plugin");
```
```js
const { BabelTransformPlugin } = require("babel-transform-webpack-plugin");
/** @type {import('webpack').Configuration} */
module.exports = {
plugins: [
// only use babel-transform-webpack-plugin in production for better performance
// you can use it in development if you want to debug the code
// but it will slow down the build process
process.env.NODE_ENV === "production"
? new BabelTransformPlugin({
transformOptions: {
plugins: [
// your babel plugins
],
},
})
: undefined,
// ... other plugins
].filter(Boolean),
};
```
The [Anti 996 License](LICENSE)