Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix[vue-gen2]: isolated-vm fix workaround for Vue SDK #3560

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/sdks/output/vue/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ NOTE: if you are using Nuxt, you will need to add the SDK's Nuxt module in `nuxt
```js
// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
module: ['@builder.io/sdk-vue/nuxt'],
modules: ['@builder.io/sdk-vue/nuxt'],
});
```

Expand Down
18 changes: 18 additions & 0 deletions packages/sdks/output/vue/nuxt.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,23 @@ export default defineNuxtModule({
* Add the compiled Builder.io CSS to the Nuxt CSS array.
*/
nuxt.options.css.push('@builder.io/sdk-vue/css');
/**
* This is because Vite tries to optimize the isolated-vm dependency while
* running the dev server (first build), which is not needed and throws an error.
* `isolated-vm` is a Node.js native module which should only be imported and used in Node.js environments.
*/
if (nuxt.options.vite?.optimizeDeps?.exclude) {
nuxt.options.vite.optimizeDeps.exclude.push(
"@builder.io/sdk-vue/node/init"
);
} else {
nuxt.options.vite = {
...nuxt.options.vite,
optimizeDeps: {
...nuxt.options.vite?.optimizeDeps,
exclude: ["@builder.io/sdk-vue/node/init"],
},
};
}
},
});
4 changes: 4 additions & 0 deletions packages/sdks/output/vue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@
"import": "./lib/browser/index.mjs",
"require": "./lib/browser/index.cjs"
}
},
"./node/init": {
"import": "./lib/node/init.mjs",
"require": "./lib/node/init.cjs"
}
},
"scripts": {
Expand Down
11 changes: 8 additions & 3 deletions packages/sdks/output/vue/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,22 @@ export default defineConfig({
const outPath = getSdkOutputPath();
copyFileSync(outPath + '/index.d.ts', outPath + '/index.d.mts');
renameSync(outPath + '/index.d.ts', outPath + '/index.d.cts');
copyFileSync(outPath + '/functions/evaluate/node-runtime/init.d.ts', outPath + '/init.d.mts');
copyFileSync(outPath + '/functions/evaluate/node-runtime/init.d.ts', outPath + '/init.d.cts');
},
}),
],
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
entry: {
index: resolve(__dirname, 'src/index.ts'),
init: resolve(__dirname, 'src/functions/evaluate/node-runtime/init.ts')
},
formats: ['es', 'cjs'],
fileName: (format) => `index.${format === 'es' ? 'mjs' : 'cjs'}`,
fileName: (format, entryName) => `${entryName}.${format === 'es' ? 'mjs' : 'cjs'}`,
},
rollupOptions: {
external: ['vue', 'node:module'],
external: ['vue', 'node:module', 'isolated-vm'],
output: {
globals: {
vue: 'Vue',
Expand Down
Loading