For a prod build I want my webpack config to have two entry points, one for JS and one for SCSS, and I want these to be output to two separate files (one JS, one CSS).
However extract-text-webpack-plugin is creating two JS files and one CSS file; ie the entry point for SCSS is producing both the desired CSS file plus a JS file that I don't want. This unused JS file contains nothing other than the webpack boilerplate and // removed by extract-text-webpack-plugin
. So it's doing its job fine, but still creating this unnecessary file. My webpack config is (showing the pertinent parts):
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: {
app: './client/src/app.js',
style: './client/src/app.scss'
},
output: {
path: __dirname + '/server/assets/',
publicPath: '/',
filename: 'bundle.[chunkhash].js',
},
module: {
loaders: [{
test: /\.js/,
exclude: /node_modules/,
include: /src/,
loader: 'babel-loader'
},{
test: /\.scss$/,
loader: ExtractTextPlugin.extract('style', 'css', 'sass'),
},{
test: /.*\.(woff|woff2|eot|ttf)$/i,
loader: "url-loader?limit=10000&mimetype=application/font-woff"
},{
test: /.*\.(png|svg|jpg)$/i,
loaders: [
'file?hash=sha512&digest=hex&name=[hash].[ext]',
'image-webpack?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}}'
]
}]
},
plugins: [
new ExtractTextPlugin('bundle.[chunkhash].css', {
allChunks: true
})
]
};
So essentially the output is creating two .js files, one for each entry and then the extract plugin is creating the actual desired .css file. How can I prevent the output from creating that unnecessary file?
Another options is to merge app
and style
chunks into one:
entry: {
app: [
'./client/src/app.js',
'./client/src/app.scss'
]
}
That way webpack will produce only one chunk - app
. At the same time ExtractTextPlugin
will remove any .scss
modules from it. Contents will be placed into bundle.[chunkhash].css
.
Remove the style
entry point from your webpack config:
module.exports = {
entry: {
app: './client/src/app.js'
},
// ...
}
Then require
it from your app.js
file:
// app.js
require('./app.scss');
// ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With