This repository has been archived by the owner on Sep 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
104 lines (104 loc) · 3.69 KB
/
webpack.config.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
const path = require('path');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const devMode = process.env.NODE_ENV !== 'production';
module.exports = {
// Tells Webpack which built-in optimizations to use
// In 'production' mode, Webpack will minify and uglify our JS code
// If you leave this out, Webpack will default to 'production'
mode: devMode ? 'development' : 'production',
// Webpack needs to know where to start the bundling process,
// so we define the main JS and Sass files, both under
// the './src' directory
entry: ['./src/scripts/main.js', './src/styles/main.scss'],
// This is where we define the path where Webpack will place
// the bundled JS file
output: {
path: path.resolve(__dirname, 'public'),
// Specify the base path for all the assets within your
// application. This is relative to the output path, so in
// our case it will be ./public/assets
publicPath: '/assets',
// The name of the output bundle. Path is also relative
// to the output path
filename: 'assets/scripts/bundle.js'
},
module: {
// Array of rules that tells Webpack how the modules (output)
// will be created
rules: [
{
// Look for JavaScript files and apply the babel-loader
// excluding the './node_modules' directory. It uses the
// configuration in `.babelrc`
test: /\.(js)$/,
exclude: /node_modules/,
use: ['babel-loader']
},
{
// Look for Sass files and process them according to the
// rules specified in the different loaders
test: /\.(sa|sc)ss$/,
// Use the following loaders from right-to-left, so it will
// use sass-loader first and ending with MiniCssExtractPlugin
use: [
{
// Extracts the CSS into a separate file and uses the
// defined configurations in the 'plugins' section
loader: MiniCssExtractPlugin.loader
},
{
// Interprets CSS
loader: 'css-loader',
options: {
importLoaders: 2
}
},
{
// Use PostCSS to minify and autoprefix. This loader
// uses the configuration in `postcss.config.js`
loader: 'postcss-loader'
},
{
// Adds support for Sass files, if using Less, then
// use the less-loader
loader: 'sass-loader'
}
]
},
{
// Adds support to load images in your CSS rules. It looks
// for .png, .jpg, .jpeg and .gif
test: /\.(png|jpe?g|gif)$/,
use: [
{
loader: 'file-loader',
options: {
// The image will be named with the original name and
// extension
name: '[name].[ext]',
// Indicates where the images are stored and will use
// this path when generating the CSS files.
// Example, in main.scss I have
// url('../../public/assets/images/venice-italy.jpg')
// and when generating the CSS file, it will be
// outputted as url(../images/venice-italy.jpg), which
// is relative to /styles/main.css
publicPath: '../images',
// When this option is 'true', the loader will emit
// the image to output.path
emitFile: false
}
}
]
}
]
},
plugins: [
// Configuration options for MiniCssExtractPlugin. Here I'm only
// indicating what the CSS outputted file name should be and
// the location
new MiniCssExtractPlugin({
filename: 'assets/styles/main.css'
})
]
};