-
Notifications
You must be signed in to change notification settings - Fork 57
/
webpack.fhir.config.js
105 lines (96 loc) · 3.09 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
const TerserPlugin = require('terser-webpack-plugin');
function commonConfig() {
return {
output: {
path: __dirname,
},
cache: false,
optimization: {
minimizer: [
new TerserPlugin({
extractComments: false,
terserOptions: {
format: {
comments: false,
},
sourceMap: true // Must be set to true if using source-maps in production
},
parallel: true
}),
],
},
module: {
rules: [
{
test: /\.m?js$/,
// exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader'
}
}
]
}
};
}
function makeConfigs(env) {
// Limit build per env
let buildOnly = env?.buildOnly;
let debugging = env?.debugging;
let configs = [];
let fhirVersions = Object.keys(require('./src/fhir/versions'));
//let versionedDist = 'lforms-'+require('./package.json').version; // no longer versioning during build except when zipping
let unversionedDist = 'lforms';
let rootDirPath = require('path').resolve(__dirname);
let unversionedDistPath = rootDirPath+'/dist/'+unversionedDist;
let distFhirPath = unversionedDistPath+'/fhir';
// Builds for each FHIR version
let fhirExternals = {
'../lforms-index': 'LForms',
'@lhncbc/ucum-lhc': 'LForms.ucumPkg'
}
var allFHIREntryFiles = [];
for (let version of fhirVersions) {
// if there is buildOnly parameter, skip this version if it is not the specified version
if (buildOnly && buildOnly !== version) continue;
let entryFile = './src/fhir/'+version+'/fhirRequire.js';
allFHIREntryFiles.push(entryFile);
let nonMinConfig = commonConfig();
nonMinConfig.entry = entryFile;
nonMinConfig.output.path = rootDirPath+'/dist/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 = debugging? 'none' : '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 = debugging? 'none' : 'production';
if (debugging) {
allFHIRConfig.output.publicPath = '/lforms/fhir';
let serverPort = require('./package.json').config.testPortFhir;
allFHIRConfig.devServer = {
port: serverPort,
static: {
directory: __dirname,
}
};
}
allFHIRConfig.devtool = 'source-map';
allFHIRConfig.externals = fhirExternals;
configs.push(allFHIRConfig);
return configs;
}
module.exports = makeConfigs;