-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathwebpack.config.js
135 lines (128 loc) · 4.38 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
const path = require('path');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const ManifestPlugin = require('webpack-assets-manifest');
const isCI = !!process.env.CI
const PORTS = {
tutor: '8000',
shared: '8000',
exercises: '8001',
};
const isProduction = process.env.NODE_ENV === 'production';
const project = process.env.OX_PROJECT || 'tutor';
const port = process.env.DEV_PORT || PORTS[project] || '8000';
const host = process.env.OX_PROJECT_HOST || 'localhost';
const servePath = `http://${host}:${port}`;
const publicPath = process.env.PUBLIC_PATH || (isProduction ? '/dist/' : `${servePath}/dist/`);
const defaultEntry = `./${project}/index.js`;
const isTutor = project == 'tutor';
const ENTRIES = {
tutor: {
tutor: defaultEntry,
lmspair: './tutor/lms-pair.js',
},
exercises: { exercises: defaultEntry },
shared: { demo: './shared/demo.js' },
};
const config = {
mode: isProduction ? 'production' : 'development',
entry: ENTRIES[project],
output: {
filename: isProduction ? '[name]-[hash].min.js' : '[name].js',
path: path.resolve(__dirname, project, 'dist'),
chunkFilename: '[name]-chunk-[hash].js',
publicPath,
},
devtool: isProduction ? 'source-map' : 'inline-source-map',
module: {
rules: [
{
test: /\.tsx?$/, loader: 'ts-loader', exclude: /node_modules/,
options: {
transpileOnly: true,
},
},
{ test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel-loader' },
{ test: /\.(png|jpg|svg|gif)/, loader: 'file-loader', options: {} },
{ test: /\.scss$/, use: [ 'style-loader', 'css-loader', 'fast-sass-loader' ] },
{ test: /\.css$/, use: [ 'style-loader', 'css-loader' ] },
{ test: /\.(woff|woff2|eot|ttf)/, loader: 'url-loader',
options: { limit: 30000, name: '[name]-[hash].[ext]' } },
],
},
resolve: {
modules: [
'node_modules',
path.resolve(__dirname, project, 'src'),
],
alias: {
shared: path.resolve(__dirname, 'shared', 'src'),
},
extensions: ['.tsx', '.ts', '.js', '.jsx', '.json'],
},
plugins: [
// don't need locales and they're huge
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
// use custom definitions containing only zones we support
new webpack.NormalModuleReplacementPlugin(
/moment-timezone\/data\/packed\/latest\.json/,
require.resolve('./configs/timezone-definitions')
),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(isProduction ? 'production' : 'development'),
},
}),
new ManifestPlugin({
assets: process.env.RELEASE_VERSION ? { version: process.env.RELEASE_VERSION } : {},
entrypoints: true,
writeToDisk: true,
output: process.env.RELEASE_VERSION ? `${process.env.RELEASE_VERSION}-assets.json` : 'assets.json',
}),
],
optimization: {
splitChunks: {
chunks: 'all',
maxInitialRequests: (isProduction && isTutor) ? 5 : 1,
},
},
performance: {
maxEntrypointSize: 2.5 * 1000000, // 1MB
maxAssetSize: 2.1 * 1000000,
},
watch: !(isCI || isProduction),
watchOptions: {
ignored: /node_modules/,
},
devServer: {
contentBase: project,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, PATCH, OPTIONS',
'Access-Control-Allow-Headers': 'X-Requested-With, content-type, Authorization',
},
port,
publicPath,
historyApiFallback: true,
inline: !isCI,
quiet: false,
noInfo: false,
clientLogLevel: 'warning',
host,
filename: '[name].js',
hot: !isCI,
liveReload: !isCI,
stats: 'errors-only',
},
};
if (!isProduction) {
config.plugins.push(
new webpack.HotModuleReplacementPlugin(),
);
}
if (process.env.ANALYZE) {
config.plugins.push(
new BundleAnalyzerPlugin()
);
}
module.exports = config;