-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathwebpack.config.js
More file actions
142 lines (139 loc) · 4.49 KB
/
Copy pathwebpack.config.js
File metadata and controls
142 lines (139 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/**
`chart.js` and `chartjs-plugin-annotation.js` do not have an ES5 distribution
by default. The annotation plugin though import chart.js and chart.js' helpers
in such a way that if we are not careful to install the whole chart.js module
in vendor/chart.js/ and update the modules path (resolveLoader.modules)
properly, we end-up with an ES6 code base in /static/cache/ (checked by
es-check in Makefile rule).
The annotation plugin also needs to be registered (done through
`chart-bundle.js`).
*/
const fs = require('fs');
const path = require('path');
const webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
const confPaths = JSON.parse(fs.readFileSync('webpack-conf-paths.json').toString())
module.exports = env => ({
mode: 'production',
target: ['web', 'es5'],
entry: {
assess: [
'js/chart-bundle.js',
'js/djaodjin-survey-vue.js',
'js/djaodjin-pages-vue.js',
'js/assess-vue.js',
],
editors: [
'js/djaodjin-survey-vue.js',
'js/djaodjin-pages-vue.js',
'js/editors-vue.js',
],
reporting: [
'js/chart-bundle.js',
'js/djaodjin-survey-vue.js',
'js/reporting-vue.js',
],
},
module: {
rules:[{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: [['@babel/preset-env', {
configPath: __dirname + "/package.json",
debug: true,
//useBuiltIns: 'usage',
// XXX If we starts to use the polyfill, there is a problem
// with Vue/extend in 'js/assess-vue.js'.
corejs: "3.22"
}]]
}
}
}, {
test: /djresources\.js$/,
loader: 'expose-loader',
type: "javascript/auto",
options: {
exposes: [{
globalName: 'clearMessages',
moduleLocalName: 'clearMessages',
}, {
globalName: 'showMessages',
moduleLocalName: 'showMessages',
}, {
globalName: 'showErrorMessages',
moduleLocalName: 'showErrorMessages',
}, {
globalName: 'getUrlParameter',
moduleLocalName: 'getUrlParameter',
}, {
globalName: 'djApi',
moduleLocalName: 'djApi',
}]
}
}
]
},
output: {
path: path.resolve(__dirname, 'htdocs/static/cache'),
filename: env.app_version_suffix ? '[name]' + env.app_version_suffix + '.js' : '[name].js',
},
externals: {
jQuery: 'jQuery',
},
optimization: {
minimize: true,
minimizer: [
new TerserPlugin({
terserOptions: {
mangle: {
reserved: ['clearMessages', 'showMessages', 'showErrorMessages', 'getUrlParameter', 'djApi'],
properties: false,
},
}
}),
],
},
plugins: [
new webpack.LoaderOptionsPlugin({
debug: true
}),
new webpack.ProvidePlugin({
httpRequestMixin: [
'js/djresourcesvue.js', 'httpRequestMixin'],
itemMixin: ['js/djresourcesvue.js', 'itemMixin'],
itemListMixin: ['js/djresourcesvue.js', 'itemListMixin'],
paramsMixin: ['js/djresourcesvue.js', 'paramsMixin'],
typeAheadMixin: ['js/djresourcesvue.js', 'typeAheadMixin'],
accountDetailMixin: [
'js/djresourcesvue.js', 'accountDetailMixin'],
userDetailMixin: [
'js/djresourcesvue.js', 'userDetailMixin'],
QueryAccountsByAffinity: [
'js/djaodjin-survey-vue.js', 'QueryAccountsByAffinity'],
QueryAccountsByAnswers: [
'js/djaodjin-survey-vue.js', 'QueryAccountsByAnswers'],
practicesListMixin: [
'js/djaopsp-resources-vue.js', 'practicesListMixin'],
})
],
resolve: {
fallback: {
"fs": require.resolve("fs"),
"http": require.resolve("stream-http"),
"https": require.resolve("https-browserify"),
"querystring": require.resolve("querystring-es3"),
"stream": require.resolve("stream-browserify"),
"url": require.resolve("url/"),
"util": require.resolve("util/")
},
modules: [path.resolve(__dirname, 'djaopsp/static/vendor')].concat(
confPaths.node_modules),
},
resolveLoader: {
modules: [path.resolve(__dirname, 'djaopsp/static/vendor')].concat(
confPaths.node_modules),
}
});