]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/web/js/ui/default/staff/webpack.config.js
LP1751520: Add contextMenu Module to Vendor Bundle
[working/Evergreen.git] / Open-ILS / web / js / ui / default / staff / webpack.config.js
1 const path = require('path');
2 const merge = require('webpack-merge');
3 const webpack = require('webpack');
4 const CleanWebpackPlugin = require('clean-webpack-plugin');
5 const UglifyJSPlugin = require('uglifyjs-webpack-plugin');
6 const CopyWebpackPlugin = require('copy-webpack-plugin');
7
8 const buildPath = 'build';
9
10 const CSS_FILES = [
11   'node_modules/angular-hotkeys/build/hotkeys.min.css',
12   'node_modules/bootstrap/dist/css/bootstrap.min.css',
13   'node_modules/ng-toast/dist/ngToast.min.css',
14   'node_modules/ng-toast/dist/ngToast-animations.min.css',
15   'node_modules/angular-tree-control/css/tree-control.css',
16   'node_modules/angular-tree-control/css/tree-control-attribute.css',
17   'node_modules/angular-tablesort/tablesort.css'
18 ];
19
20 const FONT_FILES = [
21   'node_modules/bootstrap/dist/fonts/glyphicons-halflings-regular.eot',
22   'node_modules/bootstrap/dist/fonts/glyphicons-halflings-regular.svg',
23   'node_modules/bootstrap/dist/fonts/glyphicons-halflings-regular.ttf',
24   'node_modules/bootstrap/dist/fonts/glyphicons-halflings-regular.woff',
25   'node_modules/bootstrap/dist/fonts/glyphicons-halflings-regular.woff2'
26 ];
27
28 const IMAGE_FILES = [
29   'node_modules/angular-tree-control/images/sample.png',
30   'node_modules/angular-tree-control/images/node-opened-2.png',
31   'node_modules/angular-tree-control/images/folder.png',
32   'node_modules/angular-tree-control/images/node-closed.png',
33   'node_modules/angular-tree-control/images/node-closed-light.png',
34   'node_modules/angular-tree-control/images/node-opened.png',
35   'node_modules/angular-tree-control/images/node-opened-light.png',
36   'node_modules/angular-tree-control/images/folder-closed.png',
37   'node_modules/angular-tree-control/images/node-closed-2.png',
38   'node_modules/angular-tree-control/images/file.png'
39 ]
40
41 // Some common JS files are left un-bundled.
42 // https://github.com/webpack/webpack/issues/3128
43 const JS_FILES = [
44   './node_modules/moment/min/moment-with-locales.min.js',
45   './node_modules/moment-timezone/builds/moment-timezone-with-data.min.js'
46 ]
47
48
49 // Copy files as-is from => to.
50 const directCopyFiles = [
51
52   // jquery is copied to the common build location, up one directory.
53   {from: './node_modules/jquery/dist/jquery.min.js', 
54      to: __dirname + '/../common/build/js'}
55 ];
56
57 CSS_FILES.forEach(file => directCopyFiles.push({from: file, to: './css'}));
58 FONT_FILES.forEach(file => directCopyFiles.push({from: file, to: './fonts'}));
59 IMAGE_FILES.forEach(file => directCopyFiles.push({from: file, to: './images'}));
60 JS_FILES.forEach(file => directCopyFiles.push({from: file, to: './js'}));
61
62 // EG JS files loaded on every page
63 const coreJsFiles = [
64   './services/core.js',
65   './services/strings.js',
66   './services/idl.js',
67   './services/event.js',
68   './services/net.js',
69   './services/auth.js',
70   './services/pcrud.js',
71   './services/env.js',
72   './services/org.js',
73   './services/startup.js',
74   './services/hatch.js',
75   './services/print.js',
76   './services/audio.js',
77   './services/coresvc.js',
78   './services/user.js',
79   './services/navbar.js',
80   './services/ui.js',
81   './services/i18n.js',
82   './services/date.js',
83   './services/op_change.js',
84   './services/lovefield.js'
85 ];
86
87 // 3rd-party (AKA vendor) JS files loaded on every page.
88 // Webpack knows to look in ./node_modules/
89 const vendorJsFiles = [
90   'angular',
91   'angular-route',
92   'angular-ui-bootstrap',
93   'angular-hotkeys',
94   'angular-file-saver',
95   'angular-location-update',
96   'angular-animate',
97   'angular-sanitize',
98   'angular-cookies',
99   'ng-toast',
100   'context-menu',
101   'angular-tree-control',
102   'iframe-resizer',
103   'angular-order-object-by',
104   'lovefield',
105   'angular-tablesort'
106 ];
107
108
109 let commmonOptions = {
110   // As of today, we are only bundling common files.  Individual app.js
111   // and optional service files are still imported via script tags.
112   entry: {
113     core: coreJsFiles,
114     vendor: vendorJsFiles
115   },
116   plugins: [
117     new CleanWebpackPlugin([buildPath]),
118     new CopyWebpackPlugin(directCopyFiles, {copyUnmodified: true}),
119     new webpack.optimize.CommonsChunkPlugin({
120       names: ['core', 'vendor'], // ORDER MATTERS
121       minChunks: 2 // TODO: huh?
122     })
123   ],
124   output: {
125     filename: 'js/[name].bundle.js',
126     path: path.resolve(__dirname, buildPath)
127   }
128 };
129
130 // improve debugging during development with inline source maps
131 // for bundled files.
132 let devOptions = {
133   devtool: 'inline-source-map',
134   plugins: [
135     // Avoid minifiying the core bundle in development mode.
136     // TODO: Add other bundles as necessary, but leave the 'vendor'
137     // bundle out, since we always want to minify that (it's big).
138     new UglifyJSPlugin({
139       exclude: [/core/]
140     })
141   ],
142   watchOptions: {
143     aggregateTimeout: 300,
144     poll: 1000,
145     ignored : [
146         /node_modules/
147     ]
148   }
149 };
150
151 // minify for production
152 let prodOptions = {
153   plugins: [
154     new UglifyJSPlugin()
155   ],
156 };
157
158 module.exports = env => env.prod ? 
159     merge(commmonOptions, prodOptions) : merge(commmonOptions, devOptions); 
160