This repository has been archived by the owner on Jan 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
preact.webpack.config.js
146 lines (136 loc) · 3.22 KB
/
preact.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/* eslint-env node */
/* eslint no-console: 0 */
const webpack = require('webpack'),
path = require('path'),
HtmlWebpackPlugin = require('html-webpack-plugin'),
ProgressBarPlugin = require('progress-bar-webpack-plugin'),
getArg = require('./lib/script-arg.js')
const ENV = process.env.NODE_ENV || 'development',
PROD = ENV === 'production',
DEV = ENV === 'development',
__ENV__ = JSON.stringify(ENV),
__DEV__ = JSON.stringify(DEV),
__PROD__ = JSON.stringify(PROD),
isHot = DEV && getArg('hot', 'true').toString() === 'true'
const filename = PROD ? '[name].min.js' : '[name].js'
const config = {
context: path.resolve(__dirname, 'src'),
entry: {
preact: './preact.js'
},
output: {
path: path.resolve(__dirname, 'dist'),
filename
},
resolve: {
extensions: ['.js'],
modules: [
path.resolve(__dirname, 'node_modules'),
'node_modules'
]
},
module: {
rules: [{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true,
sourceMaps: true,
presets: ['env', 'preact']
}
}
// }, {
// test: /\.json$/,
// use: 'json-loader'
}]
},
plugins: [
new ProgressBarPlugin({ width: 75, clear: true}),
new webpack.NoEmitOnErrorsPlugin(),
new webpack.DefinePlugin({
__ENV__,
__DEV__,
__PROD__,
'process.env.NODE_ENV': __ENV__
}),
new HtmlWebpackPlugin({
inject: true,
chunks: ['preact'],
template: './index.html',
filename: 'preact.html'
})
],
stats: { colors: true },
// node: {
// global: true,
// process: false,
// Buffer: false,
// __filename: false,
// __dirname: false,
// setImmediate: false
// },
devtool: PROD ? 'source-map' : 'inline-source-map',
}
if(PROD) {
config.plugins.concat([
new webpack.optimize.UglifyJsPlugin({
output: {
comments: false
},
compress: {
'unsafe_comps': true,
properties: true,
'keep_fargs': false,
'pure_getters': true,
'collapse_vars': true,
unsafe: true,
warnings: false,
'screw_ie8': true,
sequences: true,
'dead_code': true,
'drop_debugger': true,
comparisons: true,
conditionals: true,
evaluate: true,
booleans: true,
loops: true,
unused: true,
'hoist_funs': true,
'if_return': true,
'join_vars': true,
cascade: true,
'drop_console': true
}
})
])
}
if(DEV) {
if(isHot) {
config.plugins.concat([
new webpack.HotModuleReplacementPlugin()
])
}
Object.assign(config, {
devServer: {
contentBase: path.join(__dirname, 'dist'),
compress: true,
port: 8000,
hot: isHot,
// https: {
// key: fs.readFileSync('/path/to/server.key'),
// cert: fs.readFileSync('/path/to/server.crt'),
// ca: fs.readFileSync('/path/to/ca.pem'),
// },
open: true,
},
watch: true,
watchOptions: {
ignored: /node_modules/,
aggregateTimeout: 1000,
// poll: 5000,
},
})
}
module.exports = config