forked from dojo/cli-build-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
base.test.config.ts
59 lines (52 loc) · 1.56 KB
/
base.test.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
50
51
52
53
54
55
56
57
58
59
import * as MiniCssExtractPlugin from 'mini-css-extract-plugin';
import * as webpack from 'webpack';
import baseConfigFactory, { libraryName } from './base.config';
const WrapperPlugin = require('wrapper-webpack-plugin');
function webpackConfig(args: any): webpack.Configuration {
const config = baseConfigFactory(args);
const { plugins, module } = config;
const externals: any[] = (config.externals as any[]) || [];
const instrumenterOptions = args.legacy ? {} : { esModules: true };
config.plugins = [
...plugins!.filter((plugin) => {
return !(plugin instanceof MiniCssExtractPlugin) || (plugin as any).options.filename !== 'main.css';
}),
new WrapperPlugin({
test: /(all.*(\.js$))/,
footer: `typeof define === 'function' && define.amd && define(['${libraryName}'], function() {});`
})
];
if (module) {
module.rules = module.rules.map((rule) => {
if (Array.isArray(rule.use)) {
rule.use = rule.use.map((loader) => {
if (typeof loader === 'string') {
return loader;
}
const { loader: loaderName } = loader as webpack.RuleSetLoader;
if (loaderName === 'umd-compat-loader') {
return {
loader: loaderName,
options: {}
};
}
return loader;
});
}
return rule;
});
module.rules.push({
test: /src[\\\/].*\.ts(x)?$/,
use: {
loader: 'istanbul-instrumenter-loader',
options: instrumenterOptions
},
enforce: 'post'
});
}
externals.push(/^intern/);
config.externals = externals;
config.devtool = 'inline-source-map';
return config;
}
export default webpackConfig;