forked from RocketChat/Rocket.Chat.Livechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpackOverride.config.js
75 lines (62 loc) · 1.62 KB
/
webpackOverride.config.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
/* eslint-disable quote-props */
const path = require('path');
const webpack = require('webpack');
const patchBabelLoader = (config) => {
config.module.rules = config.module.rules.map((rule) => {
if (rule.loader === 'babel-loader') {
const { enforce, test, loader, options } = rule;
return {
enforce,
test,
use: [
{ loader, options },
{ loader: 'preact-i18nline/webpack-loader' },
],
};
}
if (Array.isArray(rule.use) && rule.use.find(({ loader }) => loader === 'babel-loader')) {
return {
...rule,
use: [
...rule.use,
{ loader: 'preact-i18nline/webpack-loader' },
],
};
}
return rule;
});
};
const patchFileLoader = (config) => {
const fileLoader = config.module.rules.find(({ loader }) => /file-loader|url-loader/.test(loader));
fileLoader.test = /\.(woff2?|ttf|eot|jpe?g|png|gif|mp4|mov|ogg|webm)(\?.*)?$/i;
};
module.exports = (config/* , env */) => {
config.resolve.extensions.push('.css');
config.resolve.extensions.push('.scss');
config.resolve.extensions.push('.svg');
config.resolve.alias = Object.assign(
config.resolve.alias,
{
'styles': path.join(__dirname, './src/styles'),
'autoI18n': path.resolve(__dirname, './src/i18n'),
'icons': path.join(__dirname, './src/icons'),
'components': path.join(__dirname, './src/components'),
}
);
patchBabelLoader(config);
patchFileLoader(config);
config.module.rules.push({
test: /\.svg$/,
use: [
'desvg-loader/preact',
'svg-loader',
'image-webpack-loader',
],
});
config.plugins.push(
new webpack.ProvidePlugin({
I18n: ['autoI18n', 'default'],
})
);
return config;
};