You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Having the file files of API routes (eg ./server/api/user/index.ts).
I created a vite plugin:
// ./viteBundleFilesPlugin.tsimportfsfrom'node:fs'importpathfrom'node:path'import{build,typePlugin}from'vite'interfaceBundleFilesOptions{entry: string// File path to bundleoutputDir: string// Base output directory (e.g., 'dist')}exportdefaultfunctionbundleFilesPlugin(options: BundleFilesOptions): Plugin{return{name: 'vite-plugin-bundle-files',asyncbuildStart(){const{ entry, outputDir }=optionsconstcwd=process.cwd()constentryFull=path.resolve(cwd,entry)constoutFull=path.resolve(cwd,outputDir)constfilepaths=fs.globSync('**/*.ts',{cwd: entryFull})for(constfilepathoffilepaths){consttargetFilepath=path.resolve(outFull,filepath)consttargetDir=path.dirname(targetFilepath)fs.mkdirSync(targetDir,{recursive: true})constentryFilepath=path.resolve(entryFull,filepath)// Run a build for each fileawaitbuild({configFile: false,// Avoid conflicts with the main Vite configbuild: {lib: {entry: entryFilepath,formats: ['es'],// ES module formatfileName: ()=>'[name].mjs'// Force 'index.mjs' for each file},rollupOptions: {output: {dir: targetDir,// Directory for this specific fileentryFileNames: '[name].mjs'// File name pattern}}}})}}}}
[plugin:vite:resolve] [plugin vite:resolve] Module "node:http" has been externalized for browser compatibility, imported by ... .See https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
Should I use some settings to correct bundle for PWA (vite-plugin-pwa) with vite.build as target ./dist/server/api (expected ./dist/server/api/user/index.mjs)?
There is a better way to build with vite-plugin-pwa?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Having the file files of API routes (eg
./server/api/user/index.ts
).I created a vite plugin:
I got some warnings after
vite.build
:Should I use some settings to correct bundle for PWA (
vite-plugin-pwa
) withvite.build
as target./dist/server/api
(expected./dist/server/api/user/index.mjs
)?There is a better way to build with
vite-plugin-pwa
?Beta Was this translation helpful? Give feedback.
All reactions