Closed RiQuY closed 3 weeks ago
Can't try to reproduce right now, but I'm wondering if manually setting your base and build options in vite.config.mjs is causing issues. Can you try it without the following section?:
base: '/bundles/nodecg-vite-svelte-js-template/',
build: {
cssCodeSplit: false,
outDir: 'graphics',
sourcemap: true,
rollupOptions: {
input: {
'graphics1/main': 'src/graphics/graphics1/main.js'
},
output: {
entryFileNames: '[name].js',
assetFileNames: `[name].[ext]`
},
}
// emptyOutDir: true,
}
Can't try to reproduce right now, but I'm wondering if manually setting your base and build options in vite.config.mjs is causing issues. Can you try it without the following section?:
Sorry for the delay, I wasn't home the previous weeks.
Thank you for the tip, leaving a single vite.config.mjs with the following configuration solved the issue:
import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import NodeCGPlugin from "vite-plugin-nodecg";
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
svelte(),
NodeCGPlugin({
inputs: {
"dashboard/dashboard1/index.js": "./src/dashboard/dashboard1/index.html",
"graphics/graphics1/index.js": "./src/graphics/graphics1/index.html",
},
srcDir: './src'
}),
],
base: "/bundles/nodecg-vite-svelte-js-template/",
});
I think the next question is unrelated but I would appreciate if you could help me with it.
In the package.json I have these scripts to watch the changes for dashboard/graphics and extension folders, but after running pnpm dev
I'm not able to stop the dev server with Q o a single Ctr-C, I have to press Ctrl-C like 10 times until everything stops/crashes.
"dev": "npm-run-all --parallel dev:*",
"dev:browser": "vite --config vite.config.mjs",
"dev:extension": "parcel watch src/extension/index.js --dist-dir extension",
Do you know a way to avoid this or how to build the extension folder with Vite to use a single command? I'm not using Vite to build the extension folder because it generates an empty .js file.
Thanks.
Glad to hear its fixed!
As to your new issue, I'm not sure to be honest. Maybe this issue is related?
A bigger question is why are you using parcel for your extension code? You should be able to use tsc directly, there's no need to do bundling for server-side code? Take a look at some of the other templates like zoton's vue-ts-template as a guide.
A bigger question is why are you using parcel for your extension code? You should be able to use tsc directly.
Im using Parcel to convert my extension.js file to a CommonJS format, because for some reason NodeCG throws an error trying to read the extension.js file if is using export default function(nodecg)
instead of module.exports
. And I can't use tsc
because there is nothing to compile, it's a Javacript file.
https://codeberg.org/RiQuY/nodecg-vite-svelte-js-template/src/branch/main/src/extension/index.js
I see. When I've written pure js extensions I've always just used CommonJS stuff as then you can skip the build step entirely. Otherwise with typescript you can use esnext modules and have it transpile to commonjs
Thank you for sharing a related issue of npm-run-all and the general guidelines, your plugin made using vite config easier.
I'll try to take a look at vite to see if I can generate the extension.js in the same vite.config.mjs to avoid the frozen dev command.
Do note that vite is really not designed for bundling server-side code. Perhaps you'd be better off using esbuild directly. Best of luck.
Description
When trying to use vite-plugin-nodecg 2.1.0 in a project with Vite, the command "vite dev" fails with the following error:
The plugin has these settings in my vite config file: https://codeberg.org/RiQuY/nodecg-vite-svelte-js-template/src/branch/main/vite.graphics.config.mjs
Steps to reproduce