crxjs / chrome-extension-tools

Bundling Chrome Extensions can be pretty complex. It doesn't have to be.
https://crxjs.dev/vite-plugin
2.98k stars 192 forks source link

auto-copy manifest assets not work when extension build #361

Closed chansyawn closed 2 years ago

chansyawn commented 2 years ago

Build tool

Vite

Where do you see the problem?

Describe the bug

Plugin cannot find the icons file path when executing vite build, but the file has been duplicated to the dist folder. The plugin looks like trying to get the file from the root directory, should the code here be changed to config.build.outDir. https://github.com/crxjs/rollup-plugin-chrome-extension/blob/41ee1542f7ee470f8acddda1df15d2569509e008/packages/vite-plugin/src/node/plugin-manifest.ts#L275

Reproduction

file structure

├── public
│   ├── favicon.svg
│   └── icons
│       ├── icon128.png
│       ├── icon16.png
│       ├── icon32.png
│       └── icon48.png
└──src

manifest.config.ts

export default defineManifest({
  //...
  action: {
    default_icon: {
      16: 'icons/icon16.png',
      32: 'icons/icon32.png',
      48: 'icons/icon48.png',
      128: 'icons/icon128.png',
    },
  },
  icons: {
    16: 'icons/icon16.png',
    32: 'icons/icon32.png',
    48: 'icons/icon48.png',
    128: 'icons/icon128.png',
  }
});

Logs

> tsc && vite build

vite v2.9.8 building for production...
✓ 639 modules transformed.
[crx:manifest-post] ENOENT: no such file or directory, open '/home/****/project/icons/icon16.png'
error during build:
Error: ENOENT: no such file or directory, open '/home/****/project/icons/icon16.png'

System Info

System:
    OS: Linux 5.10 Ubuntu 20.04 LTS (Focal Fossa)
    CPU: (8) x64 11th Gen Intel(R) Core(TM) i5-1135G7 @ 2.40GHz
    Memory: 4.70 GB / 7.66 GB
    Container: Yes
    Shell: 5.8 - /usr/bin/zsh
  Binaries:
    Node: 16.15.0 - ~/.nvm/versions/node/v16.15.0/bin/node
    Yarn: 1.22.18 - ~/.nvm/versions/node/v16.15.0/bin/yarn
    npm: 8.8.0 - ~/.nvm/versions/node/v16.15.0/bin/npm
  npmPackages:
    vite: ^2.9.7 => 2.9.8

Severity

annoyance

yvywang commented 2 years ago

I have the same problem, hope to repair it soon 🤔

yvywang commented 2 years ago

I found that the plugincrx:manifest-posthad this logic, and maybe should discard icons? 🤔 @jacksteamdev

image
jacksteamdev commented 2 years ago

I've added icons to an integration test to ensure that manifest assets are copied from either the project root or the public dir.

jacksteamdev commented 2 years ago

This bugfix was released to NPM in @crxjs/vite-plugin@1.0.4 :rocket: