-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebpack.config.js
102 lines (99 loc) · 3 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
const HtmlWebpackPlugin = require('html-webpack-plugin'); //installed via npm
const webpack = require('webpack'); //to access built-in plugins
const path = require('path');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const OptimizeCSSAssetsPlugin = require("optimize-css-assets-webpack-plugin");
const UglifyJsPlugin = require("uglifyjs-webpack-plugin");
module.exports = {
entry: {
bundle: "./src/entry.js",
},
output: {
path: path.resolve(__dirname, './public'),
// Save with the key from the entry section. Ie bundle.js, vendor.js
// Chunkhash is a hash of the contents of the file.
filename: '[name].min.js'
},
optimization: {
splitChunks: {
cacheGroups: {
styles: {
name: 'styles',
test: /\.css$/,
enforce: true
}
}
},
// Minify css. Setting optimization.minimizer overrides the defaults provided by webpack,
// we also need to specify a JS minimizer.
minimizer: [
new UglifyJsPlugin({
cache: true,
parallel: true,
sourceMap: true // set to true if you want JS source maps
}),
new OptimizeCSSAssetsPlugin({})
]
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env', "@babel/preset-react"]
}
}
},
{
test: /\.txt$/,
use: 'raw-loader'
},
{
test: /\.css$/,
// Order is important! Loaders are applied from right to left
use: [
MiniCssExtractPlugin.loader,
'css-loader'
]
},
{
test: /\.less$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
'less-loader'
]
},
{
test: /\.(jpeg|png|gif|svg)$/,
use: [
{
loader: 'url-loader',
options: { limit: 40000 },
},
'image-webpack-loader'
]
}
]
},
plugins: [
new HtmlWebpackPlugin({
template: path.resolve(__dirname, 'src', 'index.html'),
filename: './index.html'
}),
new MiniCssExtractPlugin({
filename: '[name].min.css'
}),
new webpack.ProvidePlugin({
"_": "underscore",
"Backbone": "backbone"
})
],
devServer: {
port: 8081,
contentBase: path.join(__dirname, 'public')
},
};