From d31de58c883a533616810b7990a069eb5df3d154 Mon Sep 17 00:00:00 2001 From: Tsotne Gvadzabia <32150283+RockiRider@users.noreply.github.com> Date: Thu, 28 Nov 2024 22:47:18 +0000 Subject: [PATCH] feat: add cjs support (#58) --- .github/workflows/release.yml | 3 +++ .github/workflows/triage.yml | 4 +++- package.json | 2 +- packages/vite-plugin-csp-guard/package.json | 8 +++++--- .../vite-plugin-csp-guard/rollup.config.mjs | 19 +++++++++++++------ 5 files changed, 25 insertions(+), 11 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b8a35fe..3228e8b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -26,6 +26,9 @@ jobs: - name: Run Unit Tests run: pnpm p:test + - name: Build Apps + run: pnpm build + - name: Install Playwright Browsers run: npx playwright install --with-deps chromium diff --git a/.github/workflows/triage.yml b/.github/workflows/triage.yml index 1a614b9..ebe020d 100644 --- a/.github/workflows/triage.yml +++ b/.github/workflows/triage.yml @@ -22,7 +22,9 @@ jobs: run: pnpm p:build - name: Run Unit Tests run: pnpm p:test - + - name: Build Apps + run: pnpm build + - name: Install Playwright Browsers run: npx playwright install --with-deps chromium diff --git a/package.json b/package.json index d6c0e0e..9886349 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "vite-csp", "private": true, "scripts": { - "build": "turbo build", + "build": "turbo build --filter=!docs --filter=!remix-spa --filter=!remix-app", "p:build": "turbo build --filter=vite-plugin-csp-guard", "p:test": "turbo test --filter=vite-plugin-csp-guard", "dev": "turbo dev", diff --git a/packages/vite-plugin-csp-guard/package.json b/packages/vite-plugin-csp-guard/package.json index 7a34ea7..f536fa4 100644 --- a/packages/vite-plugin-csp-guard/package.json +++ b/packages/vite-plugin-csp-guard/package.json @@ -19,11 +19,13 @@ "url": "https://github.com/RockiRider/csp/issues" }, "license": "GPL-3.0-only", - "main": "dist/index.js", - "module": "dist/index.js", + "main": "dist/index.cjs.js", + "module": "dist/index.esm.js", "exports": { ".": { - "import": "./dist/index.js" + "types": "./dist/index.d.ts", + "require": "./dist/index.cjs.js", + "import": "./dist/index.esm.js" } }, "types": "dist/index.d.ts", diff --git a/packages/vite-plugin-csp-guard/rollup.config.mjs b/packages/vite-plugin-csp-guard/rollup.config.mjs index 7f69a3e..0911add 100644 --- a/packages/vite-plugin-csp-guard/rollup.config.mjs +++ b/packages/vite-plugin-csp-guard/rollup.config.mjs @@ -6,11 +6,18 @@ import terser from "@rollup/plugin-terser"; export default defineConfig({ input: "src/index.ts", // Your plugin's entry point - output: { - file: "dist/index.js", - format: "esm", // Output as ES Module - sourcemap: false, - }, + output: [ + { + file: "dist/index.esm.js", + format: "esm", // Output as ES Module + sourcemap: false, + }, + { + file: "dist/index.cjs.js", + format: "cjs", // Output as CommonJS + sourcemap: false, + }, + ], external: ["lightningcss", "fsevents", "vite", "cheerio"], plugins: [ typescript({ @@ -24,4 +31,4 @@ export default defineConfig({ commonjs(), // Converts commonjs to ES modules terser(), // Minify ], -}); +}); \ No newline at end of file