Skip to content

Commit

Permalink
[ADD] plugin to remove dev icons from prod build
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnBra committed Nov 28, 2023
1 parent b5a2732 commit 97beb81
Show file tree
Hide file tree
Showing 3 changed files with 180 additions and 159 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@
"tailwindcss": "^3.2.4",
"ts-node": "^10.9.1",
"typescript": "^4.9.4",
"vite": "^4.0.4"
"vite": "^4.5.0"
}
}
23 changes: 20 additions & 3 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import react from '@vitejs/plugin-react-swc';
import { resolve } from 'path';
import fs from 'fs';
import { defineConfig } from 'vite';
import { crx, ManifestV3Export } from '@crxjs/vite-plugin';

Expand All @@ -17,12 +18,27 @@ const isDev = process.env.__DEV__ === 'true';

const extensionManifest = {
...manifest,
...(isDev ? devManifest: {} as ManifestV3Export),
...(isDev ? devManifest : {} as ManifestV3Export),
name: isDev ? `DEV: ${ manifest.name }` : manifest.name,
version: pkg.version,
};

console.log('manifest', extensionManifest)
// plugin to remove dev icons from prod build
function stripDevIcons (apply: boolean) {
if (apply) return null

return {
name: 'strip-dev-icons',
resolveId (source: string) {
return source === 'virtual-module' ? source : null
},
renderStart (outputOptions: any, inputOptions: any) {
const outDir = outputOptions.dir
fs.rm(resolve(outDir, 'dev-icon-32.png'), () => console.log(`Deleted dev-icon-32.png frm prod build`))
fs.rm(resolve(outDir, 'dev-icon-128.png'), () => console.log(`Deleted dev-icon-128.png frm prod build`))
}
}
}

export default defineConfig({
resolve: {
Expand All @@ -40,11 +56,12 @@ export default defineConfig({
injectCss: true,
}
}),
stripDevIcons(isDev)
],
publicDir,
build: {
outDir,
sourcemap: isDev,
emptyOutDir: !isDev,
emptyOutDir: !isDev
},
});
Loading

0 comments on commit 97beb81

Please sign in to comment.