-
Notifications
You must be signed in to change notification settings - Fork 4
/
webpack.config.js
188 lines (158 loc) · 4.8 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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
/**
* The contents of this file are subject to the OpenMRS Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://license.openmrs.org
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
* License for the specific language governing rights and limitations
* under the License.
* Copyright (C) OpenMRS, LLC. All Rights Reserved.
*/
// generated on 2017-01-04 using generator-openmrs-owa 0.3.2
'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 CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
const DedupePlugin = webpack.optimize.DedupePlugin;
const HtmlWebpackPlugin = require('html-webpack-plugin');
const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const WebpackOnBuildPlugin = require('on-build-webpack');
const nodeModulesDir = path.resolve(__dirname, '../node_modules');
const THIS_APP_ID = 'reactexample';
var plugins = [];
const nodeModules = {};
let outputFile = `.bundle`;
let outputPath;
var configJson;
let appEntryPoint;
let localOwaFolder;
let devtool;
var getConfig = function () {
var config;
try {
// look for config file
config = require('./config.json');
} catch (err) {
// create file with defaults if not found
config = {
'LOCAL_OWA_FOLDER': '/Users/djazayer/openmrs/reactexample/owa/',
'APP_ENTRY_POINT': 'http://localhost:8080/openmrs/owa/reactexample/index.html'
};
fs.writeFile('config.json', JSON.stringify(config));
} finally {
return config;
}
;
}
var config = getConfig();
/** Minify for production */
if (env === 'production') {
plugins.push(new UglifyPlugin({
output: {
comments: false,
},
minimize: true,
sourceMap: false,
compress: {
warnings: false
}
}));
plugins.push(new DedupePlugin());
outputFile = `${outputFile}.min.js`;
outputPath = `${__dirname}/dist/`;
plugins.push(new WebpackOnBuildPlugin(function (stats) {
//create zip file
var archiver = require('archiver');
var output = fs.createWriteStream(THIS_APP_ID + '.zip');
var archive = archiver('zip');
output.on('close', function () {
console.log('distributable has been zipped! size: ' + archive.pointer());
});
archive.on('error', function (err) {
throw err;
});
archive.pipe(output);
archive.directory(`${outputPath}`, '');
archive.finalize();
}))
} else if (env === 'deploy') {
outputFile = `${outputFile}.js`;
outputPath = `${config.LOCAL_OWA_FOLDER}${THIS_APP_ID}`;
devtool = 'source-map';
} else if (env === 'dev') {
outputFile = `${outputFile}.js`;
outputPath = `${__dirname}/dist/`;
devtool = 'source-map';
}
plugins.push(new BrowserSyncPlugin({
proxy: {
target: config.APP_ENTRY_POINT
}
}));
plugins.push(new CommonsChunkPlugin("vendor", "vendor.bundle.js"));
plugins.push(new HtmlWebpackPlugin({
template: './app/index.html',
inject: 'body'
}));
plugins.push(new CopyWebpackPlugin([{
from: './app/manifest.webapp'
}]));
plugins.push(new CopyWebpackPlugin([{
from: './app/img/omrs-button.png',
to: 'img/omrs-button.png'
}]));
var webpackConfig = {
quiet: false,
entry: {
app: `${__dirname}/app/js/reactexample.jsx`,
css: `${__dirname}/app/css/reactexample.css`,
vendor: [
'react',
'react-router',
'redux',
'redux-promise-middleware',
'redux-thunk',
'react-redux',
'whatwg-fetch',
'moment'
]
},
devtool: devtool,
target,
output: {
path: outputPath,
filename: '[name]' + outputFile,
},
module: {
loaders: [{
test: /\.jsx?$/,
loader: 'babel-loader',
exclude: /node_modules/,
query: {
presets: ['es2015', 'react'],
cacheDirectory: true
}
}, {
test: /\.css$/,
loader: 'style-loader!css-loader'
}, {
test: /\.(png|jpg|jpeg|gif|svg)$/,
loader: 'url'
}, {
test: /\.html$/,
loader: 'html'
}],
},
resolve: {
extensions: ['', '.js', '.jsx'],
},
plugins,
externals: nodeModules,
};
module.exports = webpackConfig;