Skip to content

Commit

Permalink
Build @php-wasm packages as dual ESM + CJS (#2087)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamziel authored Dec 17, 2024
1 parent eb876ab commit c5d0811
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 12 deletions.
11 changes: 10 additions & 1 deletion packages/php-wasm/scopes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,17 @@
"directory": "../../../dist/packages/php-wasm/scopes"
},
"license": "GPL-2.0-or-later",
"exports": {
".": {
"import": "./index.js",
"require": "./index.cjs"
},
"./package.json": "./package.json",
"./README.md": "./README.md"
},
"type": "module",
"main": "index.js",
"main": "./index.cjs",
"module": "./index.js",
"types": "index.d.ts",
"gitHead": "2f8d8f3cea548fbd75111e8659a92f601cddc593",
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/php-wasm/scopes/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig({
entry: 'src/index.ts',
name: 'php-wasm-scope',
fileName: 'index',
formats: ['es'],
formats: ['es', 'cjs'],
},
rollupOptions: {
// External packages that should not be bundled into your library.
Expand Down
11 changes: 11 additions & 0 deletions packages/php-wasm/util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
"access": "public",
"directory": "../../../dist/packages/php-wasm/util"
},
"exports": {
".": {
"import": "./index.js",
"require": "./index.cjs"
},
"./package.json": "./package.json",
"./README.md": "./README.md"
},
"type": "module",
"main": "./index.cjs",
"module": "./index.js",
"gitHead": "2f8d8f3cea548fbd75111e8659a92f601cddc593",
"engines": {
"node": ">=18.18.0",
Expand Down
14 changes: 11 additions & 3 deletions packages/php-wasm/web-service-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@
"access": "public",
"directory": "../../../dist/packages/php-wasm/web-service-worker"
},
"license": "GPL-2.0-or-later",
"exports": {
".": {
"import": "./index.js",
"require": "./index.cjs"
},
"./package.json": "./package.json",
"./README.md": "./README.md"
},
"type": "module",
"main": "src/index.js",
"types": "src/index.d.ts",
"main": "./index.cjs",
"module": "./index.js",
"license": "GPL-2.0-or-later",
"gitHead": "2f8d8f3cea548fbd75111e8659a92f601cddc593",
"engines": {
"node": ">=18.18.0",
Expand Down
17 changes: 11 additions & 6 deletions packages/php-wasm/web-service-worker/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,20 @@
"buildTarget": "php-wasm-web-service-worker:build:bundle:production"
}
},
"build:package-json": {
"executor": "@wp-playground/nx-extensions:package-json",
"options": {
"tsConfig": "packages/php-wasm/web-service-worker/tsconfig.lib.json",
"outputPath": "dist/packages/php-wasm/web-service-worker",
"buildTarget": "php-wasm-web-service-worker:build:bundle:production"
}
},
"build:bundle": {
"executor": "@nx/js:tsc",
"executor": "@nx/vite:build",
"outputs": ["{options.outputPath}"],
"options": {
"outputPath": "dist/packages/php-wasm/web-service-worker",
"main": "packages/php-wasm/web-service-worker/src/index.ts",
"tsConfig": "packages/php-wasm/web-service-worker/tsconfig.lib.json",
"assets": ["packages/php-wasm/web-service-worker/*.md"],
"updateBuildableProjectDepsInPackageJson": true
"emptyOutDir": false,
"outputPath": "dist/packages/php-wasm/web-service-worker"
}
},
"lint": {
Expand Down
16 changes: 16 additions & 0 deletions packages/php-wasm/web-service-worker/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { join } from 'path';

// eslint-disable-next-line @nx/enforce-module-boundaries
import { viteTsConfigPaths } from '../../vite-extensions/vite-ts-config-paths';
// eslint-disable-next-line @nx/enforce-module-boundaries
import { getExternalModules } from '../../vite-extensions/vite-external-modules';

export default defineConfig({
cacheDir: '../../../node_modules/.vite/php-wasm-web-service-worker',
Expand All @@ -22,6 +24,20 @@ export default defineConfig({
}),
],

build: {
lib: {
// Could also be a dictionary or array of multiple entry points.
entry: 'src/index.ts',
name: 'php-wasm-web-service-worker',
fileName: 'index',
formats: ['es', 'cjs'],
},
rollupOptions: {
// External packages that should not be bundled into your library.
external: getExternalModules(),
},
},

test: {
globals: true,
cache: {
Expand Down

0 comments on commit c5d0811

Please sign in to comment.