-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.common.js
82 lines (76 loc) · 2.65 KB
/
webpack.common.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
/* eslint-disable import/no-extraneous-dependencies */
import path from 'path';
import CopyPlugin from 'copy-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
/** @type {import('webpack').Configuration} */
export default {
plugins: [
new HtmlWebpackPlugin({
template: './src/index.html',
}),
new CopyPlugin({
patterns: [
{ from: 'src/public', to: '' },
],
}),
],
// Configure entry points
entry: './src/index.tsx',
resolve: {
// How should webpack look for modules.
// First search in local src, then node_modules. Resolve extensions automatically.
modules: [path.join(import.meta.url, 'src'), 'node_modules'],
extensions: ['.ts', '.tsx', '.js', '.mjs', '.cjs'],
},
module: {
// The "use" property array is run from right to left.
rules: [
{
// Provide image as resources sepperatly.
// TODO: Investigate how a cdn can host this.
test: /\.(png|jpe?g|gif|svg)$/i,
type: 'asset/resource',
},
{
// Fonts
test: /\.(woff|woff2|eot|ttf)$/,
use: [{
loader: 'url-loader',
options: {
limit: 10000,
name: './font/[hash].[ext]',
mimetype: 'application/font-woff',
},
}],
},
{
// Load and compile TS with TSC
// Use babel to transpile for older browsers
// See .babelrc for configuration
test: /\.tsx?$/,
exclude: /node_modules/,
use: [
{
loader: 'babel-loader',
},
{
loader: 'ts-loader',
},
],
},
],
},
output: {
// Output to the "dist" folder. Clean before build
path: path.resolve('dist'),
publicPath: '/',
clean: true,
filename: 'index.js',
// The devtool: "source-map" supplies source maps but webpack uses a special protocol to resolve the location
// To allow debugging with vscode, following makes it resolve with an actual filepath.
// This prevents use from having to map source map locations to actual files on disk in the launch config.
devtoolModuleFilenameTemplate(info) {
return `file:///${encodeURI(info.absoluteResourcePath)}`;
},
},
};