-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwebpack.config.client.ts
More file actions
260 lines (251 loc) · 7.83 KB
/
webpack.config.client.ts
File metadata and controls
260 lines (251 loc) · 7.83 KB
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/**
* Copyright 2016 DanceDeets.
*/
import webpack from 'webpack';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import OptimizeCssAssetsPlugin from 'optimize-css-assets-webpack-plugin';
import ManifestPlugin from 'webpack-manifest-plugin';
import ChunkManifestPlugin from 'chunk-manifest-webpack-plugin';
import WebpackMd5Hash from 'webpack-md5-hash';
import path from 'path';
import { argv as env } from 'yargs';
import pleeease from 'pleeease';
interface WebpackModule {
userRequest?: string;
}
function isJQuery(module: WebpackModule): boolean {
const userRequest = module.userRequest;
if (typeof userRequest !== 'string') {
return false;
}
if (userRequest.endsWith('css')) {
return false; // leave it in the parent commons.sccchunk
}
const common = ['jquery'];
for (const elem of common) {
if (userRequest.indexOf(elem) > -1) {
return true;
}
}
return false;
}
const prod = !(env as { debug?: boolean }).debug;
const ifProd = <T>(plugin: T): T | null => (prod ? plugin : null);
const entry: Record<string, string> = {
addEvent: './assets/js/addEvent.js',
bracketsExec: './assets/js/bracketsExec.js',
calendarExec: './assets/js/calendarExec.js',
homepageReact: './assets/js/homepageReactExec.js',
homepage: './assets/js/homepage.js',
normalPage: './assets/js/normalPage.js',
classResultsExec: './assets/js/classResultsExec.js',
eventExec: './assets/js/eventExec.js',
eventSearchResultsExec: './assets/js/eventSearchResultsExec.js',
topicExec: './assets/js/topicExec.js',
tutorialExec: './assets/js/tutorialExec.js',
tutorialCategoryExec: './assets/js/tutorialCategoryExec.js',
};
const config: webpack.Configuration = {
entry,
output: {
path: path.join(__dirname, 'dist/js'),
filename: prod ? '[name].[chunkhash].js' : '[name].js',
chunkFilename: prod ? '[name].[chunkhash].js' : '[name].js',
},
devtool: prod ? 'source-map' : 'cheap-eval-source-map',
plugins: [
new webpack.ProvidePlugin({
fetch:
'imports-loader?this=>global!exports-loader?global.fetch!whatwg-fetch',
}),
// Only import the english locale for moment.js:
new webpack.ContextReplacementPlugin(/moment[/\\]locale$/, /en$/),
new webpack.DefinePlugin({
'process.env': {
REACT_SPINKIT_NO_STYLES: JSON.stringify(true), // Import just the spinners we care about
NODE_ENV: JSON.stringify(prod ? 'production' : ''),
BROWSER: JSON.stringify(true),
},
}),
new ExtractTextPlugin({
filename: prod ? '../css/[name].[contenthash].css' : '../css/[name].css',
}),
new (webpack.optimize as any).CommonsChunkPlugin({
name: 'jquery',
// For now this is *after* 'common', and so gets loaded first.
// When we move jquery out of assets/js/common.js, we can flip these.
chunks: ['common', ...Object.keys(entry)],
minChunks: isJQuery,
}),
new (webpack.optimize as any).CommonsChunkPlugin({
name: 'common',
chunks: ['homepage', 'normalPage', 'eventExec', 'eventSearchResultsExec'],
minChunks: 2,
}),
new (webpack.optimize as any).ModuleConcatenationPlugin(),
ifProd(
new (webpack.optimize as any).UglifyJsPlugin({
sourceMap: true,
compress: {
warnings: true,
},
})
),
ifProd(
new OptimizeCssAssetsPlugin({
canPrint: false,
})
),
ifProd(new (webpack as any).HashedModuleIdsPlugin()),
ifProd(new WebpackMd5Hash()),
ifProd(
new ManifestPlugin({
fileName: '../manifest.json',
})
),
ifProd(
new ChunkManifestPlugin({
filename: '../chunk-manifest.json',
manifestVariable: 'webpackManifest',
})
),
].filter((x): x is webpack.Plugin => x !== null),
resolve: {
extensions: ['.js', '.jsx'],
},
module: {
rules: [
// Disabled eslint-loader due to eslint version incompatibilities
// {
// test: /\.jsx?$/,
// use: 'eslint-loader',
// exclude: /node_modules(?!\/dancedeets-common)/,
// enforce: 'pre',
// },
{
test: /\.jsx?$/,
exclude: /node_modules(?!\/dancedeets-common)/,
use: {
loader: 'babel-loader',
options: {
babelrc: false, // Don't use .babelrc files from dancedeets-common
presets: [
[
'@babel/preset-env',
{
modules: false,
},
],
'@babel/preset-react',
],
plugins: ['@babel/plugin-transform-flow-strip-types'],
},
},
},
{
test: /\.s?css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: 'postcss-loader',
options: {
plugins: () => [
// This handles a bunch for us:
// autoprefixer: Adds vendor prefixes to CSS, using Autoprefixer.
// filters: Converts CSS shorthand filters to SVG equivalent
// rem: Generates pixel fallbacks for rem units
// pseudoElements: Converts pseudo-elements using CSS3 syntax
// (two-colons notation like ::after, ::before, ::first-line and ::first-letter) with the old one
// opacity: Adds opacity filter for IE8 when using opacity property
//
// We intentionally don't do any minification, since we'd prefer to run uncss first
pleeease({
import: false,
rebaseUrls: false,
minifier: false,
browsers: ['> 2%'],
}),
/* uncss.postcssPlugin({
ignore: [
'.animated',
'.animated.flip',
new RegExp('\\.alert\w+\\b'),
new RegExp('\\.(in|open|collapsing)\\b'),
new RegExp('\\.header-v6(\\.header-dark-transparent)?\\.header-fixed-shrink'),
],
html: ['example_html/new_homepage.html'],
}),*/
],
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
implementation: require('sass'),
},
},
],
}),
},
{
test: /\.(png|gif)$/,
use: [
{
loader: 'url-loader',
options: {
limit: 10000,
name: '../img/[name].[ext]',
},
},
// Disabled image-webpack-loader - binaries not installed with --ignore-scripts
// {
// loader: 'image-webpack-loader',
// options: {
// bypassOnDebug: true,
// query: {
// optipng: {
// optimizationLevel: 7,
// },
// gifsicle: {
// interlaced: false,
// },
// },
// },
// },
],
},
{
test: /\.jpg$/,
use: {
loader: 'file-loader',
options: {
name: '../img/[name].[ext]',
},
},
},
{
test: /\.(ttf|otf|eot|svg|woff(2)?)(\?[a-z0-9=.]+)?$/,
use: {
loader: 'file-loader',
options: {
name: '../fonts/[name].[ext]',
},
},
},
{
// This exposes React variable so Chrome React devtools work
test: require.resolve('react'),
use: 'expose-loader?React',
},
],
},
};
export default config;