この問題を長い間読んだ後、これを行うことができました。トリックの一部は、optimization
属性を使用し、チャンク名でフィルタリングすることです。
私の webpack.config.js は次のようになります。
module.exports = {
entry: {
popup: ['./src/js/popup.js', './src/css/popup.scss'],
timer_player: [
'./src/js/content_scripts/timer_player/index.js',
'./src/css/timer_player.scss',
],
},
output: {
publicPath: '.',
path: resolve(__dirname, 'dist/'),
filename: '[name].js',
libraryTarget: 'umd',
},
plugins: [
new WebpackReloaderPlugin({
port: 9090, // Which port use to create the server
reloadPage: true, // Force the reload of the page also
entries: {
// The entries used for the content/background scripts
contentScript: 'popup', // Use the entry names, not the file name or the path
background: 'background', // *REQUIRED
},
}),
new MiniCssExtractPlugin({ filename: '[name].css' }),
new HtmlWebpackPlugin({
template: path.join(__dirname, 'src', 'popup.html'),
filename: 'popup.html',
chunks: ['popup'],
}),
new CopyWebpackPlugin([
{ from: './src/manifest.json' },
{ from: './src/images', to: 'images' },
]),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}),
],
module: {
rules: [
{
test: /\.(js|jsx)$/,
loader: 'babel-loader',
exclude: /node_modules/,
},
{
test: /\.scss$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader', // translates CSS into CommonJS
{
loader: 'sass-loader',
options: {
includePaths: ['node_modules', 'node_modules/@material/*']
.map(d => path.join(__dirname, d))
.map(g => glob.sync(g))
.reduce((a, c) => a.concat(c), []),
},
},
],
},
{
test: /\.txt$/,
use: 'raw-loader',
},
],
},
optimization: {
splitChunks: {
cacheGroups: {
extractPopupStyles: {
name: 'style',
chunks: chunk => chunk.name === 'popup',
},
},
},
},
};
どんな提案でも大歓迎です