Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build @php-wasm packages as dual ESM + CJS #2087

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading