-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathwebpack.config.tests.js
138 lines (119 loc) · 3.89 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/* eslint-disable @typescript-eslint/no-var-requires */
/* eslint-disable no-restricted-syntax */
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyPlugin = require("copy-webpack-plugin");
const WebpackCdnPlugin = require("webpack-cdn-plugin");
const fetch = require("node-fetch");
const ESLintPlugin = require("eslint-webpack-plugin");
const { getTemplates, generateStandalone } = require("./webpack.helper");
const baseConfig = require("./webpack.config.base");
const getStandaloneVersions = require("./standalone-versions");
//* 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"],
})
);
generateStandalone();
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
}
};
baseConfig.plugins.push(
new CopyPlugin({
patterns: [{ from: "./umd", to: "./standalone/" }],
})
);
let CDN_URL = "../../../standalone/zappar-threejs.js";
if (env.POST_TEST) {
const CDN_RESPONSE = await fetch("https://libs.zappar.com/zappar-threejs/latest.json");
const CDN_DATA = await CDN_RESPONSE.json();
CDN_URL = CDN_DATA.cdn;
}
const modules = {};
for (const version of getStandaloneVersions()) {
modules[version] = [
{ name: "THREE", var: "THREE", path: "three.min.js", prodUrl: `https://cdnjs.cloudflare.com/ajax/libs/three.js/${version}/three.min.js` },
{ name: "THREE", var: "THREE", path: "three.min.js", prodUrl: CDN_URL }, //* Hacky way to load in our local script.
];
}
// *Setup Manual and Jest Tests*
const builds = [
{
templateType: "jest/module",
extension: ".ts",
},
{
templateType: "manual",
extension: ".ts",
},
{
templateType: "jest/generated-standalone",
extension: ".js",
modules,
},
];
builds.forEach(setupHtmlWebpackPlugin);
const injectPlugin = new WebpackCdnPlugin({
modules: builds[2].modules,
});
baseConfig.plugins.push(injectPlugin);
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: 8081,
};
baseConfig.output.path = path.resolve(__dirname, "test-dist");
return baseConfig;
};
// = baseConfig;