-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathwebpack.config.js
81 lines (79 loc) · 2.22 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
const HtmlWebpackPlugin = require('html-webpack-plugin');
const path = require('path');
const webpack = require('webpack');
module.exports = {
/* Environment Variables
Set cross-env NODE_ENV=production + command
Set cross-env NODE_ENV=development + command
*/
mode: process.env.NODE_ENV, // default to production
// concurrently run different scripts together
entry: './public/main.js', // where to begin creating dependency graph
output: {
path: path.join(__dirname, 'dist'),
filename: 'bundle.js',
},
module: {
rules: [
/* For REACT
npm install -D babel-loader @babel/core @babel/preset-env @babel/preset-react
*/
{
test: /\.jsx?/, // ? will pick up jsx or js
exclude: /node_modules/,
use: {
loader: 'babel-loader', // babel-loader allows webpack to bundel babel presets and plugins
options: {
presets: ['@babel/preset-env', '@babel/preset-react'],
},
},
},
/* For STYLE css/sass
npm install -D sass-loader sass webpack --save-dev style-loader css-loader
*/
{
test: /\.s?css/,
exclude: /node_modules/,
use: ['style-loader', 'css-loader', 'sass-loader'], // read from right to left
// css-loader requires for css with imported URL
},
/* Rule for ThreeJs */
{
test: /\.(glb|gltf|obj|mtl|png|jpg|jpeg|gif|svg)$/i,
type: 'asset/resource',
},
],
},
/* Webpack Dev Server */
plugins: [
new HtmlWebpackPlugin({
template: path.join(__dirname, '/public/index.html'), // generate HTML file
}),
],
/* Versions that work
"webpack": "^5.64.1",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^4.5.0",
"webpack-hot-middleware": "^2.24.3" */
devServer: {
host: 'localhost',
port: 8080,
static: {
directory: path.join(__dirname, 'public'),
publicPath: '/',
},
hot: true, // reload without a refresh
historyApiFallback: true,
headers: { 'Access-Control-Allow-Origin': '*' },
/* Proxy */
proxy: {
'/leaderboard': {
target: 'http://localhost:3000/',
secure: false,
},
},
},
resolve: {
extensions: ['.js', '.jsx'],
},
};