|
1 | 1 | const webpack = require('webpack');
|
2 | 2 | const autoprefixer = require('autoprefixer');
|
3 |
| -const ExtractTextPlugin = require('extract-text-webpack-plugin'); |
| 3 | +const cssNano = require('cssnano'); |
| 4 | +const MiniCssExtractPlugin = require('mini-css-extract-plugin'); |
4 | 5 | const path = require('path');
|
5 | 6 | const project = require('./project');
|
6 | 7 |
|
@@ -51,40 +52,46 @@ module.exports = {
|
51 | 52 | {
|
52 | 53 | test: /\.scss$/,
|
53 | 54 | exclude: [/node_modules/],
|
54 |
| - use: ExtractTextPlugin.extract({ |
55 |
| - fallback: 'style-loader', |
56 |
| - use: [ |
57 |
| - { |
58 |
| - loader: 'css-loader', |
59 |
| - options: { |
60 |
| - minimize: process.env.NODE_ENV === 'production', |
61 |
| - sourceMap: true, |
62 |
| - modules: true, |
63 |
| - importLoaders: 1, |
| 55 | + use: [ |
| 56 | + { |
| 57 | + loader: MiniCssExtractPlugin.loader, |
| 58 | + options: { |
| 59 | + hmr: process.env.NODE_ENV === 'development' // only enable hot in development |
| 60 | + } |
| 61 | + }, |
| 62 | + { |
| 63 | + loader: 'css-loader', |
| 64 | + options: { |
| 65 | + sourceMap: true, |
| 66 | + importLoaders: 1, |
| 67 | + modules: { |
64 | 68 | localIdentName: (process.env.NODE_ENV === 'production')
|
65 | 69 | ? '[hash:base64:5]'
|
66 | 70 | : project.name + '_[name]_[local]---[hash:base64:5]'
|
67 | 71 | }
|
68 |
| - }, |
69 |
| - { |
70 |
| - loader: 'postcss-loader', |
71 |
| - options: { |
72 |
| - sourceMap: true, |
73 |
| - plugins: function() { |
74 |
| - return [ |
75 |
| - autoprefixer('last 2 versions') |
76 |
| - ]; |
77 |
| - } |
78 |
| - } |
79 |
| - }, |
80 |
| - { |
81 |
| - loader: 'sass-loader', |
82 |
| - options: { |
83 |
| - outputStyle: 'expanded' |
| 72 | + } |
| 73 | + }, |
| 74 | + { |
| 75 | + loader: 'postcss-loader', |
| 76 | + ident: 'postcss', |
| 77 | + options: { |
| 78 | + sourceMap: true, |
| 79 | + plugins: function() { |
| 80 | + return [ |
| 81 | + cssNano(), |
| 82 | + autoprefixer('last 2 versions') |
| 83 | + ]; |
84 | 84 | }
|
85 | 85 | }
|
86 |
| - ] |
87 |
| - }) |
| 86 | + }, |
| 87 | + { |
| 88 | + loader: 'sass-loader', |
| 89 | + options: { |
| 90 | + sourceMap: true, |
| 91 | + outputStyle: 'expanded' |
| 92 | + } |
| 93 | + } |
| 94 | + ] |
88 | 95 | },
|
89 | 96 | {
|
90 | 97 | test: /\.(png|jpg|jpeg|gif|svg)$/,
|
@@ -126,11 +133,10 @@ module.exports = {
|
126 | 133 | new webpack.DefinePlugin(GLOBALS),
|
127 | 134 |
|
128 | 135 | // Extracts the imported Sass dependencies into a single CSS file
|
129 |
| - new ExtractTextPlugin({ |
130 |
| - filename: 'assets/css/[name].css', |
131 |
| - allChunks: true, |
| 136 | + new MiniCssExtractPlugin({ |
132 | 137 | ignoreOrder: false,
|
133 |
| - disable: process.env.NODE_ENV !== 'production' |
| 138 | + filename: process.env.NODE_ENV !== 'production' ? '[name].css' : '[name].[hash].css', |
| 139 | + chunkFilename: process.env.NODE_ENV !== 'production' ? '[id].css' : '[id].[hash].css' |
134 | 140 | })
|
135 | 141 | ]
|
136 | 142 | };
|
0 commit comments