-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebpack.config.js
More file actions
129 lines (126 loc) · 2.95 KB
/
webpack.config.js
File metadata and controls
129 lines (126 loc) · 2.95 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
const path = require('path');
const glob = require('glob');
const argv = require('yargs').argv;
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const isDevelopment = argv.mode === 'development';
const isProduction = !isDevelopment;
const distPath = path.join(__dirname, '/public');
const config = {
entry: {
main: './frontend/js/index.js'
},
output: {
filename: 'scripts/bundle.js',
path: distPath
},
module: {
rules: [{
test: /\.html$/,
use: {
loader: 'html-loader',
options: {
interpolate: true,
attrs: ['img:src', 'object:data']
}
}
}, {
test: /\.js$/,
exclude: /node_modules/,
use: [{
loader: 'babel-loader'
}]
}, {
test: /\.scss$/,
exclude: /node_modules/,
use: [
isDevelopment ? 'style-loader' : {
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: '../'
}
},
'css-loader',
{
loader: 'postcss-loader',
options: {
plugins: [
isProduction ? require('cssnano') : () => {},
require('autoprefixer')({
overrideBrowserslist: ['last 2 versions']
})
]
}
},
'sass-loader'
]
}, {
test: /inline-svg[\\\/].+\.svg$/i,
loader: 'svg-inline-loader'
}, {
test: /images[\\\/].+\.(gif|png|jpe?g|svg)$/i,
use: [{
loader: 'file-loader',
options: {
name: './assets/images/[name][hash].[ext]'
}
}, {
loader: 'image-webpack-loader',
options: {
mozjpeg: {
enabled: false,
// progressive: true,
// quality: 70
}
}
}],
}, {
test: /fonts[\\\/].+\.(otf|eot|svg|ttf|woff|woff2)$/i,
use: {
loader: 'file-loader',
options: {
name: './assets/fonts/[name][hash].[ext]'
}
},
}]
},
plugins: [
new MiniCssExtractPlugin({
filename: './styles/[name].css',
chunkFilename: '[id].css'
}),
new CopyPlugin([{
from: 'frontend/assets/static/',
to: distPath
}]),
...glob.sync('./frontend/*.html')
.map(htmlFile => {
return new HtmlWebpackPlugin({
filename: path.basename(htmlFile),
template: htmlFile
});
})
],
optimization: isProduction ? {
minimizer: [
new UglifyJsPlugin({
sourceMap: true,
uglifyOptions: {
compress: {
inline: false,
drop_console: true
},
},
}),
],
} : {},
devServer: {
contentBase: distPath,
port: 8088,
compress: true,
open: true
}
};
module.exports = config;