-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.babel.js
executable file
·158 lines (145 loc) · 3.77 KB
/
webpack.config.babel.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
147
148
149
150
151
152
153
154
155
156
157
158
import path from 'path'
import webpack from 'webpack'
import BabiliPlugin from 'babili-webpack-plugin'
import StaticSiteGeneratorPlugin from 'static-site-generator-webpack-plugin'
import FilterChunk from 'filter-chunk-webpack-plugin'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
import ProgPlugin from './ProgPlugin'
import {getRouterPaths} from './src/routing'
import elements from './data/dist/basic'
// Ensure Full Errors are Shown
process.on('unhandledRejection', r => console.error(r))
export default env => {
const devMode = env !== 'production'
const routesData = {
elements: Object.keys(elements).slice(1, devMode ? 18 + 1 : undefined)
}
const routerPaths = getRouterPaths(routesData)
const cssIdentifier = 'css.css'
const stats = 'errors-only'
const progPlugin = new ProgPlugin()
const config = {
stats,
mode: devMode ? 'development' : 'production',
entry: {
client: ['@babel/polyfill', './src/client.js'],
static: ['@babel/polyfill', './src/static.js']
},
output: {
path: devMode ? '/' : path.resolve('./dist'),
filename: '[name].js',
libraryTarget: 'umd',
globalObject: '(typeof window === `object` ? window : global)'
},
target: 'web',
devtool: devMode ? 'source-map' : undefined,
module: {
rules: [
{
test: /\.js$/,
use: devMode ? 'babel-loader' : 'babel-loader?cacheDirectory',
exclude: /node_modules/
},
{
test: /\.css$/,
exclude: /node_modules/,
use: ExtractTextPlugin.extract({
use: {
loader: 'css-loader',
query: {
modules: {
localIdentName: devMode ? '[path][name]__[local]' : '[hash:base64]'
},
sourceMap: devMode
}
}
})
},
{
test: /\.css$/,
include: /node_modules/,
use: [
'node-style-loader',
{
loader: 'css-loader',
query: {
sourceMap: devMode
}
}
]
},
{
test: /\.woff2?$/,
use: {
loader: 'url-loader',
query: {
limit: 10000
}
}
},
{
test: /\.(jpe?g|png|gif|svg)$/,
use: [{
loader: 'url-loader',
query: {
limit: 10000
}
},
{
loader: 'img-loader',
query: {
minimize: true
}
}
]
}
]
},
plugins: [
...routerPaths.map((routerPath, routeNumber) => new StaticSiteGeneratorPlugin({
entry: 'static',
paths: routerPath.endsWith('.html') ? routerPath : `${routerPath}.html`,
locals: {
routerPath,
routeNumber,
routerPaths,
cssIdentifier,
progPlugin
}
})),
new ExtractTextPlugin(cssIdentifier, {
allChunks: true
}),
progPlugin._plugin,
new webpack.DefinePlugin({
__DEVTOOLS__: devMode
}),
!devMode ? new BabiliPlugin() : () => undefined,
new FilterChunk({
patterns: ['static*.js', cssIdentifier]
})
],
devServer: {
stats,
contentBase: './dist',
compress: true,
host: '0.0.0.0',
disableHostCheck: true,
port: 1616,
inline: false,
historyApiFallback: {
rewrites: [{
from: /^.*\/(.+)\/?$/,
to: context => `/${context.match[0]}.html`
}]
}
},
watchOptions: {
aggregateTimeout: 4000
},
resolve: {
extensions: ['.js', '.css', '.json']
}
}
return config
}