-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwebpack.config.js
More file actions
160 lines (155 loc) · 4.57 KB
/
webpack.config.js
File metadata and controls
160 lines (155 loc) · 4.57 KB
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
const path = require('path');
const autoprefixer = require('autoprefixer');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const OfflinePlugin = require('offline-plugin');
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
const webpack = require('webpack');
const ENV = process.env.NODE_ENV || 'development';
const CSS_MAPS = ENV!=='production';
module.exports = {
context: path.resolve(__dirname, "src"),
entry: './index.js',
output: {
path: path.resolve(__dirname, 'build'),
filename: '[name].bundle.js',
chunkFilename: '[name].bundle.js',
publicPath: '/'
},
resolve: {
extensions: ['.js', 'wasm', '.css'],
alias: {
Lib: path.resolve(__dirname, 'src/lib/'),
Component: path.resolve(__dirname, 'src/components/'),
Style: path.resolve(__dirname, 'src/style/'),
'react': 'preact-compat',
'react-dom': 'preact-compat'
}
},
module: {
rules: [
{
test: /\.jsx?$/,
exclude: path.resolve(__dirname, 'src'),
enforce: 'pre',
use: 'source-map-loader'
},
{
test: /\.jsx?$/,
exclude:/node_modules/,
use: [
{
loader: 'babel-loader',
options: {
presets: ["es2015", "stage-2", "preact"]
}
}
]
},
{
test: /\.css$/,
use: [
{ loader: MiniCssExtractPlugin.loader },
{ loader: "css-loader", options: {modules: true} }
]
},
// Emscripten JS files define a global. With `exports-loader` we can
// load these files correctly (provided the global’s name is the same
// as the file name).
/*{
test: /hex_server_protocol\.js$/,
loader: "exports-loader"
},
// wasm files should not be processed but just be emitted and we want
// to have their public URL.
{
test: /hex_server_protocol_bg\.wasm$/,
type: "javascript/auto",
loader: "file-loader",
options: {
publicPath: "build/"
}
}*/
]
},
plugins: ([
new CleanWebpackPlugin(['build']),
/*new ExtractTextPlugin({
filename: 'style.css',
allChunks: true
//disable: ENV !== 'production'
}),*/
new HtmlWebpackPlugin({
template: './index.ejs',
minify: { collapseWhitespace: true }
}),
new CopyWebpackPlugin([
{ from: './manifest.json', to: './' },
{ from: './favicon.ico', to: './' },
{ from: './lib/hex_server_protocol_bg.wasm', to: './protocol.module.wasm' },
{ from: './assets/', to: 'assets/', toType: 'dir' }
]),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: "[name].css",
chunkFilename: "[id].css"
}),
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /de|fr|hu/)
]).concat(ENV==='production' ? [
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
}
}),
new OfflinePlugin({
relativePaths: false,
AppCache: false,
excludes: ['_redirects'],
ServiceWorker: {
events: true
},
cacheMaps: [
{
match: /.*/,
to: '/',
requestTypes: ['navigate']
}
],
publicPath: '/'
})
] : []),
stats: { children: false }, // Ok??
devServer: {
historyApiFallback: true,
host: 'localhost',
port: '8082'
},
mode: 'development'
};