# @putout/plugin-rspack [![NPM version][NPMIMGURL]][NPMURL] [NPMIMGURL]: https://img.shields.io/npm/v/@putout/plugin-rspack.svg?style=flat&longCache=true [NPMURL]: https://npmjs.org/package/@putout/plugin-rspack "npm" 🐊[**Putout**](https://github.com/coderaiser/putout) plugin to convert `webpack.config.js` to [rspack](https://rspack.dev). *Not bundled*. Renamed to [@putout/plugin-rspack](https://npmjs.org/package/@putout/plugin-rspack). ## Install ``` npm i putout @putout/plugin-rspack -D ``` ## Rules - ✅ [apply-asset-type](#apply-asset-type); - ✅ [apply-global-define](#apply-global-define); - ✅ [apply-library-object](#apply-library-object); - ✅ [apply-rspack-import](#apply-rspack-import); - ✅ [apply-swc-loader](#apply-swc-loader); - ✅ [remove-webpackbar](#remove-webpackbar); ## Config ```json { "rules": { "rspack/apply-asset-type": "on", "rspack/apply-global-define": "on", "rspack/apply-library-object": "on", "rspack/apply-rspack-import": "on", "rspack/apply-swc-loader": "on", "rspack/remove-webpackbar": "on" } } ``` ## apply-asset-type Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/6d4152d33dd67f39ef4a1d56769dc22b/a6d7b603f326717a462c01fb9568e4f989ca7af7). ### ❌ Example of incorrect code ```js export default { module: { rules: [{ test: /\.(png|gif|svg)$/, use: { loader: 'url-loader', options: { limit: 50_000, }, }, }], }, }; ``` ### ✅ Example of correct code ```js export default { module: { rules: [{ test: /\.(png|gif|svg)$/, type: 'asset', parser: { dataUrlCondition: { maxSize: 50_000, }, }, }], }, }; ``` ## apply-global-define Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/627e3b66b31f9490499dcd611b535db5/8c20fc89fbe02011c38ffb850486db0452ffdcfa). Webpack replaces `global` with the global object in browser bundles, `rspack` does not do it for ESM modules (`node.global` has no effect there), so a bundle that touches `global` throws `ReferenceError: global is not defined` in the browser. Use `DefinePlugin` to replace `global` with `globalThis`. Skipped for `target: 'node'`. ### ❌ Example of incorrect code ```js export default { entry: './client/index.js', }; ``` ### ✅ Example of correct code ```js import {rspack} from '@rspack/core'; export default { entry: './client/index.js', plugins: [ new rspack.DefinePlugin({ global: 'globalThis', }), ], }; ``` ## apply-library-object Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/c9b85da3e385d1c254f4103db8952323/1b7c7c9e8568bba9070469ced671c1dd5022bed3). ### ❌ Example of incorrect code ```js export default { output: { library: 'Deepword', libraryTarget: 'var', libraryExport: 'default', }, }; ``` ### ✅ Example of correct code ```js export default { output: { library: { name: 'Deepword', type: 'var', export: 'default', }, }, }; ``` ## apply-rspack-import Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/6af7c06cecb5e2b5717271dddd783fcf/fb2b92aa42bb5c1dadd2d5d5fb98ca06d2b6ee0d). ### ❌ Example of incorrect code ```js import webpack from 'webpack'; const {EnvironmentPlugin} = webpack; ``` ### ✅ Example of correct code ```js import {rspack} from '@rspack/core'; const {EnvironmentPlugin} = rspack; ``` ## apply-swc-loader Checkout in 🐊[**Putout Editor**](https://putout.cloudcmd.io/#/gist/d26a479c7f677bcfe74f9f946c514983/c88686d689396c1e47b22d8aee24e737eff7e24f). ### ❌ Example of incorrect code ```js export default { module: { rules: [{ test: /\.js$/, loader: 'babel-loader', }], }, }; ``` ### ✅ Example of correct code ```js export default { module: { rules: [{ test: /\.js$/, loader: 'builtin:swc-loader', options: { jsc: { parser: { syntax: 'ecmascript', }, }, env: { targets: 'defaults', }, }, }], }, }; ``` ## remove-webpackbar ### ❌ Example of incorrect code ```js import WebpackBar from 'webpackbar'; export default { plugins: [new WebpackBar()], }; ``` ### ✅ Example of correct code ```js export default { plugins: [], }; ``` ## License MIT