Browse Source

ref: serve script & add npm engines

Sv443 1 year ago
parent
commit
471c29c763
4 changed files with 23 additions and 15 deletions
  1. 4 0
      package-lock.json
  2. 5 1
      package.json
  3. 4 8
      src/tools/serve.ts
  4. 10 6
      webpack.config.js

+ 4 - 0
package-lock.json

@@ -32,6 +32,10 @@
         "tslib": "^2.5.2",
         "typescript": "^5.0.4",
         "webpack-cli": "^5.1.1"
+      },
+      "engines": {
+        "node": ">=18",
+        "npm": ">=8"
       }
     },
     "node_modules/@babel/code-frame": {

+ 5 - 1
package.json

@@ -18,6 +18,10 @@
     "lint": "tsc --noEmit && eslint .",
     "node-ts": "node --no-warnings=ExperimentalWarning --enable-source-maps --loader ts-node/esm"
   },
+  "engines": {
+    "node": ">=18",
+    "npm": ">=8"
+  },
   "repository": {
     "type": "git",
     "url": "git+https://github.com/Sv443/BetterYTM.git"
@@ -73,4 +77,4 @@
       "dev/*"
     ]
   }
-}
+}

+ 4 - 8
src/tools/serve.ts

@@ -1,7 +1,7 @@
 import express, { NextFunction, Request, Response } from "express";
 import { resolve } from "path";
 import { fileURLToPath } from "url";
-import webpackCfg from "../../webpack.config.js";
+import { output as webpackCfgOutput } from "../../webpack.config.js";
 
 const envPort = Number(process.env.DEV_SERVER_PORT);
 
@@ -23,17 +23,13 @@ app.use((err: unknown, _req: Request, _res: Response, _next: NextFunction) => {
     console.error("\x1b[31mError in dev server:\x1b[0m\n", err);
 });
 
-// serves everything from `webpack_config.output.path` (`dist/` by default)
+// serves everything from `webpackConfig.output.path` (`dist/` by default)
 app.use(express.static(
-  resolve(fileURLToPath(import.meta.url), "../../", webpackCfg.output.path),
-  {
-    etag: false,
-    maxAge: 0,
-  }
+  resolve(fileURLToPath(import.meta.url), "../../", webpackCfgOutput.path)
 ));
 
 app.listen(devServerPort, "0.0.0.0", () => {
-  console.log(`The dev server is running.\nUserscript is served at \x1b[34m\x1b[4mhttp://localhost:${devServerPort}/${webpackCfg.output.filename}\x1b[0m`);
+  console.log(`The dev server is running.\nUserscript is served at \x1b[34m\x1b[4mhttp://localhost:${devServerPort}/${webpackCfgOutput.filename}\x1b[0m`);
   if(enableLogging)
     process.stdout.write("\nRequests: ");
   else

+ 10 - 6
webpack.config.js

@@ -11,15 +11,18 @@ dotenv.config();
 const mode = ["development", "production"].includes(process.env.NODE_ENV) ? process.env.NODE_ENV : "development";
 const outFileSuffix = process.env.OUTFILE_SUFFIX ?? "";
 
+/** Webpack configuration for the output file */
+const output = {
+  filename: `BetterYTM${outFileSuffix}.user.js`,
+  path: join(dirname(fileURLToPath(import.meta.url)), "/dist"),
+  clean: true,
+  module: true,
+};
+
 /** @param {import("./src/types").WebpackEnv} env */
 const getConfig = (env) => ({
   entry: "./src/BetterYTM.user.ts",
-  output: {
-    filename: `BetterYTM${outFileSuffix}.user.js`,
-    path: join(dirname(fileURLToPath(import.meta.url)), "/dist"),
-    clean: true,
-    module: true,
-  },
+  output,
   experiments: {
     // userscripts are automatically wrapped in an IIFE by the browser extension, so this can be enabled
     outputModule: true,
@@ -84,3 +87,4 @@ const getConfig = (env) => ({
 });
 
 export default getConfig;
+export { output };