Skip to content

Latest commit

 

History

History

plugin-rspack

Folders and files

README.md

@putout/plugin-rspack NPM version

🐊Putout plugin to convert webpack.config.js to rspack. Not bundled.

Renamed to @putout/plugin-rspack.

Install

npm i putout @putout/plugin-rspack -D

Rules

Config

{
    "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.

❌ Example of incorrect code

export default {
    module: {
        rules: [{
            test: /\.(png|gif|svg)$/,
            use: {
                loader: 'url-loader',
                options: {
                    limit: 50_000,
                },
            },
        }],
    },
};

✅ Example of correct code

export default {
    module: {
        rules: [{
            test: /\.(png|gif|svg)$/,
            type: 'asset',
            parser: {
                dataUrlCondition: {
                    maxSize: 50_000,
                },
            },
        }],
    },
};

apply-global-define

Checkout in 🐊Putout Editor.

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

export default {
    entry: './client/index.js',
};

✅ Example of correct code

import {rspack} from '@rspack/core';

export default {
    entry: './client/index.js',
    plugins: [
        new rspack.DefinePlugin({
            global: 'globalThis',
        }),
    ],
};

apply-library-object

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

export default {
    output: {
        library: 'Deepword',
        libraryTarget: 'var',
        libraryExport: 'default',
    },
};

✅ Example of correct code

export default {
    output: {
        library: {
            name: 'Deepword',
            type: 'var',
            export: 'default',
        },
    },
};

apply-rspack-import

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

import webpack from 'webpack';

const {EnvironmentPlugin} = webpack;

✅ Example of correct code

import {rspack} from '@rspack/core';

const {EnvironmentPlugin} = rspack;

apply-swc-loader

Checkout in 🐊Putout Editor.

❌ Example of incorrect code

export default {
    module: {
        rules: [{
            test: /\.js$/,
            loader: 'babel-loader',
        }],
    },
};

✅ Example of correct code

export default {
    module: {
        rules: [{
            test: /\.js$/,
            loader: 'builtin:swc-loader',
            options: {
                jsc: {
                    parser: {
                        syntax: 'ecmascript',
                    },
                },
                env: {
                    targets: 'defaults',
                },
            },
        }],
    },
};

remove-webpackbar

❌ Example of incorrect code

import WebpackBar from 'webpackbar';

export default {
    plugins: [new WebpackBar()],
};

✅ Example of correct code

export default {
    plugins: [],
};

License

MIT