LP#1736269: Mark Missing Pieces is non-functional
[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   './node_modules/iframe-resizer/js/iframeResizer.contentWindow.min.js',
47   './node_modules/iframe-resizer/js/iframeResizer.min.js'
48 ]
49
50
51 // Copy files as-is from => to.
52 const directCopyFiles = [
53
54   // jquery is copied to the common build location, up one directory.
55   {from: './node_modules/jquery/dist/jquery.min.js', 
56      to: __dirname + '/../common/build/js'}
57 ];
58
59 CSS_FILES.forEach(file => directCopyFiles.push({from: file, to: './css'}));
60 FONT_FILES.forEach(file => directCopyFiles.push({from: file, to: './fonts'}));
61 IMAGE_FILES.forEach(file => directCopyFiles.push({from: file, to: './images'}));
62 JS_FILES.forEach(file => directCopyFiles.push({from: file, to: './js'}));
63
64 // EG JS files loaded on every page
65 const coreJsFiles = [
66   './services/core.js',
67   './services/strings.js',
68   './services/idl.js',
69   './services/event.js',
70   './services/net.js',
71   './services/auth.js',
72   './services/pcrud.js',
73   './services/env.js',
74   './services/org.js',
75   './services/startup.js',
76   './services/hatch.js',
77   './services/print.js',
78   './services/audio.js',
79   './services/coresvc.js',
80   './services/user.js',
81   './services/navbar.js',
82   './services/ui.js',
83   './services/i18n.js',
84   './services/date.js',
85   './services/op_change.js',
86   './services/lovefield.js'
87 ];
88
89 // 3rd-party (AKA vendor) JS files loaded on every page.
90 // Webpack knows to look in ./node_modules/
91 const vendorJsFiles = [
92   'angular',
93   'angular-route',
94   'angular-ui-bootstrap',
95   'angular-hotkeys',
96   'angular-file-saver',
97   'angular-location-update',
98   'angular-animate',
99   'angular-sanitize',
100   'angular-cookies',
101   'ng-toast',
102   'angular-tree-control',
103   'angular-tree-control/context-menu.js',
104   'angular-order-object-by',
105   'lovefield',
106   'angular-tablesort'
107 ];
108
109
110 let commmonOptions = {
111   // As of today, we are only bundling common files.  Individual app.js
112   // and optional service files are still imported via script tags.
113   entry: {
114     core: coreJsFiles,
115     vendor: vendorJsFiles
116   },
117   plugins: [
118     new CleanWebpackPlugin([buildPath]),
119     new CopyWebpackPlugin(directCopyFiles, {copyUnmodified: true}),
120     new webpack.optimize.CommonsChunkPlugin({
121       names: ['core', 'vendor'], // ORDER MATTERS
122       minChunks: 2 // TODO: huh?
123     })
124   ],
125   output: {
126     filename: 'js/[name].bundle.js',
127     path: path.resolve(__dirname, buildPath)
128   }
129 };
130
131 // improve debugging during development with inline source maps
132 // for bundled files.
133 let devOptions = {
134   devtool: 'inline-source-map',
135   plugins: [
136     // Avoid minifiying the core bundle in development mode.
137     // TODO: Add other bundles as necessary, but leave the 'vendor'
138     // bundle out, since we always want to minify that (it's big).
139     new UglifyJSPlugin({
140       exclude: [/core/]
141     })
142   ],
143   watchOptions: {
144     aggregateTimeout: 300,
145     poll: 1000,
146     ignored : [
147         /node_modules/
148     ]
149   }
150 };
151
152 // minify for production
153 let prodOptions = {
154   plugins: [
155     new UglifyJSPlugin()
156   ],
157 };
158
159 module.exports = env => env.prod ? 
160     merge(commmonOptions, prodOptions) : merge(commmonOptions, devOptions); 
161