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