wip: add server boilerplate

This commit is contained in:
tsukino
2024-02-20 21:37:13 +08:00
committed by tsukino
parent aa0e6ecf0a
commit 2b7b747266
4 changed files with 559 additions and 84 deletions

566
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -4,8 +4,12 @@
"description": "",
"main": "index.js",
"scripts": {
"build": "NODE_ENV=production webpack --config webpack.config.js",
"dev": "NODE_ENV=development webpack-dev-server --config webpack.config.js --hot"
"build:ui": "NODE_ENV=production webpack --config webpack.config.js",
"build:server": "NODE_ENV=production webpack --config webpack.server.config.js",
"watch:server": "webpack --config webpack.server.config.js --watch",
"nodemon:server": "nodemon build/server/index.js",
"dev:server": "NODE_ENV=development concurrently npm:watch:server npm:nodemon:server",
"dev:ui": "NODE_ENV=development webpack-dev-server --config webpack.config.js --hot"
},
"repository": {
"type": "git",
@@ -22,6 +26,7 @@
"buffer": "^6.0.3",
"charwise": "^3.0.1",
"classnames": "^2.3.2",
"express": "^4.18.2",
"fast-deep-equal": "^3.1.3",
"isomorphic-fetch": "^3.0.0",
"node-forge": "^1.3.1",
@@ -53,6 +58,7 @@
"babel-loader": "^9.1.2",
"babel-preset-react-app": "^10.0.1",
"clean-webpack-plugin": "^4.0.0",
"concurrently": "^8.2.2",
"copy-webpack-plugin": "^11.0.0",
"css-loader": "^6.7.3",
"eslint": "^8.31.0",
@@ -68,6 +74,7 @@
"fs-extra": "^11.1.0",
"html-loader": "^4.2.0",
"html-webpack-plugin": "^5.5.0",
"nodemon": "^3.0.3",
"postcss-loader": "^7.3.3",
"postcss-preset-env": "^9.1.1",
"prettier": "^3.0.2",

3
server/index.ts Normal file
View File

@@ -0,0 +1,3 @@
import express from 'express';
console.log('hi')

63
webpack.server.config.js Executable file
View File

@@ -0,0 +1,63 @@
var webpack = require("webpack"),
path = require("path"),
CopyWebpackPlugin = require("copy-webpack-plugin"),
HtmlWebpackPlugin = require("html-webpack-plugin"),
TerserPlugin = require("terser-webpack-plugin");
var { CleanWebpackPlugin } = require("clean-webpack-plugin");
const ASSET_PATH = process.env.ASSET_PATH || "/";
const isDevelopment = process.env.NODE_ENV !== "production";
var options = {
mode: process.env.NODE_ENV || "development",
entry: {
index: path.join(__dirname, "server", "index.ts"),
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "build", "server"),
clean: true,
publicPath: ASSET_PATH,
},
module: {
rules: [
{
test: /\.(ts|tsx)$/,
exclude: /node_modules/,
use: [
{
loader: require.resolve("ts-loader"),
options: {
transpileOnly: isDevelopment,
},
},
],
},
],
},
plugins: [
isDevelopment && new ReactRefreshWebpackPlugin(),
new CleanWebpackPlugin({ verbose: false }),
new webpack.ProgressPlugin(),
new webpack.EnvironmentPlugin(["NODE_ENV"]),
].filter(Boolean),
infrastructureLogging: {
level: "info",
},
};
if (process.env.NODE_ENV === "development") {
options.devtool = "cheap-module-source-map";
} else {
options.optimization = {
minimize: true,
minimizer: [
new TerserPlugin({
extractComments: false,
}),
],
};
}
module.exports = options;