-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
113 lines (83 loc) · 3.22 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const { VueLoaderPlugin } = require('vue-loader');
const DotenvWebpackPlugin = require('dotenv-webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const InlineSourcePlugin = require('html-webpack-inline-source-plugin');
const InjectPlugin = require('webpack-inject-plugin').default;
const ENTRY_ORDER = require('webpack-inject-plugin').ENTRY_ORDER;
const path = require('path');
const webpack = require('webpack');
const rootPath = (...paths) => path.join(__dirname, ...paths);
const srcPath = (...paths) => rootPath('src', ...paths);
const config = (local, sw, mode) => ({
devtool: mode === 'production' ? undefined : 'cheap-module-eval-source-map',
entry: {
main: srcPath('index.js')
},
output: {
path: rootPath(mode === 'production'
? 'dist' : 'dist-dev'),
filename: mode === 'production'
? '[name].[chunkhash].js' : '[name].[hash].js',
publicPath: '/'
},
optimization: {
splitChunks : { chunks: 'all' },
runtimeChunk: true
},
node: {
fs: 'empty', net: 'empty', tls: 'empty'
},
resolve: {
extensions: [ '.js', '.vue' ],
alias : {
'vue$': 'vue/dist/vue.esm.js',
'api' : srcPath('api'), 'store': srcPath('store'),
},
},
module : {
rules: [{
test : /\.vue$/, loader: 'vue-loader',
}, {
test : /\.js$/, loader: 'babel-loader',
include: [ srcPath() ],
options: { presets: [[ '@babel/preset-env', {
modules: false, useBuiltIns: 'usage', corejs: 'core-js@3'
} ]] }
}, {
test: /\.(css|scss)$/,
use : [ 'vue-style-loader', 'css-loader' ]
}],
noParse: /node_modules\/gun\/(gun|sea)\.js$/ // see https://git.io/Jv2K2
},
plugins: [
...(local ? [ // dev server only
new CleanWebpackPlugin() ] : []),
new webpack.DefinePlugin({
'process.env': { MODE: JSON.stringify(mode) }
}),
new DotenvWebpackPlugin(),
new VueLoaderPlugin(),
new HtmlWebpackPlugin({
template : srcPath('index.html'),
inlineSource: 'runtime~.+\\.js',
}),
new InlineSourcePlugin(),
new webpack.HashedModuleIdsPlugin(),
// suppress log spam from modules
new InjectPlugin(() => `
window.cvclnk_log = window.console['log'];
window.console['log'] = () => {};`, { entryOrder: ENTRY_ORDER.NotLast }),
new InjectPlugin(() => `
window.console["log"] = window.cvclnk_log;
delete window.cvclnk_log;`, { entryOrder: ENTRY_ORDER.Last })
]
});
module.exports = (env, argv) => {
let local = env && env.includes('local');
let sw = env && env.includes('sw');
console.log('\x1b[33m', `configuring webpack for ${ argv.mode }`,
`${ local ? 'on local server' : '' }`,
`${ sw ? 'with service worker' : '' }`, '\x1b[0m\n');
return config(local, sw, argv.mode);
};