-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconfig-overrides.js
84 lines (75 loc) · 2.52 KB
/
config-overrides.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
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
const curDir = __dirname;
const path = require('path');
const allowedBuildTypes = ['commonjs', 'umd'];
function findAndFixCSSPath(config, newCssFilePath) {
const cssPlugin = config.plugins.filter(o=>o&&o.options&&typeof o.options==='object'&&typeof o.options.filename==='string'&&o.options.filename.indexOf(".css")&&o.options.chunkFilename)[0];
if(cssPlugin){
cssPlugin.options.filename = newCssFilePath;
}
}
function override(config, env) {
config.resolve.alias["react"] = "preact/compat";
config.resolve.alias["react-dom/test-utils"] = "preact/test-utils";
config.resolve.alias["react-dom"] = "preact/compat";
config.resolve.alias['@'] = path.resolve(__dirname, 'src');
//config.output.chunkFilename = '[chunkhash].[name].js';
config.optimization.minimizer = [
// Prevent function reduction in preact for preact-compat to work.
new UglifyJsPlugin({
include: /preact\.js$/,
uglifyOptions: {
compress: {
reduce_funcs: false,
},
},
}),
// Normal uglifying for everything else.
new UglifyJsPlugin({
exclude: /preact\.js$/,
cache: true,
parallel: true,
}),
];
if(env!=="production") {
return config;
}else{
const envBuildType = process.env.BUILD_TYPE;
if(envBuildType==="demo") {
return config;
}
const buildType = allowedBuildTypes.indexOf(envBuildType)!==-1?envBuildType:"commonjs";
return overrideGen(config, env, buildType, "my-eos."+buildType+".js");
}
}
function overrideGen(config, env, libraryTarget, outFile) {
config = Object.assign(config, {}, {output: Object.assign({}, config.output,{})});
findAndFixCSSPath(config, "my-eos.css");
config.optimization.runtimeChunk = false;
config.optimization.splitChunks = {
cacheGroups: {
default: false,
},
};
const libraryName = "MyEOS"
const outDir = "./build";
/**
* add library configurations to webpack config
*/
config.output.library = libraryName;
config.output.libraryTarget = libraryTarget;
if(libraryTarget==="umd") {
config.output.libraryExport = "default";
}
/**
* Change the webpack entry and output path
*/
//config.entry = { [libraryName]: path.resolve(__dirname,entryFile) };
config.entry = [
path.resolve(curDir, "./src/libEntryPoint.js"),
]
config.output.filename = outFile;
config.output.path = path.resolve(__dirname, outDir);
return config;
}
module.exports = override;