-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.js
46 lines (40 loc) · 1.44 KB
/
build.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
// see: https://stackoverflow.com/a/69594493/13483323
const rewire = require('rewire');
const defaults = rewire('react-scripts/scripts/build.js');
const config = defaults.__get__('config');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const HTMLInlineCSSWebpackPlugin = require('html-inline-css-webpack-plugin').default;
const HtmlInlineScriptPlugin = require('html-inline-script-webpack-plugin');
const shouldInlineRuntimeChunk = process.env.INLINE_RUNTIME_CHUNK !== 'false';
// config.optimization.minimize = false;
// config.devtool = 'inline-source-map'
const path = require('path');
const fs = require('fs');
// Make sure any symlinks in the project folder are resolved:
// https://github.com/facebook/create-react-app/issues/637
const appDirectory = fs.realpathSync(process.cwd());
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
config.plugins[0] = new HtmlWebpackPlugin(
Object.assign(
{},
{
inject: 'body',
template: resolveApp('public/index.html'),
},
undefined
)
)
const webpack = require('webpack');
config.plugins.push(...[
shouldInlineRuntimeChunk &&
new HtmlInlineScriptPlugin(),
shouldInlineRuntimeChunk &&
new HTMLInlineCSSWebpackPlugin(),
new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
new webpack.SourceMapDevToolPlugin({
filename: '[file].map',
publicPath: 'https://richard-zheng.github.io/jxfw-ng/',
}),
].filter(Boolean))