-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwebpack.config.js
154 lines (150 loc) · 4.46 KB
/
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
147
148
149
150
151
152
153
154
;`use strict`
const path = require(`path`)
const webpack = require(`webpack`)
const WebpackPwaManifest = require('webpack-pwa-manifest')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const autoprefixer = require('autoprefixer')
const csswring = require('csswring')
const { InjectManifest } = require('workbox-webpack-plugin')
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer')
const bc = require(`./build-config`)
const client = {
target: `web`,
mode: bc.env,
entry: {
thailpha: `./js/application.js`,
},
output: {
filename: `[name].[hash].js`,
path: bc.buildPath,
publicPath: `/`,
},
devtool: bc.isDev ? `source-map` : false,
resolve: {
alias: { '~': path.resolve(__dirname, `js`) },
},
module: {
rules: [
{
test: /\.jsx?$/,
include: [path.resolve(__dirname, `js`)],
use: {
loader: `babel-loader`,
options: { babelrc: true },
},
},
{
test: /\.(sa|sc|c)ss$/,
use: [
bc.isDev ? `style-loader` : MiniCssExtractPlugin.loader,
`css-loader`,
{
loader: `postcss-loader`,
options: {
ident: `postcss`,
plugins: [autoprefixer({})].concat(
bc.isDev ? [] : [csswring({ removeAllComments: true })]
),
},
},
`sass-loader`,
],
},
// https://github.com/pugjs/pug-loader
{
test: /\.pug$/,
use: [
{
loader: `pug-loader`,
options: {
self: true,
pretty: true,
},
},
],
},
],
},
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify(bc.env),
__IS_DEV__: JSON.stringify(bc.isDev),
__APP_TITLE__: JSON.stringify(bc.APP_TITLE),
__APP_DESC__: JSON.stringify(bc.APP_DESC),
__APP_URL__: JSON.stringify(bc.APP_URL),
__APP_VERSION__: JSON.stringify(bc.APP_VERSION),
}),
new MiniCssExtractPlugin({
// Options similar to the same options in webpackOptions.output
// both options are optional
filename: bc.isDev ? `[name].css` : `[name].[hash].css`,
chunkFilename: bc.isDev ? `[id].css` : `[id].[hash].css`,
}),
new HtmlWebpackPlugin({
template: path.resolve(__dirname, `html/index.pug`),
// custom variables
// https://stackoverflow.com/a/41376115
env: bc.env,
isRelease: bc.isRelease,
APP_TITLE: bc.APP_TITLE,
// options: {
// minify: false,
// },
}),
// PWA Manifest
// https://www.npmjs.com/package/webpack-pwa-manifest
new WebpackPwaManifest({
// https://github.com/webpack/webpack/issues/237#issuecomment-342129128
version: process.env.npm_package_version,
name: bc.APP_TITLE,
short_name: bc.APP_TITLE,
background_color: `#fff`,
theme_color: `black`,
description: `Thai Alphabet`,
lang: `en-US`,
display: `standalone`,
start_url: `${bc.BASE_URL}/index.html?utm_source=homescreen`,
orientation: `any`,
inject: true,
ios: true,
icons: [
{
src: bc.iconSource,
// same sizes as nuxt-pwa
sizes: [64, 120, 144, 152, 192, 384, 512],
// destination: `img/icons`,
ios: true,
},
],
}),
// keep this in case we want to check a regular generated SW
// new GenerateSW({
// swDest: `thailpha-sw.js`,
// include: [/\.html$/, /\.js$/, /\.css$/, /\.png$/, /\.svg$/, /\.json$/],
// cacheId: `thailpha-cache-v3`,
// navigateFallback: `${bc.BASE_URL}/index.html`,
// navigateFallbackWhitelist: [/\/(vowels|numbers|about|search|char\/)/],
// }),
// Workbox Service Worker
// https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin#injectmanifest_plugin_1
new InjectManifest({
swSrc: path.resolve(__dirname, `js/service-worker-templates.js`),
swDest: `thailpha-sw.js`,
// importWorkboxFrom: `local`,
}),
].concat(bc.isProd ? [new BundleAnalyzerPlugin()] : []),
// https://gist.github.com/sokra/1522d586b8e5c0f5072d7565c2bee693
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
test: /[\\/]node_modules[\\/]/,
name: `thailpha-lib`,
chunks: `all`,
},
},
},
},
}
module.exports = [client]