-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
executable file
·61 lines (58 loc) · 2.17 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
// * importing modules
const path = require('path'); // * absolute path
// * importing plugins
const MiniCssExtractPlugin = require('mini-css-extract-plugin'); // * generates a css file
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); // * minifies css
const TerserPlugin = require('terser-webpack-plugin'); // * minifies javascript
// * webpack mode
const devMode = process.env.NODE_ENV !== 'production';
module.exports = {
entry: ['@babel/polyfill', './src/index.js'], // webpack entry point
output: {
filename: 'bundle.js', // webpack output file
path: path.resolve(__dirname, 'public') // webpack output point / directory
},
module: { // # loaders
rules: [
{ // # js loader
test: /\.js$/,
exclude: /node_modules/,
use: ['babel-loader', 'eslint-loader']
},
{ // # styles loader
test: /\.scss$/, // tests for a sass file
use: [
MiniCssExtractPlugin.loader, // compiles CSS into a seperate file
{ loader: 'css-loader' }, // translates CSS into CommonJS
{ loader: 'sass-loader' } // compiles Sass to CSS, using Node Sass by default
]
},
{ // # file loader
test: /\.(png|svg|jpg|gif)$/, // tests for an img
use: [
{ loader: 'file-loader' }
]
}
]
},
optimization: { // # optimization
minimizer: [
new OptimizeCssAssetsPlugin(), // minifies css
new TerserPlugin() // minifies javascript
]
},
plugins: [ // # plugins
new MiniCssExtractPlugin({ // generates a css file
filename: '[name].css',
chunkFilename: '[id].css',
})
],
// # development
devServer: { // webpack development server
contentBase: path.join(__dirname, 'public'),
historyApiFallback: true,
open: 'Google Chrome'
},
devtool: 'source-map', // source maps for debugging
mode: devMode ? 'development' : 'production' // webpack mode
};