-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.mjs
121 lines (115 loc) · 2.85 KB
/
webpack.config.mjs
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
import CompressionWebpackPlugin from 'compression-webpack-plugin';
import CopyWebpackPlugin from 'copy-webpack-plugin';
import DotenvPlugin from 'dotenv-webpack';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import path from 'path';
import webpack from 'webpack';
const {
EnvironmentPlugin,
HotModuleReplacementPlugin,
NoEmitOnErrorsPlugin,
ProvidePlugin
} = webpack;
const PORT = process.env.PORT || 8080;
export default function ({ production, WEBPACK_WATCH }) {
const mode = production ? 'production' : 'development';
const devtool = production ? false : 'inline-source-map';
return {
entry: path.resolve('src/index.ts'),
target: 'web',
mode,
devtool,
stats: 'errors-only',
bail: WEBPACK_WATCH ? false : true,
output: {
crossOriginLoading: 'anonymous',
filename: '[name].js',
path: path.resolve('dist'),
sourceMapFilename: '[file].map',
libraryTarget: 'umd',
},
resolve: {
extensions: ['.ts', '.js']
},
module: {
rules: [
{
test: /\.(js|ts)x?$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
cacheDirectory: true
}
}
},
{
test: /\.(ico|png|jpg|jpeg|gif|webp|env|glb|stl)$/i,
use: {
loader: 'url-loader',
options: {
limit: 8192
}
}
}
]
},
performance: {
hints: false
},
optimization: {
minimize: production ? true : false
},
watchOptions: {
aggregateTimeout: 300,
poll: 300,
ignored: /node_modules/
},
plugins: [
new CopyWebpackPlugin({
patterns: [
{ from: 'assets' }
]
}),
new NoEmitOnErrorsPlugin(),
new EnvironmentPlugin({
NODE_ENV: mode
}),
new DotenvPlugin(),
new ProvidePlugin({
CANNON: 'cannon'
}),
new HtmlWebpackPlugin({
title: 'Playlist Browser XR',
template: path.resolve('public/index.html'),
favicon: path.resolve('public/favicon.png')
}),
...production ? [
new CompressionWebpackPlugin()
] : [
new HotModuleReplacementPlugin()
]
],
devServer: {
watchContentBase: true,
open: true,
quiet: true,
port: PORT,
publicPath: `http://localhost:${PORT}`,
noInfo: true,
compress: true,
hot: true,
headers: { 'Access-Control-Allow-Origin': '*' },
disableHostCheck: true,
stats: 'errors-only',
watchOptions: {
poll: 300
},
// enable access from other devices on the network
useLocalIp: true,
host: '0.0.0.0',
// if you aren’t using ngrok, and want to connect locally, WebXR requires HTTPS
// https: true,
},
};
};