-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathextend.webpack.config.ts
49 lines (43 loc) · 1.54 KB
/
extend.webpack.config.ts
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
import path from 'path';
import { Configuration, RuleSetUseItem, RuleSetLoader } from 'webpack';
import HardSourceWebpackPlugin from 'hard-source-webpack-plugin';
// eslint-disable-next-line @typescript-eslint/no-var-requires
const defaultConfigHash = require('hard-source-webpack-plugin/lib/defaultConfigHash');
export default (config: Configuration) => {
if (config.module) {
config.module.rules.push({
// yaml or yml
test: /\.ya?ml$/,
loaders: ['json-loader', 'yaml-loader'],
});
// NOTE: nuxtが生成するルールだとbabelを通してしまうので tsはbabelを通さない
const tsRule = config.module.rules.find((rule) => {
return rule.test ? rule.test.toString() === '/\\.ts$/i' : false;
});
if (tsRule !== undefined && tsRule.use) {
tsRule.use = (tsRule.use as RuleSetUseItem[]).filter((loader) => {
const loaderName = (loader as RuleSetLoader).loader;
return loaderName !== undefined
? !/babel-loader/.test(loaderName)
: false;
});
}
}
if (config.plugins) {
config.plugins.push(
new HardSourceWebpackPlugin({
cacheDirectory: path.join(
__dirname,
'/node_modules/.cache/hard-source/[confighash]'
),
configHash: (webpackConfig) =>
defaultConfigHash(webpackConfig) + '-' + process.env.NODE_ENV,
})
);
config.plugins.push(
new HardSourceWebpackPlugin.ExcludeModulePlugin([
{ test: /extract-css-chunks-webpack-plugin[\\/]dist[\\/]loader/ },
])
);
}
};