forked from bs-community/blessing-skin-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.ts
161 lines (158 loc) · 4.59 KB
/
webpack.config.ts
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
151
152
153
154
155
156
157
158
159
160
161
import * as path from 'path'
import * as webpack from 'webpack'
import { execSync } from 'child_process'
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
import HtmlWebpackPlugin from 'html-webpack-plugin'
import HtmlWebpackEnhancementPlugin from './tools/HtmlWebpackEnhancementPlugin'
interface Env {
production?: boolean
}
export default function (env?: Env): webpack.Configuration {
const isDev = !env?.production
const isGitpod = 'GITPOD_REPO_ROOT' in process.env
const htmlPublicPath = isDev
? isGitpod
? `${execSync('gp url 8080')}/app/`
: '//localhost:8080/app/'
: '{{ cdn_base }}/app/'
return {
name: 'app',
mode: isDev ? 'development' : 'production',
entry: {
app: ['react-hot-loader/patch', '@/index.tsx'],
style: [
'@/styles/common.css',
'admin-lte/dist/css/alt/adminlte.components.min.css',
'admin-lte/dist/css/alt/adminlte.core.min.css',
'admin-lte/dist/css/alt/adminlte.pages.min.css',
'admin-lte/dist/css/alt/adminlte.light.min.css',
'@fortawesome/fontawesome-free/css/all.min.css',
],
home: '@/scripts/homePage.ts',
'home-css': '@/styles/home.css',
spectre: [
'spectre.css/dist/spectre.min.css',
'@/fonts/minecraft.css',
'@/styles/spectre.css',
],
},
output: {
path: `${__dirname}/public/app`,
publicPath: '/app/',
filename: isDev ? '[name].js' : '[name].[contenthash:7].js',
chunkFilename: isDev ? '[id].js' : '[id].[contenthash:7].js',
crossOriginLoading: 'anonymous',
},
module: {
rules: [
{
test: /\.tsx?$/,
loader: 'ts-loader',
options: {
configFile: isDev ? 'tsconfig.dev.json' : 'tsconfig.build.json',
transpileOnly: true,
},
},
{
test: /\.css$/,
use: [
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
},
'postcss-loader',
],
},
{
test: /\.(png|webp|svg|woff2?|eot|ttf)$/,
type: 'asset',
},
],
},
plugins: [
new MiniCssExtractPlugin({
filename: isDev ? '[name].css' : '[name].[contenthash:7].css',
chunkFilename: isDev ? '[id].css' : '[id].[contenthash:7].css',
}),
new HtmlWebpackPlugin({
templateContent: '',
chunks: ['app'],
scriptLoading: 'blocking',
filename: 'app.twig',
publicPath: htmlPublicPath,
}),
new HtmlWebpackPlugin({
templateContent: '',
chunks: ['style'],
filename: 'style.twig',
publicPath: htmlPublicPath,
}),
new HtmlWebpackPlugin({
templateContent: '',
chunks: ['home'],
scriptLoading: 'blocking',
filename: 'home.twig',
publicPath: htmlPublicPath,
}),
new HtmlWebpackPlugin({
templateContent: '',
chunks: ['home-css'],
filename: 'home-css.twig',
publicPath: htmlPublicPath,
}),
new HtmlWebpackPlugin({
templateContent: '',
chunks: ['spectre'],
filename: 'spectre.twig',
publicPath: htmlPublicPath,
}),
new HtmlWebpackEnhancementPlugin(),
new webpack.DefinePlugin({
'window.Deno': 'true',
Deno: {
args: [],
build: {},
version: {},
},
'process.platform': '"browser"',
__blessing_public_path__: JSON.stringify(htmlPublicPath),
}),
].concat(isDev ? [new webpack.HotModuleReplacementPlugin()] : []),
resolve: {
extensions: ['.js', '.ts', '.tsx'],
alias: {
'react-dom': '@hot-loader/react-dom',
'@': path.resolve(__dirname, 'resources/assets/src'),
readline: '@/scripts/cli/readline.ts',
prompts: 'prompts/lib/index.js',
assert: false,
},
},
optimization: {
// @ts-ignore
minimizer: [new CssMinimizerPlugin({}), '...'],
},
experiments: {
syncWebAssembly: true,
},
devtool: isDev ? 'eval-source-map' : 'source-map',
devServer: {
headers: {
'Access-Control-Allow-Origin': '*',
},
host: '0.0.0.0',
hot: true,
hotOnly: true,
stats: 'errors-warnings',
allowedHosts: ['localhost'].concat(
isDev && isGitpod ? ['.gitpod.io'] : [],
),
},
stats: 'errors-warnings',
ignoreWarnings: [/size limit/i],
}
}