-
-
Notifications
You must be signed in to change notification settings - Fork 390
Closed
Milestone
Description
I tried to follow the advanced example, but the devMode ? 'style-loader' : MiniCssExtractPlugin.loader, part always seems to use style-loader.
My scripts
"scripts": {
"test": "test",
"build": "webpack-dev-server --config webpack.config.js --mode development", // uses style-loader
"prod": "webpack --config webpack.config.js --mode production" // uses style-loader
},
Am I missing something?
This is my config:
const webpack = require('webpack');
const path = require('path');
const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const devMode = process.env.NODE_ENV !== 'production';
module.exports = {
entry: './src/index',
output: {
filename: '[name].bundle.js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new MiniCssExtractPlugin({
// fallback: "style-loader",
// filename: 'styles/[name].css',
filename: devMode ? '[name].css' : 'styles/[name].[hash].css',
chunkFilename: devMode ? '[id].css' : '[id].[hash].css',
}),
new UglifyJSPlugin(),
new HtmlWebpackPlugin({
title: "Output management",
template: 'src/assets/html/index.html'
}),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
include: path.resolve(__dirname, "src"),
loader: 'babel-loader',
options: {
presets: ['env']
}
},
{
test: /\.(png|svg|jpg|gif)$/,
use: [
'file-loader'
]
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'assets/fonts/'
}
}
]
},
{
test: /\.(scss|css)$/,
use: [
devMode ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader'
},
{
loader: 'sass-loader'
}
]
}
]
},
devServer: {
contentBase: "./dev",
compress: true,
port: "9000"
},
watchOptions: {
aggregateTimeout: 300,
poll: 1000,
ignored: /node_modules/
},
resolve: {
alias: {
fontello: path.resolve(__dirname, 'src/assets/icons/fontello-icons')
}
}
// devtool: 'source-map' // CSS source not shown in devtools
};