Advertisement
aolaniran

Untitled

Jun 13th, 2017
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.64 KB | None | 0 0
  1. /**
  2. * The contents of this file are subject to the OpenMRS Public License
  3. * Version 1.0 (the "License"); you may not use this file except in
  4. * compliance with the License. You may obtain a copy of the License at
  5. * http://license.openmrs.org
  6. * Software distributed under the License is distributed on an "AS IS"
  7. * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
  8. * License for the specific language governing rights and limitations
  9. * under the License.
  10. * Copyright (C) OpenMRS, LLC. All Rights Reserved.
  11. */
  12. // generated on 2017-01-25 using generator-openmrs-owa 0.4.0
  13. 'use strict';
  14. const webpack = require('webpack');
  15. const path = require('path');
  16. const fs = require('fs');
  17. const env = require('yargs').argv.mode;
  18. const target = require('yargs').argv.target;
  19.  
  20. const UglifyPlugin = webpack.optimize.UglifyJsPlugin;
  21.  
  22. const CommonsChunkPlugin = webpack.optimize.CommonsChunkPlugin;
  23.  
  24. const DedupePlugin = webpack.optimize.DedupePlugin;
  25.  
  26. const HtmlWebpackPlugin = require('html-webpack-plugin');
  27. const BrowserSyncPlugin = require('browser-sync-webpack-plugin');
  28. const CopyWebpackPlugin = require('copy-webpack-plugin');
  29. const WebpackOnBuildPlugin = require('on-build-webpack');
  30.  
  31.  
  32. const nodeModulesDir = path.resolve(__dirname, '../node_modules');
  33.  
  34. const THIS_APP_ID = 'cohortbuilder';
  35.  
  36. let plugins = [];
  37. const nodeModules = {};
  38.  
  39. let outputFile = `.bundle`;
  40. let outputPath;
  41.  
  42. let configJson;
  43. let appEntryPoint;
  44. let localOwaFolder;
  45.  
  46. let devtool;
  47.  
  48. const getConfig = function () {
  49. let config;
  50.  
  51. try {
  52. // look for config file
  53. config = require('./config.json');
  54. } catch (err) {
  55. // create file with defaults if not found
  56. config = {
  57. 'LOCAL_OWA_FOLDER': '/home/sims01/openmrs/openmrs-server/owa/',
  58. 'APP_ENTRY_POINT': 'http://localhost:8080/openmrs/owa/cohortbuilder/index.html'
  59. };
  60.  
  61. fs.writeFile('config.json', JSON.stringify(config));
  62.  
  63. } finally {
  64. return config;
  65. }
  66. };
  67. const config = getConfig();
  68.  
  69. /** Minify for production */
  70. if (env === 'production') {
  71.  
  72. plugins.push(new UglifyPlugin({
  73. output: {
  74. comments: false
  75. },
  76. minimize: true,
  77. sourceMap: false,
  78. compress: {
  79. warnings: false
  80. }
  81. }));
  82. plugins.push(new DedupePlugin());
  83. outputFile = `${outputFile}.min.js`;
  84. outputPath = `${__dirname}/dist/`;
  85. plugins.push(new WebpackOnBuildPlugin(function(stats){
  86. //create zip file
  87. const archiver = require('archiver');
  88. const output = fs.createWriteStream(THIS_APP_ID+'.zip');
  89. const archive = archiver('zip');
  90.  
  91. output.on('close', function () {
  92. /*eslint-disable no-console*/
  93. console.log('distributable has been zipped! size: '+archive.pointer());
  94. });
  95.  
  96. archive.on('error', function(err){
  97. throw err;
  98. });
  99.  
  100. archive.pipe(output);
  101.  
  102. archive.directory(`${outputPath}`, '');
  103.  
  104. archive.finalize();
  105. }));
  106.  
  107. } else if (env === 'deploy') {
  108. outputFile = `${outputFile}.js`;
  109. outputPath = `${config.LOCAL_OWA_FOLDER}${THIS_APP_ID}`;
  110. devtool = 'source-map';
  111.  
  112. } else if (env === 'dev') {
  113. outputFile = `${outputFile}.js`;
  114. outputPath = `${__dirname}/dist/`;
  115. devtool = 'source-map';
  116. }
  117.  
  118. plugins.push(new BrowserSyncPlugin({
  119. proxy: {
  120. target : config.APP_ENTRY_POINT
  121. }
  122. }));
  123.  
  124. plugins.push(new CommonsChunkPlugin("vendor", "vendor.bundle.js"));
  125.  
  126. plugins.push(new HtmlWebpackPlugin({
  127. template: './app/index.html',
  128. inject: 'body'
  129. }));
  130.  
  131. plugins.push(new CopyWebpackPlugin([{
  132. from: './app/manifest.webapp'
  133. }]));
  134.  
  135. plugins.push(new CopyWebpackPlugin([{
  136. from: './app/img/',
  137. to: 'img'
  138. }, {
  139. from: './app/img/loader.gif',
  140. to: 'img/loader.gif'
  141. },{
  142. from: 'libs',
  143. to: 'libs'
  144. }
  145. ]));
  146.  
  147. const webpackConfig = {
  148. quiet: false,
  149. entry: {
  150. app : `${__dirname}/app/js/cohortbuilder`,
  151. css: `${__dirname}/app/css/cohortbuilder.css`,
  152. vendor : [
  153. 'react', 'react-router'
  154. , 'redux', 'redux-promise-middleware', 'redux-thunk', 'react-redux'
  155. ]
  156. },
  157. devtool: devtool,
  158. target,
  159. output: {
  160. path: outputPath,
  161. filename: '[name]'+outputFile
  162. },
  163. module: {
  164. loaders: [{
  165. test: /\.jsx?$/,
  166. loader: 'babel-loader',
  167. exclude: /node_modules/,
  168. query: {
  169. presets: [ 'es2015', 'react' ],
  170. cacheDirectory : true
  171. }
  172. },{
  173. test: /\.css$/,
  174. loader: 'style-loader!css-loader'
  175. }, {
  176. test: /\.(png|jpg|jpeg|gif|svg)$/,
  177. loader: 'url'
  178. }, {
  179. test: /\.html$/,
  180. loader: 'html'
  181. }]
  182. },
  183. resolve: {
  184. root: path.resolve('./src'),
  185. extensions: ['', '.js', '.jsx']
  186. },
  187. plugins,
  188. externals: nodeModules
  189. };
  190.  
  191. module.exports = webpackConfig;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement