blessing-skin-server/webpack.config.ts

193 lines
5.5 KiB
TypeScript
Raw Normal View History

2020-07-03 16:30:46 +08:00
import * as path from 'path'
import * as webpack from 'webpack'
2022-06-17 13:47:29 +08:00
import { execSync } from 'child_process'
2020-07-03 16:30:46 +08:00
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
2020-11-04 11:34:36 +08:00
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'
2020-10-31 10:43:47 +08:00
import HtmlWebpackPlugin from 'html-webpack-plugin'
import HtmlWebpackEnhancementPlugin from './tools/HtmlWebpackEnhancementPlugin'
import SyncMetaJsPlugin from './tools/SyncMetaJsPlugin'
2018-07-29 15:31:54 +08:00
interface Env {
production?: boolean
}
2018-07-29 15:31:54 +08:00
export default function (env?: Env): webpack.Configuration[] {
const isDev = !env?.production
2022-06-17 13:47:29 +08:00
const isGitpod = 'GITPOD_REPO_ROOT' in process.env
const htmlPublicPath = isDev
? isGitpod
? `${execSync('gp url 8080')}/app/`
: '//localhost:8080/app/'
: '{{ cdn_base }}/app/'
2020-10-31 10:43:47 +08:00
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',
],
home: '@/scripts/homePage.ts',
'home-css': '@/styles/home.css',
spectre: [
'spectre.css/dist/spectre.min.css',
'@/fonts/minecraft.css',
'@/styles/spectre.css',
],
2020-01-16 16:14:49 +08:00
},
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: [
2020-03-14 17:00:35 +08:00
{
test: /\.tsx?$/,
loader: 'ts-loader',
2020-03-14 17:00:35 +08:00
options: {
2021-01-02 16:38:18 +08:00
configFile: isDev ? 'tsconfig.dev.json' : 'tsconfig.build.json',
transpileOnly: true,
2020-03-14 17:00:35 +08:00
},
},
{
test: /\.css$/,
use: [
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
importLoaders: 1,
},
},
'postcss-loader',
],
},
{
2021-08-22 10:39:41 +08:00
test: /\.(png|webp|svg|woff2?|eot|ttf)$/,
2021-08-22 10:57:45 +08:00
type: 'asset',
},
2019-03-15 11:42:41 +08:00
],
},
plugins: [
new MiniCssExtractPlugin({
filename: isDev ? '[name].css' : '[name].[contenthash:7].css',
chunkFilename: isDev ? '[id].css' : '[id].[contenthash:7].css',
}),
new HtmlWebpackPlugin({
2022-03-26 02:07:55 +08:00
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"',
2022-06-21 23:07:22 +08:00
__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,
2019-02-19 17:26:38 +08:00
},
2019-03-15 11:42:41 +08:00
},
optimization: {
// @ts-ignore
minimizer: [new CssMinimizerPlugin({}), '...'],
2019-03-15 11:42:41 +08:00
},
experiments: {
syncWebAssembly: true,
},
devtool: isDev ? 'eval-source-map' : false,
devServer: {
headers: {
'Access-Control-Allow-Origin': '*',
2020-05-18 16:40:31 +08:00
},
host: '0.0.0.0',
hot: true,
hotOnly: true,
2021-08-21 23:06:23 +08:00
stats: 'errors-warnings',
2022-06-21 23:07:22 +08:00
allowedHosts: ['localhost'].concat(
isDev && isGitpod ? ['.gitpod.io'] : [],
),
},
2021-08-21 23:06:23 +08:00
stats: 'errors-warnings',
2021-08-23 15:35:14 +08:00
ignoreWarnings: [/size limit/i],
2019-02-19 17:26:38 +08:00
},
{
name: 'meta',
mode: isDev ? 'development' : 'production',
entry: {
meta: './resources/assets/src/scripts/meta.ts',
sw: './resources/assets/src/scripts/sw.ts',
},
output: {
path: `${__dirname}/public`,
filename: '[name].js',
},
module: {
rules: [
{
test: /\.ts$/,
loader: 'ts-loader',
options: {
configFile: 'tsconfig.build.json',
transpileOnly: true,
},
},
],
},
plugins: [new SyncMetaJsPlugin()],
resolve: {
extensions: ['.js', '.ts'],
},
2021-08-21 23:06:23 +08:00
stats: 'errors-warnings',
},
]
2018-08-09 09:31:34 +08:00
}