Skip to content

Commit

Permalink
fix(chore): fix node path compatible problem & add express example (#…
Browse files Browse the repository at this point in the history
…4248)

* chore: add express

* fix(core): fix node path
  • Loading branch information
hardfist authored Sep 26, 2023
1 parent 591f55d commit 775ffc8
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 27 deletions.
22 changes: 22 additions & 0 deletions examples/express/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "example-express",
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": true,
"scripts": {
"dev": "rspack serve",
"build": "rspack build"
},
"devDependencies": {
"@rspack/cli": "workspace:*",
"run-script-webpack-plugin": ""
},
"dependencies": {
"express": "4.18.2"
},
"sideEffects": false,
"keywords": [],
"author": "",
"license": "MIT"
}
50 changes: 50 additions & 0 deletions examples/express/rspack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const { RunScriptWebpackPlugin } = require("run-script-webpack-plugin");

/** @type {import('@rspack/cli').Configuration} */
const config = {
experiments: {
rspackFuture: {
disableTransformByDefault: true
}
},
context: __dirname,
target: "node",
entry: {
main: ["webpack/hot/poll?100", "./src/main.ts"]
},
module: {
rules: [
{
test: /\.ts$/,
use: {
loader: "builtin:swc-loader",
options: {
jsc: {
parser: {
syntax: "typescript",
decorators: true
}
}
}
}
}
]
},
optimization: {
minimize: false
},
externalsType: "commonjs",
plugins: [
!process.env.BUILD &&
new RunScriptWebpackPlugin({
name: "main.js",
autoRestart: false
})
].filter(Boolean),
devServer: {
devMiddleware: {
writeToDisk: true
}
}
};
module.exports = config;
3 changes: 3 additions & 0 deletions examples/express/src/api/root.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function rootHandler(req, res) {
res.send("Hello Rspack");
}
15 changes: 15 additions & 0 deletions examples/express/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
declare const module: any;
import express from "express";
import { rootHandler } from "./api/root";
async function bootstrap() {
const app = express();
app.get("/", rootHandler);
const server = app.listen(4000, () =>
console.log("Listening on http://localhost:4000")
);
if (module.hot) {
module.hot.accept();
module.hot.dispose(() => server.close());
}
}
bootstrap();
2 changes: 1 addition & 1 deletion packages/rspack/src/builtin-loader/swc/relay.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import path from "node:path";
import path from "path";

import { RawRelayConfig } from "@rspack/binding";

Expand Down
54 changes: 28 additions & 26 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 775ffc8

Please sign in to comment.