-
Notifications
You must be signed in to change notification settings - Fork 25
/
webpack.common.js
150 lines (148 loc) · 3.96 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
const path = require('path');
const fs = require('fs');
const webpack = require('webpack');
const tailwindcss = require('tailwindcss');
const autoprefixer = require('autoprefixer');
const postcssNested = require('postcss-nested');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin');
const ReactRefreshTypeScript = require('react-refresh-typescript');
const pkg = require('./package.json');
const isProduction = process.env.NODE_ENV === 'production';
module.exports = {
entry: './src/index.tsx',
optimization: {
usedExports: true,
},
output: {
filename: 'assets/js/[name].[contenthash].js',
path: path.resolve(__dirname, 'dist'),
},
watchOptions: {
ignored: '**/node_modules',
},
module: {
rules: [
{
test: /\.[jt]sx?$/,
loader: 'ts-loader',
options: {
getCustomTransformers: () => ({
before: [!isProduction && ReactRefreshTypeScript()].filter(Boolean),
}),
transpileOnly: true,
},
},
{
test: /\.(scss|css)$/,
use: [
process.env.NODE_ENV !== 'production'
? 'style-loader'
: MiniCssExtractPlugin.loader,
'css-loader',
{
loader: 'postcss-loader',
options: {
sourceMap: true,
postcssOptions: {
plugins: [tailwindcss, autoprefixer, postcssNested],
},
},
},
'sass-loader',
],
},
{
test: /\.(woff(2)?|ttf|eot)$/,
type: 'asset/resource',
generator: {
filename: './assets/fonts/[name][ext]',
},
},
],
},
resolve: {
extensions: ['.tsx', '.ts', '.js', '.jsx'],
alias: {
'@tensorflow/tfjs$': path.resolve(
__dirname,
'./custom_tfjs/custom_tfjs.js',
),
'@tensorflow/tfjs-core$': path.resolve(
__dirname,
'./custom_tfjs/custom_tfjs_core.js',
),
},
},
plugins: [
{
apply: (compiler) => {
compiler.hooks.initialize.tap('PlugNmeet', () => {
// temporary work around for worker files
const from = path.resolve(
__dirname,
'node_modules',
'livekit-client',
'dist',
'livekit-client.e2ee.worker.js',
);
const to = path.resolve(
__dirname,
'src',
'helpers',
'livekit',
'e2ee-worker',
'livekit-client.e2ee.worker.js',
);
fs.copyFileSync(from, to);
});
},
},
new webpack.DefinePlugin({
IS_PRODUCTION: isProduction,
PNM_VERSION: JSON.stringify(pkg.version),
BUILD_TIME: Math.floor(Date.now() / 1000),
process: {
env: {
IS_PREACT: false,
},
},
}),
!isProduction && new ReactRefreshWebpackPlugin(),
new MiniCssExtractPlugin({
filename: 'assets/css/[name].[contenthash].css',
}),
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: './src/index.html',
}),
new HtmlWebpackPlugin({
filename: 'login.html',
template: './src/login.html',
inject: false,
}),
new ForkTsCheckerWebpackPlugin(),
new CopyPlugin({
patterns: [
{
from: 'src/assets',
to: 'assets',
globOptions: {
ignore: ['assets/fonts', '**/assets/tflite'],
},
info: { minimized: true },
},
{
from: 'src/assets/tflite/*',
to() {
return 'assets/js/[name][ext]';
},
},
],
}),
].filter(Boolean),
};