forked from joshhunt/destinySets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config-overrides.js
108 lines (94 loc) · 2.91 KB
/
config-overrides.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
const path = require('path');
const { merge } = require('lodash');
const { getLoader, injectBabelPlugin } = require('react-app-rewired');
const rewireReactHotLoader = require('react-app-rewire-hot-loader');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const WebpackVisualizerPlugin = require('webpack-visualizer-plugin');
const { UnusedFilesWebpackPlugin } = require('unused-files-webpack-plugin');
module.exports = function override(config, env) {
config = injectBabelPlugin('lodash', config);
config.entry.unshift('babel-polyfill');
const babelLoader = getLoader(config.module.rules, rule => {
return rule.loader && /[\/\\]babel-loader[\/\\]/.test(rule.loader);
});
babelLoader.include = [
babelLoader.include,
require.resolve('@destiny-plumbing/definitions')
];
const cssLoader = getLoader(
config.module.rules,
rule => String(rule.test) === String(/\.css$/)
);
let stylusRules;
if (false) {
config.plugins.push(
new UnusedFilesWebpackPlugin({
patterns: ['src/**/*.*']
})
);
}
config.plugins.push(
new WebpackVisualizerPlugin({
filename: './build/stats.html'
})
);
if (env === 'development') {
config = rewireReactHotLoader(config, env);
stylusRules = {
test: /\.styl$/,
use: [
{ loader: 'style-loader', options: { sourceMap: true } },
{
loader: 'css-loader',
options: {
sourceMap: true,
modules: true,
importLoaders: 2,
localIdentName: '[folder]--[local]--[hash:base64:2]'
}
},
{ loader: 'postcss-loader', options: { sourceMap: true } },
{ loader: 'stylus-loader', options: { sourceMap: true } }
]
};
} else {
const cssExtractTextLoader = cssLoader.loader[0];
if (!cssExtractTextLoader.loader.includes('extract-text-webpack-plugin')) {
throw new Error('Unable to find extract-text loader for CSS, aborting');
}
stylusRules = {
test: /\.styl$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
options: {
sourceMap: true,
modules: true,
importLoaders: 2,
localIdentName: '[folder]--[local]--[hash:base64:2]'
}
},
{ loader: 'postcss-loader', options: { sourceMap: true } },
{ loader: 'stylus-loader', options: { sourceMap: true } }
]
})
};
}
const oneOfRule = config.module.rules.find(rule => rule.oneOf !== undefined);
if (oneOfRule) {
oneOfRule.oneOf.unshift(stylusRules);
} else {
// Fallback to previous behaviour of adding to the end of the rules list.
config.module.rules.push(stylusRules);
}
// throw 'Stopping';
return merge(config, {
resolve: {
alias: {
app: path.resolve(__dirname, 'src')
}
}
});
};