This repository has been archived by the owner on May 12, 2020. It is now read-only.
/
webpack.rules.js
88 lines (82 loc) · 2.43 KB
/
webpack.rules.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
const autoprefixer = require('autoprefixer');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
module.exports = (isDev) => ({
css: {
test: /\.(css|scss)$/,
use: [
MiniCssExtractPlugin.loader,
{
// CSS Loader https://github.com/webpack/css-loader
loader: 'css-loader',
options: {
importLoaders: 2,
sourceMap: isDev,
// CSS Nano http://cssnano.co/options/
minimize: !isDev,
},
},
{
// PostCSS Loader https://github.com/postcss/postcss-loader
loader: 'postcss-loader',
options: {
sourceMap: isDev,
plugins: [
// Add vendor prefixes to CSS rules using values from caniuse.com
// https://github.com/postcss/autoprefixer
autoprefixer(),
],
},
},
{
// Allow resolving `url('...')` from node_modules
// https://github.com/bholloway/resolve-url-loader
loader: 'resolve-url-loader',
},
{
// Sass Loader https://github.com/webpack-contrib/sass-loader
loader: 'sass-loader',
options: {
sourceMap: isDev,
},
},
],
},
js: {
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /(node_modules|bower_components)/,
query: {
// Faster build thanks to caching
// https://github.com/babel/babel-loader#options
cacheDirectory: isDev,
presets: [
// A Babel preset that can automatically determine the Babel plugins and polyfills
// https://github.com/babel/babel/tree/master/packages/babel-preset-env
[
'@babel/preset-env',
{
modules: isDev ? 'commonjs' : false,
useBuiltIns: isDev ? false : 'usage',
},
],
// Experimental ECMAScript proposals
// https://babeljs.io/docs/plugins/preset-stage-2/
['@babel/preset-stage-2', { decoratorsLegacy: true }],
],
plugins: [
// Allows for optional chaining through `?.`
// https://github.com/babel/babel/tree/master/packages/babel-plugin-syntax-optional-chaining
'@babel/plugin-proposal-optional-chaining',
],
},
},
asset: {
// File loader
// https://github.com/webpack-contrib/file-loader
test: /\.(jpg|jpeg|gif|png|svg|woff|woff2)$/,
loader: 'file-loader',
options: {
name: '[name].[ext]?[hash]',
},
},
});