-
Notifications
You must be signed in to change notification settings - Fork 2
/
webpack.config.babel.js
executable file
·148 lines (140 loc) · 4.12 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
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';
const SWPrecache = require('sw-precache-webpack-plugin');
import autoprefixer from 'autoprefixer';
import Dashboard from 'webpack-dashboard/plugin';
import ScriptExtHtmlWebpackPlugin from 'script-ext-html-webpack-plugin';
import {CriticalPlugin} from 'webpack-plugin-critical';
const ENV = process.env.NODE_ENV || 'development';
module.exports = {
entry: {
app: './src/index.js',
vendor: ['preact', 'preact-router', 'redux']
},
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!sass-loader?sourceMap')
}
]
},
plugins: ([
new webpack.optimize.CommonsChunkPlugin({name: 'vendor', minChunks: Infinity}),
new webpack.optimize.OccurrenceOrderPlugin(),
new webpack.LoaderOptionsPlugin({
options: {
context: __dirname,
postcss: [autoprefixer]
},
minimize: true,
debug: false
}),
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: 'Wave PWA',
removeRedundantAttributes: true,
inject: false,
manifest: `${ENV === 'production'
? 'manifest.json'
: '/assets/manifest.json'}`,
minify: {
collapseWhitespace: true,
removeComments: true
},
themeColor: '#404042'
}),
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 CriticalPlugin({src: 'index.html', inline: true, minify: true, dest: 'index.html'}),
new SWPrecache({
runtimeCaching: [
{
urlPattern: /^https:\/\/api.soundcloud\.com\//,
handler: 'cacheFirst'
}, {
urlPattern: /^https:\/\/cf-media.sndcdn\.com\//,
handler: 'cacheFirst'
}
],
filename: 'service-worker.js',
dontCacheBustUrlsMatching: /./,
navigateFallback: 'index.html',
staticFileGlobsIgnorePatterns: [/\.map$/, /\.DS_Store/]
}),
new webpack.optimize.UglifyJsPlugin({
output: {
comments: 0
},
compress: {
unused: 1,
warnings: 0
}
}),
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 || 3000,
host: '0.0.0.0',
compress: true,
contentBase: './src',
historyApiFallback: true
}
};