crxjs / chrome-extension-tools

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

@crxjs/vite-plugin doesn't work with the @sveltejs/kit/vite #505

Open gprieto opened 1 year ago

gprieto commented 1 year ago

Build tool

Vite

Where do you see the problem?

Describe the bug

When using this vite-plugin with SvelteKit and the adapter-static, the build fails with:

> web2notion@0.0.1 build
> vite build

vite v3.0.9 building for production...
✓ 36 modules transformed.
Could not resolve entry module (index.html).
error during build:
Error: Could not resolve entry module (index.html).
    at error (file:///workspace/node_modules/rollup/dist/es/shared/rollup.js:1858:30)
    at ModuleLoader.loadEntryModule (file:///workspace/node_modules/rollup/dist/es/shared/rollup.js:22352:20)
    at async Promise.all (index 0)

Reproduction

Using the following vite.config:

import { sveltekit } from '@sveltejs/kit/vite';
import { crx } from '@crxjs/vite-plugin';
import manifest from './manifest.json';
import { defineConfig } from 'vite';

const config = defineConfig(({ command, mode, ssrBuild }) => {
    return {
        plugins: [
            sveltekit(), 
            crx({ manifest })
        ],
    };
});

export default config;

and then running npm build run

Severity

blocking all usage of RPCE

gprieto commented 1 year ago

The current workaround I found is running the build twice:

With vite.config.js:

const config = defineConfig(({ command, mode, ssrBuild }) => {
    return {
        plugins: (() => {
            if (mode === "sveltekit"){
                return [sveltekit()]
            }
            else if (mode === "crx"){
                return [crx({ manifest })]
            }
            else{
                return []
            }})(),
    };
});

export default config;
B4Dmonkey commented 1 year ago

I'm running into this issue as well, any idea on how one could do the temp fix using UserConfig? I might be missing something but I'm not seeing an api definition for this interface on vite's website

import manifest from './static/manifest.json';
import { crx } from '@crxjs/vite-plugin';
import { sveltekit } from '@sveltejs/kit/vite';
import type { UserConfig } from 'vite';

const config: UserConfig = {
    plugins: [sveltekit(), crx({ manifest })],
    test: {
        include: ['src/**/*.{test,spec}.{js,ts}']
    }
};

export default config;