react-compiler-webpack
Version:
The webpack/Next.js Plugin for React Compiler
36 lines (33 loc) • 1.16 kB
JavaScript
;
const reactCompilerLoader = require.resolve('./react-compiler-loader');
const defineReactCompilerLoaderOption = (options)=>options;
function withReactCompiler(pluginOptions, ruleOptions = {}) {
return (nextConfig = {})=>{
const $ruleOptions = {
test: /\.(mtsx|mjsx|tsx|jsx)$/,
exclude: /node_modules/,
...ruleOptions
};
return {
...nextConfig,
webpack (config, ctx) {
if (typeof nextConfig.webpack === 'function') {
config = nextConfig.webpack(config, ctx);
}
config.module.rules.push({
...$ruleOptions,
use: [
{
loader: reactCompilerLoader,
options: pluginOptions
}
]
});
return config;
}
};
};
}
exports.defineReactCompilerLoaderOption = defineReactCompilerLoaderOption;
exports.reactCompilerLoader = reactCompilerLoader;
exports.withReactCompiler = withReactCompiler;