This repository has been archived by the owner on Oct 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
webpack.config.babel.js
163 lines (155 loc) · 3.67 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
159
160
161
162
163
import path from 'path';
import webpack from 'webpack';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import CompressionPlugin from 'compression-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import ManifestPlugin from 'webpack-manifest-plugin';
import OfflinePlugin from 'offline-plugin';
import Dashboard from 'webpack-dashboard/plugin';
import ScriptExtHtmlWebpackPlugin from 'script-ext-html-webpack-plugin';
const ENV = process.env.NODE_ENV || 'development';
module.exports = {
entry: {
app: './src/index.js',
vendor: ['preact', 'preact-router', 'redux', 'preact-mdl']
},
output: {
path: path.resolve(__dirname, './build'),
filename: '[name].[hash:8].js',
chunkFilename: '[id].[hash:8].chunk.js',
publicPath: '/'
},
resolve: {
extensions: ['.js'],
alias: {
react: 'preact-compat',
'react-dom': 'preact-compat'
}
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
loader: 'source-map-loader',
exclude: /src/
},
{
enforce: 'pre',
test: /\.js$/,
loader: 'eslint-loader',
include: /src/
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [
path.resolve('src'),
path.resolve('node_modules/preact-compat/src')
]
},
{
test: /\.(scss|css)$/,
loader: ExtractTextPlugin.extract(
'css-loader?sourceMap!postcss-loader?sourceMap!sass-loader?sourceMap'
)
}
]
},
plugins: [
new webpack.optimize.CommonsChunkPlugin({
name: 'vendor',
minChunks: Infinity
}),
new webpack.optimize.OccurrenceOrderPlugin(),
new ExtractTextPlugin({
filename: '[name].[chunkhash:5].css',
allChunks: true
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(ENV)
}),
new HtmlWebpackPlugin({
template: './src/index.html',
title: 'Preact Simple Starter',
removeRedundantAttributes: true,
inject: false,
manifest: `${ENV === 'production' ? 'manifest.json' : '/assets/manifest.json'}`,
minify: {
collapseWhitespace: true,
removeComments: true
},
themeColor: '#333'
}),
new ScriptExtHtmlWebpackPlugin({
defaultAttribute: 'async'
}),
new ManifestPlugin({
fileName: 'asset-manifest.json'
})
]
// Only for development
.concat(
ENV === 'development'
? [new webpack.HotModuleReplacementPlugin(), new Dashboard()]
: []
)
// Only for production
.concat(
ENV === 'production'
? [
new webpack.NoEmitOnErrorsPlugin(),
new CopyWebpackPlugin([
{ from: './src/assets/manifest.json', to: './' },
{ from: './src/assets/img', to: './img' }
]),
new OfflinePlugin({
relativePaths: false,
publicPath: '/',
updateStrategy: 'all',
safeToUseOptionalCaches: true,
caches: 'all',
ServiceWorker: {
navigateFallbackURL: '/',
events: true
},
AppCache: false
}),
new webpack.optimize.UglifyJsPlugin({
output: {
comments: 0
},
compress: {
unused: 1,
warnings: 0
}
}),
// CompressionPlugin Usage in Express
/**
app.get('*.js', function (req, res, next) {
req.url = req.url + '.gz';
res.set('Content-Encoding', 'gzip');
next();
});
**/
new CompressionPlugin({
asset: '[path].gz[query]',
algorithm: 'gzip',
test: /\.js$|\.css$|\.html$/,
threshold: 10240,
minRatio: 0.8
})
]
: []
),
stats: { colors: true },
devtool: ENV !== 'production' && 'eval',
devServer: {
port: process.env.PORT || 8080,
host: '0.0.0.0',
compress: true,
contentBase: './src',
historyApiFallback: true
}
};