-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.extend.js
83 lines (75 loc) · 2.85 KB
/
webpack.config.extend.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
/**
* Project's customized Webpack Configuration Extension
* ----------------------------------------------------
*
* this file is heavily inspired by `react-app-rewired` mechanism.
*
* it simply gives you the chance to hook into the default Webpack
* configuration as it is provided by `create-react-app`, and to
* change it so to match your project's needs.
*
* If you want to check out the default values look into:
* `./node_modules/marcopeg-react-scripts/config/webpack.config.${env}.js`
*
*/
const path = require('path');
const webpack = require('webpack');
const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPlugin;
const rtlcssLoader = path.resolve(__dirname, 'rtlcss-loader.js');
module.exports = (webpackConfig, env, { paths }) => {
// Support for RTL
/*
const isDev = webpackConfig.mode === 'development'
const sassRegex = /\.(scss|sass)$/.toString();
webpackConfig.module.rules[2].oneOf.some((rule, idx) => {
if (rule.test && rule.test.toString() === sassRegex) {
webpackConfig.module.rules[2].oneOf[idx][isDev ? 'use' : 'loader'].splice(
webpackConfig.module.rules[2].oneOf[idx][isDev ? 'use' : 'loader'].length - 1,
0,
rtlcssLoader)
return true;
}
});
*/
// Fix for flot resize
webpackConfig.module.rules[2].oneOf.splice(0, 0, {
test: /jquery\.flot\.resize\.js$/,
use: ['imports-loader?this=>window']
});
// Support for use custom .eslintrc
webpackConfig.module.rules.some(rule => {
if (Array.isArray(rule.use)) {
const eslintUse = rule.use.find(item =>
Object.keys(item.options).find(key => key === 'useEslintrc')
);
eslintOptions = eslintUse && eslintUse.options;
if (eslintOptions) {
eslintOptions.useEslintrc = true;
return true;
}
}
});
// Set globals for external plugins
webpackConfig.plugins = (webpackConfig.plugins || []).concat([
new webpack.ProvidePlugin({
$: 'jquery',
jQuery: 'jquery',
'window.jQuery': 'jquery',
'window.moment': 'moment',
moment: 'moment',
Raphael: 'raphael' // required by morris.js
})
]);
// Allow cofiguration of router base href
webpackConfig.plugins = (webpackConfig.plugins || []).concat([
new webpack.DefinePlugin({
PUBLIC_URL: JSON.stringify(process.env.PUBLIC_URL)
})
]);
// Enable BundleAnalyzerPlugin
// webpackConfig.plugins = (webpackConfig.plugins || []).concat([
// new BundleAnalyzerPlugin()
// ]);
// here you can extend your webpackConfig at will
return webpackConfig;
};