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

assetsInclude=[] in vite config causes extra file generation and path complications #10926

Closed
7 tasks done
colearendt opened this issue Nov 14, 2022 · 2 comments · Fixed by #10941
Closed
7 tasks done
Labels
contribution welcome p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@colearendt
Copy link

Describe the bug

Using vite-plugin-web-extension to create a web extension, I happened upon very strange behavior. Namely,

  • files would sometimes be produced at incorrect paths (i.e. if src/popup/popup.html, then output at dist/popup.html
  • some files would get content like export default "/popup.html"
  • error messages like:
Generated an empty chunk: "popup/popup"
"popup.html" overwrites a previously emitted file of the same name

The fix for this behavior was to remove the following line from my vite.config.ts (which was there as a placeholder):

assetsInclude: []

Reproduction

https://github.com/colearendt/extensions-example

Steps to reproduce

  • npm run build
  • notice there is a dist/popup.html file with contents: export default "/popup.html"%
  • remove the assetsInclude: [] line from vite.config.ts
  • Build and notice dist/popup.html has expected contents

System Info

System:
    OS: macOS 12.2.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 91.50 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 16.15.1 - ~/.nvm/versions/node/v16.15.1/bin/node
    Yarn: 1.22.18 - /opt/homebrew/bin/yarn
    npm: 8.11.0 - ~/.nvm/versions/node/v16.15.1/bin/npm
  Browsers:
    Brave Browser: 104.1.42.88
    Chrome: 107.0.5304.110
    Firefox: 106.0.5
    Safari: 15.3
  npmPackages:
    @vitejs/plugin-vue: ^3.2.0 => 3.2.0 
    vite: ^3.2.3 => 3.2.3

Used Package Manager

npm

Logs

 npm run build

> [email protected] build
> vue-tsc && vite build

vite v3.2.3 building for production...

[vite-plugin-web-extension] 
  Building HTML Pages in Multi-Page Mode:
    • src/popup.html
  Building in Lib Mode:
    • (none)

[vite-plugin-web-extension] Building HTML Pages in Multi-Page Mode
✓ 1 modules transformed.
Generated an empty chunk: "popup"
rendering chunks (1)...The emitted file "popup.html" overwrites a previously emitted file of the same name.
../dist/assets/vue.svg   0.48 KiB
../dist/manifest.json    0.28 KiB
../dist/popup.html       0.03 KiB

Validations

@colearendt colearendt changed the title assetsInclude causes extra file generation and path complications assetsInclude=[] in vite config causes extra file generation and path complications Nov 14, 2022
@bluwy
Copy link
Member

bluwy commented Nov 15, 2022

Looks like it's because the empty array is passed to here as-is:

const assetsFilter = config.assetsInclude
? createFilter(config.assetsInclude)
: () => false

which equals to () => true, which probably isn't what the most people expect. This code should instead check that the array has at least one children before using createFilter.

@bluwy bluwy added contribution welcome p3-minor-bug An edge case that only affects very specific usage (priority) and removed pending triage labels Nov 15, 2022
@github-actions
Copy link

Hello @colearendt. We like your proposal/feedback and would appreciate a contribution via a Pull Request by you or another community member. We thank you in advance for your contribution and are looking forward to reviewing it!

@github-actions github-actions bot locked and limited conversation to collaborators Nov 30, 2022
patak-dev pushed a commit that referenced this issue Nov 30, 2022
* fix(config): exclude config.assetsInclude empty array (#10941)

fixes #10926

* feat(css): upgrade postcss-modules (#10987)

* fix(mpa): support mpa fallback (#10985)

fixes #10966

* fix: export preprocessCSS in CJS (#11067)

* chore: update license

Co-authored-by: sun0day <[email protected]>
Co-authored-by: Jason Quense <[email protected]>
Co-authored-by: sun0day <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution welcome p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants