-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
94 lines (86 loc) · 2.38 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
const path = require('path');
const fs = require('fs');
const fs_extra = require('fs-extra');
const mkdir = require('mkdirp');
const remove_dir = require('delete');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BrowserAsyncPlugin = require('browser-sync-webpack-plugin');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
let gameDir = `./src`;
remove_dir.sync('./dist');
const copyFilesAndDirectory=(src,dest)=>{
console.log(">>>>src---"+src,dest);
fs_extra.copySync(src, dest);
};
let toCopy = [
{from: `${gameDir}/assets/`,to:'./dist/assets/'},
// {from:`${gameDir}/components/`,to:'./dist/components/'},
// {from:`${gameDir}/helpers/`,to:'./dist/helpers/'},
{from:`${gameDir}/lib/`,to:'./dist/lib/'},
];
for (let i=0;i<toCopy.length;i++){
copyFilesAndDirectory(toCopy[i].from,toCopy[i].to);
}
// keep this as option
// const definePlugin = new webpack.DefinePlugin({
// __DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true'))
// });
let extraPlugins = [];
module.exports = {
entry: './src/index.js',
output: {
filename: '[name].min.js',
path: path.resolve(__dirname, 'dist'),
hotUpdateChunkFilename: 'hot/hot-update.js',
hotUpdateMainFilename: 'hot/hot-update.json'
},
watch:true, // helps to run browser-sync plugin
plugins: [
// definePlugin,
new HtmlWebpackPlugin({
filename: '../dist/index.html',
template: `./index.html`,
}),
new BrowserAsyncPlugin({
host: process.env.IP || 'localhost',
port: process.env.PORT || 3000,
server: {
baseDir: ['./dist']
}
})
],
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
test: /\.js(\?.*)?$/i,
terserOptions: {
output: {
comments: false,
quote_keys:false,
keep_quoted_props:false,
},
mangle:{
keep_fnames:false,
keep_classnames:false,
toplevel:true,
safari10:true,
},
compress:{
arguments:false,
collapse_vars:true,
conditionals:false,
arrows:false,
unsafe_arrows:false,
loops:true,
toplevel:true,
reduce_funcs:true,
reduce_vars:true,
join_vars:true,
},
},
}),
],
},
};