aklinker1 / vite-plugin-web-extension

Vite plugin for developing Chrome/Web Extensions
https://vite-plugin-web-extension.aklinker1.io/
MIT License
654 stars 57 forks source link

`build.emptyOutDir = true` has no effect #184

Closed NicolasReibnitz closed 8 months ago

NicolasReibnitz commented 8 months ago

Summary

Hi!

I understand that you internally check if the user set build.emptyOutDir and then manually remove that folder before anything else because you definitely have to set it internally to false. So far, so good, but it seems that resolvedConfig.build.emptyOutDir was already overwritten at the time you test for it.

So, if I don't miss anything, the line referenced here

https://github.com/aklinker1/vite-plugin-web-extension/blob/191fa4f69617e763da0ba334c914b45ff28801b7/packages/vite-plugin-web-extension/src/plugins/manifest-loader-plugin.ts#L222

should be

if (userConfig.build.emptyOutDir) { 

instead.

This is the only way I can get the plugin to empty out the dist folder before building the extension.

Reproduction

The default setup plus the build.emptyOutDir option set to true will be enough to demonstrate that the dist folder is not emptied.

// vite.config.ts
import { defineConfig } from 'vite';
import webExtension from 'vite-plugin-web-extension';

export default defineConfig({
    build: {
        emptyOutDir: true
    },
    plugins: [webExtension()]
});

Feel free to let me know if you need anything else.

Environment

  System:
    OS: macOS 14.3.1
    CPU: (12) arm64 Apple M2 Max
    Memory: 335.38 MB / 64.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 18.14.2 - ~/Library/Caches/fnm_multishells/46290_1710372422808/bin/node
    npm: 9.5.0 - ~/Library/Caches/fnm_multishells/46290_1710372422808/bin/npm
    pnpm: 8.14.1 - /opt/homebrew/bin/pnpm
  Browsers:
    Brave Browser: 122.1.63.165
    Chrome: 122.0.6261.129
    Chrome Canary: 124.0.6356.2
    Edge: 122.0.2365.80
    Safari: 17.3.1
  npmPackages:
    vite: ^5.0.0 => 5.1.5 
    vite-plugin-web-extension: ^4.0.0 => 4.1.1 

Thanks!

aklinker1 commented 8 months ago

https://github.com/aklinker1/vite-plugin-web-extension/releases/tag/v4.1.3