forked from rossning92/movy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
94 lines (85 loc) · 2.21 KB
/
webpack.config.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
const HtmlWebpackPlugin = require("html-webpack-plugin");
const path = require("path");
const fs = require("fs");
const plugins = [];
// Setup HtmlWebpackPlugin for all found entries. Automatically search all
// files under `./examples` folder and add them as webpack entries.
const entries = {};
function addEntry(file) {
const name = path.parse(file).name;
entries[name] = file;
plugins.push(
new HtmlWebpackPlugin({
filename: name + ".html",
template: path.resolve(__dirname, "player.html"),
chunks: [name],
title: name,
})
);
}
module.exports = (env) => {
let openPage = undefined;
const contentBase = [
path.resolve(__dirname, "examples"),
path.resolve(__dirname, "node_modules/ccapture.js/build"),
];
if (env && env.file) {
addEntry(env.file);
openPage = path.parse(env.file).name + ".html";
contentBase.push(path.dirname(env.file));
} else {
// The folder that contains source code and resource files (images, videos,
// etc.)
const entryFolders = [path.resolve(__dirname, "examples")];
entryFolders.forEach((dir) => {
fs.readdirSync(dir).forEach((file) => {
if (path.extname(file).toLowerCase() !== ".js") {
return;
}
const fullPath = path.join(dir, file);
addEntry(fullPath);
});
});
}
plugins.push(
new HtmlWebpackPlugin({
filename: "index.html",
template: path.resolve(__dirname, "index.html"),
chunks: [],
movySceneNames: Object.keys(entries),
})
);
return {
entry: entries,
plugins: plugins,
mode: "development",
resolve: {
modules: [
path.resolve(__dirname, "src"),
path.resolve(__dirname, "node_modules"),
"node_modules",
],
extensions: [".js", ".ts", ".json"],
},
module: {
rules: [
{
test: /\.tsx?$/,
use: {
loader: path.resolve(__dirname, "node_modules/ts-loader"),
options: {
configFile: path.resolve(__dirname, "tsconfig.json"),
},
},
},
],
},
devServer: {
compress: true,
contentBase,
open: true,
openPage,
stats: "minimal",
},
};
};