-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.conf.js
80 lines (79 loc) · 2.56 KB
/
webpack.conf.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
const CONF = require('@ideadesignmedia/config.js')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CompressionPlugin = require("compression-webpack-plugin");
const fs = require('fs');
const path = require('path')
let build = path.join(process.cwd(), process.env.STATIC || './static')
let directory = path.join(process.cwd(), './src')
let inferredIndex = path.join(directory, 'index.html')
let htmlOptions = { title: process.env.TITLE || 'APP', hash: false, }
if (fs.existsSync(inferredIndex)) htmlOptions.template = inferredIndex
module.exports = {
entry: process.env.ENTRY || './src/index.js',
output: {
path: build,
filename: 'index.js',
},
module: {
rules: [
{
test: /.(sa|sc|c)ss$/i,
use: [MiniCssExtractPlugin.loader, "css-loader",],
},
{
test: /\.(?:js|mjs|cjs)$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['@babel/preset-env', { targets: "defaults" }]
],
cacheDirectory: true,
}
}
}
],
},
plugins: [new HtmlWebpackPlugin(htmlOptions), new MiniCssExtractPlugin(), new CompressionPlugin()],
optimization: {
minimizer: [
new UglifyJsPlugin({
test: /\.js(\?.*)?$/i,
uglifyOptions: {
compress: true,
mangle: true,
extractComments: 'all',
parallel: false,
toplevel: true,
}
})
],
mangleExports: 'size',
mergeDuplicateChunks: true,
minimize: true,
},
devtool: "eval-cheap-source-map",
devServer: {
historyApiFallback: true,
static: {
directory,
watch: {
ignored: '*.txt',
usePolling: false,
}
},
compress: true,
port: process.env.DEVPORT || 3000,
open: {
target: ['index.html'],
app: {
name: 'google-chrome',
arguments: ['--incognito', '--new-window'],
},
},
webSocketServer: 'ws'
},
};