forked from LHNCBC/lforms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.fhir.config.js
109 lines (103 loc) · 3.5 KB
/
webpack.fhir.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
const TerserPlugin = require('terser-webpack-plugin');
function commonConfig() {
return {
output: {
path: __dirname,
},
optimization: {
minimizer: [
// Disable the terser cache, which does not detect changes to the
// webpack configuration (and sometimes keeps old configuration data).
// In particular, changes to the filename lformsFHIRAll.min.js did not
// show up in the output sourcemap when the cache was used. (However,
// I don't think it should show up at all, but that is separate problem.)
// Disabling the cache adds 4-5s to 31s build. Having the cache on
// resulted in several lost hours debugging a very confusing problem.
new TerserPlugin({
extractComments: false,
terserOptions: {
format: {
comments: false,
},
},
cache: false,
parallel: true,
sourceMap: true // Must be set to true if using source-maps in production
}),
],
},
module: {
rules: [
{
test: /\.m?js$/,
// exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env',
{
"targets": {
"browsers": "ie >= 11"
}
}
]]
}
}
}
]
}
};
}
function makeConfigs(env) {
// Limit build per env
let buildSTU3 = !env || !env.r4Only;
let buildFHIR = !env || !env.mainOnly;
let configs = [];
let fhirVersions = Object.keys(require('./src/fhir/versions'));
let versionedDist = 'lforms-'+require('./package.json').version;
let rootDirPath = require('path').resolve(__dirname);
let versionedDistPath = rootDirPath+'/dist/'+versionedDist;
let distFhirPath = versionedDistPath+'/fhir';
// Builds for each FHIR version
let fhirExternals = {
'../lforms-index': 'LForms',
'@lhncbc/ucum-lhc': 'LForms.ucumPkg'
}
var allFHIREntryFiles = [];
if (buildFHIR) {
for (let version of fhirVersions) {
if (version !== 'STU3' || buildSTU3) {
let entryFile = './src/fhir/'+version+'/fhirRequire.js';
allFHIREntryFiles.push(entryFile);
let nonMinConfig = commonConfig();
nonMinConfig.entry = entryFile;
nonMinConfig.output.path = rootDirPath+'/src/fhir/'+version;
nonMinConfig.output.filename = 'lformsFHIR.js';
nonMinConfig.mode = 'none';
nonMinConfig.externals = fhirExternals;
configs.push(nonMinConfig);
let minConfig = commonConfig();
minConfig.entry = entryFile;
minConfig.output.path = distFhirPath + '/' + version;
minConfig.output.filename = 'lformsFHIR.min.js';
minConfig.mode = 'production';
minConfig.externals = fhirExternals;
minConfig.devtool = 'source-map';
configs.push(minConfig);
}
}
// All FHIR versions together
let allFHIRConfig = commonConfig();
allFHIRConfig.entry = allFHIREntryFiles;
// Note: Setting the path as part of output.filename results in problems
// for the source map file.
allFHIRConfig.output.path = distFhirPath;
allFHIRConfig.output.filename = 'lformsFHIRAll.min.js';
allFHIRConfig.mode = 'production';
allFHIRConfig.devtool = 'source-map';
allFHIRConfig.externals = fhirExternals;
configs.push(allFHIRConfig);
}
return configs;
}
module.exports = makeConfigs;