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

vite build does not bundle the dependencies #90

Open
tresabhi opened this issue May 17, 2023 · 3 comments
Open

vite build does not bundle the dependencies #90

tresabhi opened this issue May 17, 2023 · 3 comments

Comments

@tresabhi
Copy link

It's quite clear in the title. No matter what I do, it just won't bundle. I can't even find a place to specify bundle: true.

vite.config.ts:

export default defineConfig({
  server: { port: 3000 },
  plugins: [
    ...VitePluginNode({
      adapter: 'express',
      appPath: './src/main.ts',
      exportName: 'viteNodeApp',
      tsCompiler: 'esbuild',
    }),
  ],
  build: {
    target: 'node18',
    minify: 'esbuild',
    sourcemap: 'inline',
    emptyOutDir: true,
  },
  optimizeDeps: {
    esbuildOptions: { treeShaking: true },
  },
});

package.json (scripts):

"scripts": {
    "dev": "vite-node src/main.ts --script",
    "build": "vite build",
    "lint": "tsc"
  },

And the command output if that's needed:

yarn build
yarn run v1.22.19
$ vite build
vite v4.3.7 building SSR bundle for production...
✓ 44 modules transformed.
dist/main.js  143.33 kB │ map: 90.05 kB
✓ built in 393ms
Done in 0.69s.
@pkhadson
Copy link

it is solved? i've the same problem

@dantzjs
Copy link

dantzjs commented Dec 18, 2023

A swc plugin is needed. You can replace esbuild builder for swc:

npm install -D @swc/core

or any adapter for esbuild

@ljb2458
Copy link

ljb2458 commented Apr 15, 2024

需要一个 swc 插件。您可以将 esbuild builder 替换为 swc:

npm install -D @swc/核心

或任何用于 esbuild 的适配器

After this modification, there is still no solution

package.json

{
  "name": "fastify-test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "dev": "vite",
    "tsc": "tsc && node dist/tsc/app.js",
    "build": "vite build"
  },
  "type": "module",
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@fastify/type-provider-typebox": "^4.0.0",
    "@sinclair/typebox": "^0.32.20",
    "fastify": "^4.26.2"
  },
  "devDependencies": {
    "@swc/core": "^1.4.14",
    "ts-node": "^10.9.2",
    "ts-node-dev": "^2.0.0",
    "typescript": "^5.4.5",
    "vite": "^4.5.3",
    "vite-plugin-node": "^3.1.0"
  }
}
export default defineConfig((config) => {
  return {
    server: {
      port: 3000,
      host: "0.0.0.0",
    },
    base: "./",
    build: {
      target: "node18",
      minify: "esbuild",
      sourcemap: "inline",
      emptyOutDir: true,
    },
    optimizeDeps: {
      esbuildOptions: { treeShaking: true },
    },
    plugins: [
      ...VitePluginNode({
        adapter: "fastify",
        appPath: "src/main.ts",
        exportName: "app",
        tsCompiler: "swc",
      }),
    ],
  };
});

I need help

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants