I'm using Webpack 4
and the mini-css-extract-plugin
in a php application. I keep all the css
styles I've written in scss
files but, in some cases, when I import an external library, I import its css in the script where I use it. My end goal would be to have all the css styles in a single css file that I can manually include in a php view, but at the moment I get the scss in a file and the css from libraries in another.
My current webpack configuration is this:
module.exports = {
devtool: 'source-map',
entry: {
style: './resources/assets/sass/style.scss',
...
},
optimization: {
splitChunks: {
cacheGroups: {
default: false,
styles: {
name: 'styles',
test: /\.s?css$/,
minChunks: 1,
reuseExistingChunk: true,
enforce: true,
},
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendors',
chunks: 'all',
//minChunks: 2,
},
},
},
},
module: {
rules: [
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
],
},
{
test: /\.scss$/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: { config: { path: 'postcss.config.js' } },
},
'sass-loader',
],
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].[chunkhash].css',
}),
new webpack.ProvidePlugin({
noUiSlider: 'nouislider',
}),
]
The scss
styles work correctly, but then in one script I have this:
import 'nouislider/distribute/nouislider.css';
Which is from a script included with ProvidePlugin
and this css ends up in vendors.css
file, while I would like it to be in style.css
together with the rest.
What am I doing wrong?
Edit: As suggested, I created a github repository recreating the issue: