-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
107 lines (105 loc) · 2.86 KB
/
Copy pathwebpack.config.js
File metadata and controls
107 lines (105 loc) · 2.86 KB
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
105
106
107
const path = require('path')
// const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = (env) => {
const isProduction = env === 'production'
const indexCSSExtract = new MiniCssExtractPlugin('css/[index].css')
return {
entry: {
index: path.join(__dirname, '/web/src/index.js')
},
output: {
path: path.join(__dirname, '/web/assets/dist'),
filename: '[name].bundle.js',
publicPath: '/'
},
mode: isProduction ? 'production' : 'development',
module: {
rules: [
{
loader: 'babel-loader',
test: /\.js$/,
exclude: /node_modules/,
query: {
presets: [ 'env', 'react' ],
plugins: ['transform-class-properties']
}
},
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
MiniCssExtractPlugin.loader, // don't change this
{ loader: 'css-loader', options: { sourceMap: true } },
{ loader: 'sass-loader', options: { sourceMap: true } }
]
},
{
test: /\.css$/,
include: /node_modules/,
use: [ 'style-loader', { loader: 'css-loader', options: { sourceMap: true } } ]
},
{
test: /\.(png|gif|svg|jpe?g)$/i,
use: [
{
loader: 'file-loader',
options: {
name: 'img/[name].[ext]'
}
},
{
loader: 'image-webpack-loader',
options: {
gifsicle: {
interlanced: false
},
optipng: {
optimizationLevel: 7
},
pngquant: {
quality: '65-90',
speed: 4
},
mozjpeg: {
progressive: true,
quality: 65
}
}
}
]
}
]
},
optimization: {
splitChunks: {
cacheGroups: {
commons: { test: /[\\/]node_modules[\\/]/, name: "vendors", chunks: "all" }
}
}
},
devtool: isProduction ? 'source-map' : 'inline-source-map',
devServer: {
port: 3000,
contentBase: path.join(__dirname, '/web/assets/dist'),
historyApiFallback: true,
open: true,
headers: { 'Access-Control-Allow-Origin': '*' },
https: false,
disableHostCheck: true
},
plugins: [
indexCSSExtract,
new HtmlWebpackPlugin({
filename: 'index.html',
minify: {
collapseWhitespace: true,
removeComments: true
},
inject: false,
template: path.join(__dirname, '/web/src/index.html')
})
]
}
}