-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.js
77 lines (75 loc) · 2.62 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
/* eslint import/no-extraneous-dependencies: ["error", {"devDependencies": true}] */
import HtmlWebPackPlugin from 'html-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import latestVersion from 'latest-version';
import apiKey from './src/apiKey.js';
export default async (_env, { mode }) => {
const prod = mode === 'production';
const croquet_version = await latestVersion('@croquet/croquet', {version: 'dev'});
const croquet_script =`<script src="https://cdn.jsdelivr.net/npm/@croquet/croquet@${croquet_version}"></script>`;
// const croquet_script =`<script src="https://cdn.jsdelivr.net/npm/@croquet/croquet@1.1.0"></script>`;
return {
entry : {
labyrinth: './labyrinth.js',
lobby: './lobby.js',
},
devtool: 'source-map',
output: {
filename: '[name]-[contenthash:8].js',
chunkFilename: 'chunk-[contenthash:8].js',
assetModuleFilename: 'assets/[contenthash:8][ext]',
clean: true,
},
devServer: {
allowedHosts: 'all',
port: 8080,
hot: true,
liveReload: true,
watchFiles: ['src/**/*', 'public/**/*'],
client: {
overlay: true,
progress: true
},
},
module: {
rules: [
{
test: /\.js$/,
enforce: "pre",
use: ["source-map-loader"],
},
{
test: /\.(png|jpg|jpeg|gif|svg|wav|mp3|glb|gltf)$/,
type: 'asset/resource',
},
],
},
// use Croquet loaded via <script>
externals: {
"@croquet/croquet": "Croquet",
},
plugins: [
new HtmlWebPackPlugin({
template: 'labyrinth.html', // input
filename: 'labyrinth.html', // output filename in dist/
chunks: ['labyrinth'],
templateParameters: { croquet_script },
}),
new HtmlWebPackPlugin({
template: 'lobby.html',
filename: 'index.html', // output filename in dist/
chunks: ['lobby'],
templateParameters: { croquet_script, apiKey },
}),
new CopyWebpackPlugin({
patterns: [
{ from: 'draco', to: 'draco' },
{ from: 'assets', to: 'assets' }
]
})
],
experiments: {
asyncWebAssembly: true,
},
};
};