-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.config.js
205 lines (196 loc) · 6.33 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
/* eslint no-console: 0, quote-props: 0*/
const path = require('path');
const webpack = require('webpack');
const HTMLWebpackPlugin = require('html-webpack-plugin');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const devMode = process.env.NODE_ENV !== 'production';
const analyzeBundle = process.env.ANALYZE_BUNDLE;
// console.log(`Starting Webpack (devmode: ${devMode})`);
let devtool;
if (devMode) {
devtool = 'eval-source-map';
} else {
devtool = 'nosources-source-map';
}
const babelLoader = {
loader: 'babel-loader',
options: {
presets: [
[require('babel-preset-env'), {
targets: {
browsers: devMode ?
['last 1 Chrome versions', 'last 1 Firefox versions'] :
['last 2 versions', 'safari >= 7', 'not ie < 11']
},
modules: false, // keeping the esm module syntax enables the minifier to go through the modules
loose: true,
debug: !devMode // log targets when creating dist
}],
require('babel-preset-react'),
],
plugins: [
require('babel-plugin-transform-object-rest-spread'), // transpile spread operator for objects
require('babel-plugin-transform-class-properties'), // transpile class properties
require('babel-plugin-transform-es2015-classes'), // react-hot-loader always needs this, see: https://github.com/gaearon/react-hot-loader/issues/313
require('babel-plugin-syntax-dynamic-import'), // enable dynamic imports (lazy loading)
require('babel-plugin-transform-runtime'),
...(devMode ? [
require('react-hot-loader/babel')
] : [
// require('babel-plugin-ramda'), // improve dead code elimination for ramda
require('babel-plugin-lodash'), // improve dead code elimination for lodash
[require('babel-plugin-transform-imports'), {
// improve dead code elimination for material-ui
'material-ui': { transform: 'material-ui/${member}', preventFullImport: true }
}]
])
],
babelrc: false
}
};
const cssModuleLoader = {
loader: 'css-loader',
query: {
modules: true,
localIdentName: '[name]__[local]___[hash:base64:5]'
}
};
const workerLoader = {
loader: 'worker-loader',
options: {
inline: false, // sepererate files will still be created as fallback
name: '[name].worker.js'
}
};
const imgLoader = [{
loader: 'file-loader',
options: { name: '[path][name].[ext]' }
}];
if (!devMode) {
const imageCompressor = {
loader: 'image-webpack-loader',
options: {
mozjpeg: { progressive: true, quality: 65 },
optipng: { enabled: false },
pngquant: { quality: '65-90', speed: 4 }
}
};
imgLoader.push(imageCompressor);
}
module.exports = {
entry: {
app: [
...(devMode ? [
'webpack-hot-middleware/client?reload=true', // hot middleware client
'react-hot-loader/patch'
] : []),
'./src/js/preloader.js'
]
},
plugins: [
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify(process.env.NODE_ENV),
'PLATFORM': JSON.stringify(process.env.PLATFORM),
}
}),
...(analyzeBundle ? [new BundleAnalyzerPlugin()] : [
new HTMLWebpackPlugin({
template: require('html-webpack-template'),
filename: 'index.html',
title: 'Doodle3D Transform',
appMountId: 'app',
inject: false,
mobile: true,
minify: !devMode && { html5: true },
hash: !devMode,
favicon: 'favicon.ico',
chunks: ['app'],
meta: [
{ 'http-equiv': 'Content-Type', content: 'text/html; charset=utf-8' },
{ property: 'og:image', content: 'https://doodle3d.com/img/screenshot.png' },
{ property: 'og:type', content: 'website' },
{ property: 'og:url', content: 'https://doodle3d.com' },
{ name: 'apple-mobile-web-app-capable', content: 'yes' },
{ name: 'apple-mobile-web-app-status-bar-style', content: 'black' },
{ name: 'mobile-web-app-capable', content: 'yes' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, minimal-ui, user-scalable=no' }
],
headHtmlSnippet: '<link rel="shortcut icon" href="img/apple-touch-icon-144x144-precomposed.png" type="image/x-icon" />\
<link rel="apple-touch-icon" href="img/apple-touch-icon-144x144-precomposed.png">',
}),
new HTMLWebpackPlugin({
template: require('html-webpack-template'),
filename: '404.html',
title: 'Page not found',
inject: false,
mobile: true,
bodyHtmlSnippet: 'Not found',
chunks: []
})
]),
...(devMode ? [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin()
// new BundleAnalyzerPlugin()
] : [])
],
output: {
filename: '[name].bundle.js',
chunkFilename: '[name].chunk.js',
path: path.resolve(__dirname, 'dist'),
publicPath: '/'
},
resolve: {
alias: {
'src': path.resolve(__dirname, 'src/'),
'data': path.resolve(__dirname, 'data/'),
'img': path.resolve(__dirname, 'img/'),
'workers': path.resolve(__dirname, 'workers/'),
'server': path.resolve(__dirname, 'server/'),
'CHANGELOG.md': path.resolve(__dirname, 'CHANGELOG.md')
}
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: [babelLoader]
}, {
test: /\.css$/,
exclude: /src\/css\/.+\.css$/,
use: ['style-loader', 'css-loader']
}, { // css modules
test: /src\/css\/.+\.css$/,
use: ['style-loader', cssModuleLoader]
}, {
test: /\.(png|jpeg|jpg|gif)$/,
use: imgLoader
}, {
test: /\.(woff)$/,
use: {
loader: 'file-loader'
}
}, {
test: /\.(svg|glsl|txt|md)$/,
use: 'raw-loader'
}, {
test: /\.json$/,
use: 'json-loader'
}, {
test: /\.yml$/,
use: 'yml-loader'
}, { // web workers
test: /\.worker.js$/,
use: [workerLoader, babelLoader]
}, { // make THREE global available to three.js examples
test: /three\/examples\/.+\.js/,
use: 'imports-loader?THREE=three'
}
]
},
// Source map creation
// https://webpack.js.org/configuration/devtool/
devtool
};