This repository has been archived by the owner on Dec 12, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwebpack.config.js
99 lines (95 loc) · 2.33 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
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const CleanObsoleteChunks = require('webpack-clean-obsolete-chunks');
const ENV = process.argv[process.argv.length - 1] || 'production';
const SRC_DIR = path.resolve(__dirname, 'src');
const BUILD_DIR = path.resolve(__dirname, 'build');
const plugins = [
new CopyPlugin([{
from: path.join(SRC_DIR, 'assets'),
to: path.join(BUILD_DIR, 'assets'),
}]),
new MiniCssExtractPlugin({
filename: 'index.css',
path: BUILD_DIR,
}),
new HtmlWebpackPlugin({
template: path.join(SRC_DIR, 'index.html'),
minify: {
collapseWhitespace: true,
removeComments: true,
removeRedundantAttributes: true,
removeScriptTypeAttributes: true,
removeStyleLinkTypeAttributes: true,
useShortDoctype: true,
},
}),
new CleanObsoleteChunks(),
];
if (ENV === 'production') {
plugins.push(new OptimizeCssAssetsPlugin({
cssProcessor: require('cssnano'),
cssProcessorPluginOptions: {
preset: ['default', {discardComments: {removeAll: true}}],
},
}));
}
module.exports = {
target: 'web',
mode: ENV,
devServer: {
port: process.env.DEV_SERVER_PORT || 8081,
host: '0.0.0.0',
open: false,
writeToDisk: true,
proxy: {
'/': 'http://nginx',
},
},
entry: [
path.join(SRC_DIR, 'index.js'),
path.join(SRC_DIR, 'index.scss'),
],
output: {
filename: 'index.js',
chunkFilename: `[name].[chunkhash].js`,
path: BUILD_DIR,
},
module: {
rules: [
{
test: /\.scss$/,
exclude: /node_modules/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
},
{
loader: 'sass-loader',
},
],
},
{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},
{
test: /\.(png|jpg|svg|gif|mp4|eot|woff|woff2)$/i,
use: [
{
loader: 'file-loader',
},
],
},
],
},
plugins,
devtool: ENV === 'production' ? false : 'source-map',
};