-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.commons.js
280 lines (261 loc) · 7.95 KB
/
webpack.commons.js
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const FaviconsWebpackPlugin = require('favicons-webpack-plugin');
const Dotenv = require('dotenv-webpack');
const CopyWebpackPlugin = require('copy-webpack-plugin');
// default: we are building an SPA
const commonLibsPath = path.resolve(__dirname, 'node_modules', 'esn-frontend-common-libs');
const angularCommon = path.resolve(__dirname, 'node_modules', 'esn-frontend-common-libs', 'src', 'angular-common.js');
const angularInjections = path.resolve(__dirname, 'src', 'require-angular-injections.js');
const chartJs = path.resolve(__dirname, 'node_modules', 'esn-frontend-common-libs', 'src', 'frontend', 'components', 'Chart.js/Chart.js');
const materialAdmin = path.resolve(__dirname, 'node_modules', 'esn-frontend-common-libs', 'src', 'frontend', 'js', 'material.js');
const momentPath = path.resolve(__dirname, 'node_modules', 'moment', 'moment.js');
const pugLoaderOptions = {
root: `${__dirname}/node_modules/esn-frontend-common-libs/src/frontend/views`
};
const BASE_HREF = process.env.BASE_HREF || '/admin/';
const assetsFolder = 'assets/';
module.exports = {
mode: 'development',
entry: './src/index.js',
devtool: 'source-map',
output: {
filename: 'main.js',
path: path.resolve(__dirname, 'dist', assetsFolder),
publicPath: BASE_HREF + assetsFolder
},
resolve: {
alias: {
'moment/moment.js': momentPath,
moment$: momentPath
}
},
plugins: [
new Dotenv({ systemvars: true }),
new webpack.IgnorePlugin({ resourceRegExp: /codemirror/ }), // for summernote
new webpack.IgnorePlugin({ resourceRegExp: /^\.\/locale$/, contextRegExp: /moment$/ }),
new webpack.ProvidePlugin({
jQuery: 'jquery',
$: 'jquery',
'window.jQuery': 'jquery',
'window.$': 'jquery',
Chart: chartJs,
materialAdmin: materialAdmin,
angular: angularCommon,
'window.angularInjections': angularInjections,
angularDragula: 'angularjs-dragula/angularjs-dragula.js', // for unifiedinbox
sanitizeHtml: 'sanitize-html', // for unifiedinbox
DOMPurify: 'dompurify', // for unifiedinbox
localforage: 'localforage' // for calendar
}),
new webpack.IgnorePlugin({ resourceRegExp: /openpaas\.js$/, contextRegExp: /env$/ }),
/*
* To transform assets/index.pug to an HTML file, with webpack autoimporting the "main.js" bundle
*/
new HtmlWebpackPlugin({
template: './assets/index.pug',
filename: '../index.html'
}),
new FaviconsWebpackPlugin({
logo: './src/linagora.esn.admin/images/admin-center-icon.svg',
prefix: 'favicon/'
}),
new CopyWebpackPlugin({
patterns: [
{
from: path.resolve(__dirname, 'src', 'linagora.esn.admin', 'images', 'white-logo.svg'),
to: 'images'
},
{
from: path.resolve(__dirname, 'node_modules', 'socket.io-client', 'dist', 'socket.io.js'),
to: 'socket.io/socket.io.js'
},
{
from: path.resolve(__dirname, 'env', 'openpaas.js'),
to: 'env'
},
{
from: path.resolve(__dirname, 'src', 'linagora.esn.admin', 'images', 'logo-tiny.png'),
to: 'images'
}
]
})
],
devServer: {
contentBase: [path.resolve(__dirname, 'dist'), path.resolve(__dirname, 'node_modules', 'esn-frontend-login', 'dist')],
// contentBasePublicPath and writeToDisk are needed because webpack base path is 'assets' subfolder
// So index.html needs to be accessed explicitly from root 'dist' folder
contentBasePublicPath: [BASE_HREF + 'index.html', '/login'],
// and index.html needs to be copied explicitly to root 'dist' folder
writeToDisk: filePath => {
if (filePath.endsWith('index.html')) {
return (filePath);
}
},
compress: true,
host: '0.0.0.0',
disableHostCheck: true,
historyApiFallback: {
index: BASE_HREF + 'index.html'
},
port: 9900
},
module: {
rules: [
/*
for linagora.esn.unifiedinbox
can be removed after using a require for jmapDraft instead of a global $window.jmapDraft
.factory('jmapDraft', function($window) {
return $window.jmapDraft;
})
*/
{
test: require.resolve('jmap-draft-client/dist/jmap-draft-client.js'),
loader: 'expose-loader',
options: {
exposes: 'jmapDraft'
}
},
/*
for esn-frontend-common-libs
can be removed after using a require for emailAddresses instead of a global $window.emailAddresses
angular.module('esn.email-addresses-wrapper', [])
.factory('emailAddresses', function($window) {
return $window.emailAddresses;
});
*/
{
test: require.resolve('email-addresses'),
loader: 'expose-loader',
options: {
exposes: 'emailAddresses'
}
},
/*
for esn-frontend-common-libs
can be removed after using a require for autosize instead of a global $window.autosize
angular.module('esn.form.helper')
.factory('autosize', function($window) {
return $window.autosize;
})
*/
{
test: require.resolve('autosize'),
loader: 'expose-loader',
options: {
exposes: 'autosize'
}
},
/*
for esn-frontend-common-libs
can be removed after using a require for Autolinker instead of a global $window.Autolinker
angular.module('esn.autolinker-wrapper', [])
.factory('autolinker', function($window) {
return $window.Autolinker;
});
*/
{
test: require.resolve(commonLibsPath + '/src/frontend/components/Autolinker.js/dist/Autolinker.js'),
loader: 'expose-loader',
options: {
exposes: 'Autolinker'
}
},
/*
for angular-jstz in esn-frontend-common-libs
*/
{
test: require.resolve(commonLibsPath + '/src/frontend/components/jstzdetect/jstz.js'),
loader: 'expose-loader',
options: {
exposes: [
'jstz'
]
}
},
/*
usefull, at least for esn-frontend-common-libs / notification.js:
var notification = $window.$.notify(escapeHtmlFlatObject(options), angular.extend({}, getDefaultSettings(options), settings));
*/
{
test: require.resolve('jquery'),
loader: 'expose-loader',
options: {
exposes: '$'
}
},
{
test: /\.(woff(2)?|ttf|eot)(\?v=\d+\.\d+\.\d+)?$/,
use: [
{
loader: 'file-loader'
}
]
},
{
test: /all\.less$/,
use: [
{
loader: 'style-loader' // creates style nodes from JS strings
},
{
loader: 'css-loader' // translates CSS into CommonJS
},
{
loader: 'less-loader', // compiles Less to CSS
options: {
lessOptions: {
javascriptEnabled: true
}
}
}
]
},
{
test: /\.(png|jpe?g|gif|svg)$/i,
use: [
{
loader: 'file-loader',
options: {
outputPath: 'images'
}
}
]
},
/*
* for the "index.html" file of this SPA.
*
*/
{
test: /assets\/index\.pug$/,
use: [
{
loader: 'html-loader'
},
{
loader: 'pug-html-loader',
options: {
data: {
base: BASE_HREF
}
}
}
]
},
{
test: /\.pug$/i,
exclude: /assets\/index\.pug$/,
use: [
{
loader: 'apply-loader'
},
{
loader: 'pug-loader',
options: pugLoaderOptions
}
]
}
]
}
};