`vite build` ignores `optimizeDeps.include`
See original GitHub issueDescribe the bug
optimizeDeps.include
option in config file is ignored by vite build
command, while dev-server (just vite
command) performs optimizing steps for the included files.
I use these feature because of I have to deal with CommonJS modules. My project uses gRPC-Web and generetes JavaScript-clients by Protocol Buffer Compiler with gRPC-Web plugin. This tool can’t generate ES modules syntax currently.
During migrating to Vite from Webpack I move the generated files to local package ("my-project-proto": "file:./my-project-proto"
) and instruct Vite to optimize it (convert from cjs -> esm) by optimizeDeps.include
option.
npm run dev
does the trick, and I can see properly converted files in the cache, but npm run build
skip this step. Even when I intentionally make typo in value of optimizeDeps.include
, then npm run build
doesn’t react to it, while npm run dev
exits with error about the dependency: Error: Failed to resolve force included dependency: my-package-name-with-typo
.
Reproduction
To investigate the problem, I experiment with it in specailly created minimal project: buggy state commit. To reproduce the bug, clone the repo and execute npm run build
. This repo is not about gRPC-Web, but for illustrate more common ~pattern~ bug: using CommonJS modules in Vite project.
System Info
Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:
System:
OS: Linux 5.8 Ubuntu 20.10 (Groovy Gorilla)
CPU: (8) x64 Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz
Memory: 22.69 GB / 31.30 GB
Container: Yes
Shell: 5.8 - /usr/bin/zsh
Binaries:
Node: 12.18.2 - /usr/bin/node
npm: 6.14.8 - /usr/bin/npm
Browsers:
Chromium: 91.0.4472.114
Firefox: 89.0.1
npmPackages:
vite: ^2.3.7 => 2.3.8
Used package manager: npm
Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:6
Would it be possible to do this without requiring a local package. I have the following structure where generated protofiles are placed in src/proto, and i just want to be able to point the config to src/proto, and have it transform the the files to ES6.
The execution process of the build does not include dependency pre-bundling, so optimizeDeps.include is invalid
build commonjsOptions include’s default config is
[/node_modules/]
, this caused the error.https://github.com/vitejs/vite/blob/bb095db11db5c7a12db6dcee866694f1f68d1e15/packages/vite/src/node/build.ts#L212-L216
the following config is work