Add vite-plugin-node to be able to run API locally

This commit is contained in:
Nikita Karamov 2023-03-16 12:18:17 +01:00
parent 03f49e4056
commit 40c0add0e3
No known key found for this signature in database
GPG key ID: 41D6F71EE78E77CD
3 changed files with 49 additions and 3 deletions

View file

@ -34,7 +34,8 @@
"sass": "^1.49.7",
"svgo": "^3.0.1",
"terser": "^5.16.6",
"vite": "^4.1.4"
"vite": "^4.1.4",
"vite-plugin-node": "^3.0.2"
},
"postcss": {
"map": true,

View file

@ -14,6 +14,7 @@ specifiers:
svgo: ^3.0.1
terser: ^5.16.6
vite: ^4.1.4
vite-plugin-node: ^3.0.2
devDependencies:
'@vitejs/plugin-legacy': 4.0.2_terser@5.16.6+vite@4.1.4
@ -29,6 +30,7 @@ devDependencies:
svgo: 3.0.2
terser: 5.16.6
vite: 4.1.4_sass@1.49.7+terser@5.16.6
vite-plugin-node: 3.0.2_vite@4.1.4
packages:
@ -1502,6 +1504,14 @@ packages:
fastq: 1.15.0
dev: true
/@rollup/pluginutils/4.2.1:
resolution: {integrity: sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==}
engines: {node: '>= 8.0.0'}
dependencies:
estree-walker: 2.0.2
picomatch: 2.3.1
dev: true
/@trysound/sax/0.2.0:
resolution: {integrity: sha512-L7z9BgrNEcYyUYtF+HaEfiS5ebkh9jXqbszz7pC0hRBPaatV0XjSD3+eHrpqFemQfgwiFF0QPIarnIihIDn7OA==}
engines: {node: '>=10.13.0'}
@ -2119,7 +2129,11 @@ packages:
engines: {node: '>=4.0'}
dev: true
/esutils@2.0.3:
/estree-walker/2.0.2:
resolution: {integrity: sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==}
dev: true
/esutils/2.0.3:
resolution: {integrity: sha512-kVscqXk4OCp68SZ0dkgEKVi6/8ij300KBWTJq32P/dYeWTSwK41WyTxalN1eRmA5Z9UU/LX9D7FWSmV9SAYx6g==}
engines: {node: '>=0.10.0'}
dev: true
@ -3052,6 +3066,23 @@ packages:
spdx-expression-parse: 3.0.1
dev: true
/vite-plugin-node/3.0.2_vite@4.1.4:
resolution: {integrity: sha512-pA/QZDe4VRFUSChTrR64EfdsnwHbTnkXKx1Be8MP2oW43TPeQgtIfqiGOuXTPUKjwINtyEl8JMzRN0+dYyfTow==}
peerDependencies:
'@swc/core': ^1.2.153
vite: ^4.0.0
peerDependenciesMeta:
'@swc/core':
optional: true
dependencies:
'@rollup/pluginutils': 4.2.1
chalk: 4.1.2
debug: 4.3.4
vite: 4.1.4_sass@1.49.7+terser@5.16.6
transitivePeerDependencies:
- supports-color
dev: true
/vite/4.1.4_sass@1.49.7+terser@5.16.6:
resolution: {integrity: sha512-3knk/HsbSTKEin43zHu7jTwYWv81f8kgAL99G5NWBcA1LKvtvcVAC4JjBH1arBunO9kQka+1oGbrMKOjk4ZrBg==}
engines: {node: ^14.18.0 || >=16.0.0}

View file

@ -1,4 +1,5 @@
import legacy from "@vitejs/plugin-legacy";
import { VitePluginNode } from "vite-plugin-node";
export default {
build: {
@ -6,5 +7,18 @@ export default {
terserOptions: { ecma: 5 },
sourcemap: "true",
},
plugins: [legacy()],
plugins: [
legacy(),
VitePluginNode({
// Workaround from: https://github.com/axe-me/vite-plugin-node/issues/47
adapter({ app, req, res, next }) {
if (req.url.startsWith("/api/")) {
app(req, res);
} else {
next();
}
},
appPath: "./api/share.js",
}),
],
};