-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathwebpack.config.js
82 lines (73 loc) · 1.73 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
/* eslint-disable func-names */
'use strict';
const webpack = require('webpack');
const path = require('path');
const fs = require('fs');
const env = require('yargs').argv.mode;
const target = require('yargs').argv.target;
const UglifyPlugin = webpack.optimize.UglifyJsPlugin;
const libraryName = 'OpenMRS';
const fileName = 'openmrs';
const plugins = [];
const nodeModules = {};
let outputFile;
/** Don't bundle dependencies for node module */
if (target === 'web') {
outputFile = `${fileName}.bundle`;
} else if (target === 'node') {
outputFile = fileName;
fs.readdirSync('node_modules')
.filter(x =>
['.bin'].indexOf(x) === -1
)
.forEach(mod => {
nodeModules[mod] = `commonjs ${mod}`;
});
}
/** Minify for production */
if (env === 'production') {
plugins.push(new UglifyPlugin({
output: {
comments: false,
},
minimize: true,
}));
outputFile = `${outputFile}.min.js`;
} else if (env === 'dev') {
outputFile = `${outputFile}.js`;
}
/** Inject version number */
plugins.push(new webpack.DefinePlugin({
__OPENMRS_JS_VERSION__: JSON.stringify(require('./package.json').version),
}));
const config = {
entry: `${__dirname}/src/openmrs.js`,
devtool: 'source-map',
target,
output: {
path: `${__dirname}/lib`,
filename: outputFile,
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true,
},
module: {
preLoaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
}],
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
}],
},
resolve: {
root: path.resolve('./src'),
extensions: ['', '.js'],
},
plugins,
externals: nodeModules,
};
module.exports = config;