Skip to content

Commit 0087e4f

Browse files
fix(pubsub): fix ESM compatibility issue
Added @rollup/plugin-commonjs to handle CommonJS modules in ESM build, ensuring compatibility with paho-mqtt.js. Co-authored-by: Joon Choi <13882232+joon-won@users.noreply.github.com>
1 parent 5c85092 commit 0087e4f

File tree

4 files changed

+33
-8
lines changed

4 files changed

+33
-8
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"@babel/preset-react": "^7.0.0",
8383
"@eslint/compat": "^1.2.0",
8484
"@lerna/legacy-package-management": "^8.2.1",
85+
"@rollup/plugin-commonjs": "^28.0.1",
8586
"@rollup/plugin-typescript": "^11.1.6",
8687
"@size-limit/dual-publish": "^8.1.0",
8788
"@size-limit/file": "^8.1.0",

packages/pubsub/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
"test:size": "size-limit",
1616
"build-with-test": "npm run clean && npm run build",
1717
"build:umd": "webpack && webpack --config ./webpack.config.dev.js",
18-
"build:esm-cjs": "rollup --forceExit -c rollup.config.mjs && cp -R src/vendor dist/cjs/vendor && cp -R src/vendor dist/esm/vendor",
19-
"build:watch": "mkdirp dist/esm/vendor && mkdirp dist/cjs/vendor && cp -R src/vendor dist/cjs/vendor && cp -R src/vendor dist/esm/vendor && rollup --forceExit -c rollup.config.mjs --watch",
18+
"build:esm-cjs": "rollup --forceExit -c rollup.config.mjs && cp -R src/vendor dist/cjs/vendor",
19+
"build:watch": "mkdirp dist/esm/vendor && mkdirp dist/cjs/vendor && cp -R src/vendor dist/cjs/vendor && rollup --forceExit -c rollup.config.mjs --watch",
2020
"build": "npm run clean && npm run build:esm-cjs && npm run build:umd",
2121
"clean": "npm run clean:size && rimraf dist lib lib-esm",
2222
"clean:size": "rimraf dual-publish-tmp tmp*",

packages/pubsub/rollup.config.mjs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
import { fileURLToPath } from 'node:url';
55
import { defineConfig } from 'rollup';
6+
import commonjs from '@rollup/plugin-commonjs';
67
import typescript from '@rollup/plugin-typescript';
78
import { getInputForGlob } from '../../rollup/utils.mjs';
89
import {
@@ -27,11 +28,14 @@ const config = defineConfig([
2728
// ESM config
2829
{
2930
input: input,
30-
external: [
31-
fileURLToPath(new URL('src/vendor/paho-mqtt.js', import.meta.url)),
32-
],
3331
output: esmOutput,
34-
plugins: [typescript(esmTSOptions)],
32+
plugins: [
33+
commonjs({
34+
include: ['src/vendor/paho-mqtt.js'],
35+
exclude: ['**/*.ts'],
36+
}),
37+
typescript(esmTSOptions),
38+
],
3539
},
3640
]);
3741

yarn.lock

Lines changed: 22 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)