-
Notifications
You must be signed in to change notification settings - Fork 7
/
webpack.config.js
135 lines (119 loc) · 3.46 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
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
/* 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 HtmlWebpackPlugin = require('html-webpack-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
var CopyWebpackPlugin = require('copy-webpack-plugin')
var nodeExternals = require('webpack-node-externals');
const libraryName = 'openmrs-contrib-uicommons';
const fileName = 'openmrs-contrib-uicommons';
const plugins = [];
const nodeModules = {};
let outputFile;
let outputDir;
let entry;
var configJson;
let appEntryPoint;
let localOwaFolder;
try{
configJson = require('./config.json');
appEntryPoint = configJson.APP_ENTRY_POINT;
localOwaFolder = configJson.LOCAL_OWA_FOLDER;
} catch(err){
appEntryPoint = "http://localhost:8080//openmrs//owa//openmrs-contrib-uicommons//index.html";
localOwaFolder = `${__dirname}/dist/`;
}
/** Don't bundle dependencies for node module */
if (target === 'web') {
outputFile = `${fileName}.bundle`;
}
/** Minify for production */
if (env === 'production') {
plugins.push(new UglifyPlugin({
compress: {
warnings: false
}
}));
outputFile = `${outputFile}.min.js`;
outputDir = `${__dirname}/lib`;
entry = `${__dirname}/openmrs-contrib-uicommons.js`;
} else if (env === 'dev') {
outputFile = `${outputFile}.js`;
outputDir = `${__dirname}/dist`;
entry = `${__dirname}/demo-app/app.module.js`;
plugins.push(new HtmlWebpackPlugin({
template: './demo-app/app.html',
inject: 'body'
}));
} else if (env === 'deploy'){
outputFile = `${outputFile}.js`;
outputDir = `${localOwaFolder}${libraryName}`;
entry = `${__dirname}/demo-app/app.module.js`;
plugins.push(new CopyWebpackPlugin([{
from: './demo-app/manifest.webapp'
}]));
plugins.push(new HtmlWebpackPlugin({
template: './demo-app/app.html',
inject: 'body'
}));
plugins.push(new BrowserSyncPlugin({
host: 'localhost',
port: 3000,
proxy: {
target : appEntryPoint
}
}));
}
/** Inject version number */
plugins.push(new webpack.DefinePlugin({
__OPENMRS_CONTRIB_UICOMMONS_VERSION__: JSON.stringify(require('./package.json').version),
}));
const config = {
entry: entry,
devtool: 'source-map',
target,
output: {
path: outputDir,
filename: outputFile,
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true,
},
module: {
loaders: [{
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader',
},{
test: /\.css$/,
loader: 'style-loader!css-loader'
}, {
test: /\.(png|jpg|jpeg|gif|svg)$/,
loaders: ['url',
'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false']
}, {
test: /\.html$/,
loader: 'html'
}, {
test: /\.scss$/,
loader: "style!css!sass?outputStyle=expanded&includePaths[]="
+ path.resolve(__dirname, "./node_modules/compass-mixins/lib")
},
{test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url'},
{test: /\.woff2(\?v=\d+\.\d+\.\d+)?$/, loader: 'url'},
{test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/, loader: 'url'},
{test: /\.eot(\?v=\d+\.\d+\.\d+)?$/, loader: 'url'},],
},
resolve: {
root: path.resolve('./src'),
extensions: ['', '.js'],
},
plugins,
externals: [nodeExternals()],
};
module.exports = config;