-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathwebpack.config.tests.js
107 lines (90 loc) · 2.74 KB
/
webpack.config.tests.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
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-restricted-syntax */
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const ESLintPlugin = require("eslint-webpack-plugin");
const { getTemplates } = require("./webpack.helper");
const baseConfig = require("./webpack.config.base");
//* To add an extra test this script does not need to be modified.*
//* Please read CONTRIBUTING.MD *
module.exports = async (env) => {
const entries = {};
baseConfig.plugins = [];
baseConfig.plugins.push(
new ESLintPlugin({
fix: true,
extensions: ["ts", "tsx"],
exclude: ["node_modules", "tests"],
})
);
const getPlugin = (testType, template, chunk, modules) => {
const plugins = [];
if (modules) {
// eslint-disable-next-line guard-for-in
for (const key in modules) {
plugins.push(
new HtmlWebpackPlugin({
template: `./tests/html-templates/${template.template_id}.html`,
filename: `./pages/${testType}/${template.pageName}-${key}.html`,
favicon: "./tests/assets/favicon.png",
title: "Zappar UAR ThreeJS",
chunks: [chunk],
cdnModule: key,
})
);
}
} else {
plugins.push(
new HtmlWebpackPlugin({
template: `./tests/html-templates/${template.template_id}.html`,
filename: `./pages/${testType}/${template.pageName}.html`,
favicon: "./tests/assets/favicon.png",
title: "Zappar UAR ThreeJS",
chunks: [chunk],
cdnModule: false,
})
);
}
return plugins;
};
const setupHtmlWebpackPlugin = (opts) => {
for (const template of getTemplates(opts)) {
const chunk = `${opts.templateType}-${template.pageName}`;
entries[chunk] = `./tests/${opts.templateType}/${template.fullFileName}`;
const plugins = getPlugin(opts.templateType, template, chunk, opts.modules);
plugins.forEach((plugin) => baseConfig.plugins.push(plugin)); // todo
}
};
// *Setup Manual and Jest Tests*
const builds = [
{
templateType: "jest/module",
extension: ".tsx",
},
{
templateType: "manual",
extension: ".tsx",
},
];
builds.forEach(setupHtmlWebpackPlugin);
baseConfig.entry = entries;
baseConfig.output = {
filename: "js/[name].js",
path: `${__dirname}test-dist`,
};
baseConfig.devtool = "eval-cheap-source-map";
baseConfig.devServer = {
static: "./test-dist",
https: true,
host: "0.0.0.0",
open: false,
hot: true,
port: 8082,
client: {
overlay: false,
},
};
baseConfig.output.path = path.resolve(__dirname, "test-dist");
return baseConfig;
};
// = baseConfig;