Skip to content

Commit

Permalink
fix: hotfix manifest.json to work
Browse files Browse the repository at this point in the history
  • Loading branch information
stepan662 committed Oct 18, 2024
1 parent 971dda4 commit 7920aff
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 24 deletions.
42 changes: 21 additions & 21 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"react-dom": "^18.2.0"
},
"devDependencies": {
"@crxjs/vite-plugin": "^2.0.0-beta.21",
"@crxjs/vite-plugin": "2.0.0-beta.25",
"@semantic-release/changelog": "^5.0.1",
"@semantic-release/exec": "^5.0.0",
"@semantic-release/git": "^9.0.0",
Expand Down
40 changes: 38 additions & 2 deletions vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,47 @@
import { defineConfig } from 'vite';
import { defineConfig, Plugin } from 'vite';
import react from '@vitejs/plugin-react';
import { crx } from '@crxjs/vite-plugin';
import zipPack from 'vite-plugin-zip-pack';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import fs from 'node:fs';
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
import path from 'node:path';

import manifest from './manifest.json';

function myPlugin(): Plugin {
function updateManifest() {
const absolutePath = path.resolve('./dist/manifest.json');

const content = fs.readFileSync(absolutePath);
const test = JSON.parse(content);
test.web_accessible_resources = test.web_accessible_resources.map((i) => ({
...i,
use_dynamic_url: false,
}));
fs.writeFile(absolutePath, JSON.stringify(test, null, 2), (err) => {
if (err) {
console.error(err);
} else {
console.log('manifest.json updated');
}
});
}

return {
name: 'my-plugin',
generateBundle(options, bundle) {
console.log(bundle);
},
writeBundle() {
updateManifest();
},
};
}

// https://vitejs.dev/config/
export default defineConfig({
plugins: [react(), crx({ manifest: manifest as any }), zipPack()],
plugins: [react(), crx({ manifest: manifest as any }), myPlugin(), zipPack()],
});

0 comments on commit 7920aff

Please sign in to comment.