-
I'm writing a Chrome extension with CRA and using CRACO to create separate .js files in the build for content scripts, service worker/background scripts, etc. I am able to output the files separately using the module.exports = {
webpack: {
configure: (webpackConfig, { env, paths }) => {
return {
...webpackConfig,
entry: {
main: [
env === 'development' && require.resolve('react-dev-utils/webpackHotDevClient'),
paths.appIndexJs,
].filter(Boolean),
content: './src/chromeServices/domBootstrap.ts',
background: './src/chromeServices/serviceWorker.ts',
},
output: {
...webpackConfig.output,
filename: 'static/js/[name].js',
},
optimization: {
...webpackConfig.optimization,
runtimeChunk: false,
},
};
},
},
}; Thanks! |
Beta Was this translation helpful? Give feedback.
Answered by
billdami
Feb 17, 2023
Replies: 1 comment
-
If anyone comes across this, i figured it out. I had to overrided CRA's default const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
webpack: {
configure: (webpackConfig, { env, paths }) => {
const isEnvDevelopment = env === 'development';
const isEnvProduction = env === 'production';
return {
...webpackConfig,
plugins: [
new HtmlWebpackPlugin(
Object.assign(
{},
{
inject: true,
template: paths.appHtml,
excludeChunks: ['content', 'background'],
},
isEnvProduction
? {
minify: {
removeComments: true,
collapseWhitespace: false,
removeRedundantAttributes: true,
useShortDoctype: true,
removeEmptyAttributes: true,
removeStyleLinkTypeAttributes: true,
keepClosingSlash: true,
minifyJS: true,
minifyCSS: true,
minifyURLs: true,
},
}
: undefined
)
),
...webpackConfig.plugins.slice(1),
],
entry: {
main: [
isEnvDevelopment && require.resolve('react-dev-utils/webpackHotDevClient'),
paths.appIndexJs,
].filter(Boolean),
content: './src/chromeServices/domBootstrap.ts',
background: './src/chromeServices/serviceWorker.ts',
},
output: {
...webpackConfig.output,
filename: 'static/js/[name].js',
},
optimization: {
...webpackConfig.optimization,
runtimeChunk: false,
},
};
},
},
}; |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
billdami
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If anyone comes across this, i figured it out. I had to overrided CRA's default
HtmlWebpackPlugin
config, adding theexcludeChunks
option: