| 1 |
const path = require('path') |
= |
1 |
const path = require('path') |
| 2 |
const glob = require('glob') |
|
2 |
const glob = require('glob') |
| 3 |
const UglifyJsPlugin = require('uglifyjs-webpack-plugin') |
|
3 |
const UglifyJsPlugin = require('uglifyjs-webpack-plugin') |
| 4 |
|
|
4 |
|
| 5 |
|
|
5 |
|
| 6 |
|
|
6 |
|
| 7 |
|
|
7 |
|
| 8 |
const conf = (() => { |
|
8 |
const conf = (() => { |
| 9 |
const _conf = require('./build-config') |
|
9 |
const _conf = require('./build-config') |
| 10 |
return require('deepmerge').all([{}, _conf.base || {}, _conf[process.env.NODE_ENV] || {}]) |
|
10 |
return require('deepmerge').all([{}, _conf.base || {}, _conf[process.env.NODE_ENV] || {}]) |
| 11 |
})() |
|
11 |
})() |
| 12 |
|
|
12 |
|
| 13 |
conf.buildPath = path.resolve(__dirname, conf.buildPath) |
|
13 |
conf.buildPath = path.resolve(__dirname, conf.buildPath) |
| 14 |
|
|
14 |
|
| 15 |
|
|
15 |
|
| 16 |
|
|
16 |
|
| 17 |
|
|
17 |
|
| 18 |
const TRANSPILE_PACKAGES = [ |
|
18 |
const TRANSPILE_PACKAGES = [ |
| 19 |
'bootstrap', |
|
19 |
'bootstrap', |
| 20 |
'bootstrap-slider', |
|
20 |
'bootstrap-slider', |
| 21 |
'popper.js', |
|
21 |
'popper.js', |
| 22 |
'bootstrap-table', |
|
22 |
'bootstrap-table', |
| 23 |
'shepherd.js', |
|
23 |
'shepherd.js', |
| 24 |
'flot', |
|
24 |
'flot', |
| |
|
-+ |
25 |
'plyr', |
| |
|
|
26 |
'rangetouch', |
| 25 |
] |
= |
27 |
] |
| 26 |
|
|
28 |
|
| 27 |
const packageRejex = package => `(?:\\\\|\\/)${package}(?:\\\\|\\/).+?\\.js$` |
|
29 |
const packageRejex = package => `(?:\\\\|\\/)${package}(?:\\\\|\\/).+?\\.js$` |
| 28 |
|
|
30 |
|
| 29 |
|
|
31 |
|
| 30 |
|
|
32 |
|
| 31 |
|
|
33 |
|
| 32 |
const collectEntries = () => { |
|
34 |
const collectEntries = () => { |
| 33 |
const fileList = glob.sync(`!(${conf.exclude.join('|')})!(_)*.@(js|es6)`) || [] |
|
35 |
const fileList = glob.sync(`!(${conf.exclude.join('|')})!(_)*.@(js|es6)`) || [] |
| 34 |
return fileList.reduce((entries, file) => { |
|
36 |
return fileList.reduce((entries, file) => { |
| 35 |
const filePath = file.replace(/\\/g, '/') |
|
37 |
const filePath = file.replace(/\\/g, '/') |
| 36 |
return { ...entries, [filePath.replace(/\.(?:js|es6)$/, '')]: `./${filePath}` } |
|
38 |
return { ...entries, [filePath.replace(/\.(?:js|es6)$/, '')]: `./${filePath}` } |
| 37 |
}, {}) |
|
39 |
}, {}) |
| 38 |
} |
|
40 |
} |
| 39 |
|
|
41 |
|
| 40 |
const babelLoader = () => ({ |
|
42 |
const babelLoader = () => ({ |
| 41 |
loader: 'babel-loader', |
|
43 |
loader: 'babel-loader', |
| 42 |
options: { |
|
44 |
options: { |
| 43 |
presets: [['@babel/preset-env', { targets: 'last 2 versions, ie >= 10' }]], |
|
45 |
presets: [['@babel/preset-env', { targets: 'last 2 versions, ie >= 10' }]], |
| 44 |
plugins: ['@babel/plugin-transform-destructuring', '@babel/plugin-proposal-object-rest-spread', '@babel/plugin-transform-template-literals'], |
|
46 |
plugins: ['@babel/plugin-transform-destructuring', '@babel/plugin-proposal-object-rest-spread', '@babel/plugin-transform-template-literals'], |
| 45 |
babelrc: false |
|
47 |
babelrc: false |
| 46 |
} |
|
48 |
} |
| 47 |
}) |
|
49 |
}) |
| 48 |
|
|
50 |
|
| 49 |
const webpackConfig = { |
|
51 |
const webpackConfig = { |
| 50 |
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development', |
|
52 |
mode: process.env.NODE_ENV === 'production' ? 'production' : 'development', |
| 51 |
entry: collectEntries(), |
|
53 |
entry: collectEntries(), |
| 52 |
|
|
54 |
|
| 53 |
output: { |
|
55 |
output: { |
| 54 |
path: conf.buildPath, |
|
56 |
path: conf.buildPath, |
| 55 |
filename: '[name].js', |
|
57 |
filename: '[name].js', |
| 56 |
libraryTarget: 'window' |
|
58 |
libraryTarget: 'window' |
| 57 |
}, |
|
59 |
}, |
| 58 |
|
|
60 |
|
| 59 |
module: { |
|
61 |
module: { |
| 60 |
rules: [{ |
|
62 |
rules: [{ |
| 61 |
|
|
63 |
|
| 62 |
test: /\.es6$|\.js$/, |
|
64 |
test: /\.es6$|\.js$/, |
| 63 |
exclude: [path.resolve(__dirname, 'node_modules')], |
|
65 |
exclude: [path.resolve(__dirname, 'node_modules')], |
| 64 |
use: [babelLoader()] |
|
66 |
use: [babelLoader()] |
| 65 |
}, { |
|
67 |
}, { |
| 66 |
|
|
68 |
|
| 67 |
test: new RegExp(`(?:${TRANSPILE_PACKAGES.map(packageRejex).join(')|(?:')})`), |
|
69 |
test: new RegExp(`(?:${TRANSPILE_PACKAGES.map(packageRejex).join(')|(?:')})`), |
| 68 |
include: [path.resolve(__dirname, 'node_modules')], |
|
70 |
include: [path.resolve(__dirname, 'node_modules')], |
| 69 |
use: [babelLoader()] |
|
71 |
use: [babelLoader()] |
| 70 |
}, { |
|
72 |
}, { |
| 71 |
test: /\.css$/, |
|
73 |
test: /\.css$/, |
| 72 |
use: [ |
|
74 |
use: [ |
| 73 |
{ loader: 'style-loader' }, |
|
75 |
{ loader: 'style-loader' }, |
| 74 |
{ loader: 'css-loader' } |
|
76 |
{ loader: 'css-loader' } |
| 75 |
] |
|
77 |
] |
| 76 |
}, { |
|
78 |
}, { |
| 77 |
test: /\.scss$/, |
|
79 |
test: /\.scss$/, |
| 78 |
use: [ |
|
80 |
use: [ |
| 79 |
{ loader: 'style-loader' }, |
|
81 |
{ loader: 'style-loader' }, |
| 80 |
{ loader: 'css-loader' }, |
|
82 |
{ loader: 'css-loader' }, |
| 81 |
{ loader: 'sass-loader' } |
|
83 |
{ loader: 'sass-loader' } |
| 82 |
] |
|
84 |
] |
| 83 |
}, { |
|
85 |
}, { |
| 84 |
test: /\.html$/, |
|
86 |
test: /\.html$/, |
| 85 |
use: [{ |
|
87 |
use: [{ |
| 86 |
loader: 'html-loader', |
|
88 |
loader: 'html-loader', |
| 87 |
options: { minimize: true } |
|
89 |
options: { minimize: true } |
| 88 |
}] |
|
90 |
}] |
| 89 |
}] |
|
91 |
}] |
| 90 |
}, |
|
92 |
}, |
| 91 |
|
|
93 |
|
| 92 |
externals: { |
|
94 |
externals: { |
| 93 |
'jquery': 'jQuery', |
|
95 |
'jquery': 'jQuery', |
| 94 |
'moment': 'moment', |
|
96 |
'moment': 'moment', |
| 95 |
'datatables.net': '$.fn.dataTable', |
|
97 |
'datatables.net': '$.fn.dataTable', |
| 96 |
'spin.js': 'Spinner', |
|
98 |
'spin.js': 'Spinner', |
| 97 |
'jsdom': 'jsdom', |
|
99 |
'jsdom': 'jsdom', |
| 98 |
'd3': 'd3', |
|
100 |
'd3': 'd3', |
| 99 |
'eve': 'eve', |
|
101 |
'eve': 'eve', |
| 100 |
'velocity': 'Velocity', |
|
102 |
'velocity': 'Velocity', |
| 101 |
'hammer': 'Hammer', |
|
103 |
'hammer': 'Hammer', |
| 102 |
'raphael': 'Raphael', |
|
104 |
'raphael': 'Raphael', |
| 103 |
'jquery-mapael': 'Mapael', |
|
105 |
'jquery-mapael': 'Mapael', |
| 104 |
'pace': '"pace-progress"', |
|
106 |
'pace': '"pace-progress"', |
| 105 |
'popper.js': 'Popper', |
|
107 |
'popper.js': 'Popper', |
| 106 |
'jquery-validation': 'jQuery', |
|
108 |
'jquery-validation': 'jQuery', |
| 107 |
|
|
109 |
|
| 108 |
|
|
110 |
|
| 109 |
'canvas-to-blob': 'blueimpDataURLtoBlob', |
|
111 |
'canvas-to-blob': 'blueimpDataURLtoBlob', |
| 110 |
'blueimp-tmpl': 'blueimpTmpl', |
|
112 |
'blueimp-tmpl': 'blueimpTmpl', |
| 111 |
'load-image': 'blueimpLoadImage', |
|
113 |
'load-image': 'blueimpLoadImage', |
| 112 |
'load-image-meta': 'null', |
|
114 |
'load-image-meta': 'null', |
| 113 |
'load-image-scale': 'null', |
|
115 |
'load-image-scale': 'null', |
| 114 |
'load-image-exif': 'null', |
|
116 |
'load-image-exif': 'null', |
| 115 |
'jquery-ui/ui/widget': 'null', |
|
117 |
'jquery-ui/ui/widget': 'null', |
| 116 |
'./jquery.fileupload': 'null', |
|
118 |
'./jquery.fileupload': 'null', |
| 117 |
'./jquery.fileupload-process': 'null', |
|
119 |
'./jquery.fileupload-process': 'null', |
| 118 |
'./jquery.fileupload-image': 'null', |
|
120 |
'./jquery.fileupload-image': 'null', |
| 119 |
'./jquery.fileupload-video': 'null', |
|
121 |
'./jquery.fileupload-video': 'null', |
| 120 |
'./jquery.fileupload-validate': 'null', |
|
122 |
'./jquery.fileupload-validate': 'null', |
| 121 |
|
|
123 |
|
| 122 |
|
|
124 |
|
| 123 |
'./blueimp-helper': 'jQuery', |
|
125 |
'./blueimp-helper': 'jQuery', |
| 124 |
'./blueimp-gallery': 'blueimpGallery', |
|
126 |
'./blueimp-gallery': 'blueimpGallery', |
| 125 |
'./blueimp-gallery-video': 'blueimpGallery' |
|
127 |
'./blueimp-gallery-video': 'blueimpGallery' |
| 126 |
} |
|
128 |
} |
| 127 |
} |
|
129 |
} |
| 128 |
|
|
130 |
|
| 129 |
|
|
131 |
|
| 130 |
|
|
132 |
|
| 131 |
|
|
133 |
|
| 132 |
if (conf.sourcemaps) { |
|
134 |
if (conf.sourcemaps) { |
| 133 |
webpackConfig.devtool = conf.devtool |
|
135 |
webpackConfig.devtool = conf.devtool |
| 134 |
} |
|
136 |
} |
| 135 |
|
|
137 |
|
| 136 |
|
|
138 |
|
| 137 |
|
|
139 |
|
| 138 |
|
|
140 |
|
| 139 |
|
|
141 |
|
| 140 |
if (process.env.NODE_ENV !== 'production' && conf.minify) { |
|
142 |
if (process.env.NODE_ENV !== 'production' && conf.minify) { |
| 141 |
webpackConfig.plugins.push( |
|
143 |
webpackConfig.plugins.push( |
| 142 |
new UglifyJsPlugin({ |
|
144 |
new UglifyJsPlugin({ |
| 143 |
uglifyOptions: { |
|
145 |
uglifyOptions: { |
| 144 |
compress: { |
|
146 |
compress: { |
| 145 |
warnings: false |
|
147 |
warnings: false |
| 146 |
} |
|
148 |
} |
| 147 |
}, |
|
149 |
}, |
| 148 |
sourceMap: conf.sourcemaps, |
|
150 |
sourceMap: conf.sourcemaps, |
| 149 |
parallel: true |
|
151 |
parallel: true |
| 150 |
}) |
|
152 |
}) |
| 151 |
) |
|
153 |
) |
| 152 |
} |
|
154 |
} |
| 153 |
|
|
155 |
|
| 154 |
module.exports = webpackConfig |
|
156 |
module.exports = webpackConfig |