-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.babel.js
113 lines (102 loc) · 3.17 KB
/
webpack.config.babel.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
const prod = process.env.NODE_ENV === 'production';
import path from 'path';
import dotenv from 'dotenv';
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
export const mode = prod ? 'production' : 'development';
dotenv.config({ path: prod ? 'prod.env' : 'dev.env' });
// entry point of parsing
export const entry = './src/index.tsx';
// output folder
export const output = {
path: __dirname + '/dist/',
publicPath: "/", // for dev server
};
// setup rules for parsing
export const module = {
rules: [
// use ts-loader for all typescript files
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
resolve: {
extensions: ['.ts', '.tsx', '.js', '.json'],
},
use: 'ts-loader',
},
// use css-loader for all css files
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader'],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/i,
type: 'asset/resource',
},
{
test: /\.(fbx|gltf)$/i,
use: 'file-loader',
},
{
test: /\.glsl$/i,
loader: 'webpack-glsl-loader',
},
// load SASS
{
test: /\.s[ac]ss$/i,
use: [
// Creates `style` nodes from JS strings
"style-loader",
// Translates CSS into CommonJS
"css-loader",
// Compiles Sass to CSS
"sass-loader",
],
},
// load text files
{
test: /\.txt$/,
use: 'raw-loader'
},
// load json files
{
test: /\.json$/,
type: 'javascript/auto',
use: 'json-loader'
},
],
// don't parse typescript files with babel
noParse: [require.resolve('typescript/lib/typescript.js')],
};
// resolve extensions for importing files without specifying extension name
// in import statement, e.g. import { App } from './App';
export const resolve = {
extensions: ['.ts', '.tsx', '.js', '.json'],
fallback: {
"path": require.resolve("path-browserify"),
}
};
// source map allows us to see the original code in the browser
// for easier debugging, it is not needed in production
export const devtool = prod ? undefined : 'source-map';
export const devServer = prod ? undefined : {
static: path.join(__dirname, "build"),
historyApiFallback: true,
port: process.env.PORT || 3200,
open: true,
hot: true
};
// add plugins that will be used in the build pipeline
export const plugins = [
// use index.html as a template for the output html file
new HtmlWebpackPlugin({
template: 'public/index.html',
favicon: 'public/favicon.ico',
}),
// compile css into one file
new MiniCssExtractPlugin(),
// Use ForkTsCheckerWebpackPlugin to speed up compilation and type checking
// by running it in a separate process and caching results.
new ForkTsCheckerWebpackPlugin(),
];