From 659ba90699018761925f67bf698821f444da6691 Mon Sep 17 00:00:00 2001 From: Guillaume Chau Date: Mon, 15 Jan 2024 09:48:39 +0100 Subject: [PATCH] fix: improve esm support, fix #1524 --- packages/vue-apollo-components/build/rollup.config.es.js | 2 +- packages/vue-apollo-components/package.json | 4 ++-- packages/vue-apollo-option/build/rollup.config.es.js | 2 +- packages/vue-apollo-option/package.json | 4 ++-- packages/vue-apollo-ssr/build.mjs | 8 ++++++++ packages/vue-apollo-ssr/package.json | 2 +- 6 files changed, 15 insertions(+), 7 deletions(-) create mode 100644 packages/vue-apollo-ssr/build.mjs diff --git a/packages/vue-apollo-components/build/rollup.config.es.js b/packages/vue-apollo-components/build/rollup.config.es.js index 6f2007d1c..788c9ce91 100644 --- a/packages/vue-apollo-components/build/rollup.config.es.js +++ b/packages/vue-apollo-components/build/rollup.config.es.js @@ -2,7 +2,7 @@ import base from './rollup.config.base' const config = Object.assign({}, base, { output: { - file: 'dist/vue-apollo-components.esm.js', + file: 'dist/vue-apollo-components.esm.mjs', format: 'es', name: 'vue-apollo-components', }, diff --git a/packages/vue-apollo-components/package.json b/packages/vue-apollo-components/package.json index eaa3849a2..de7e0137b 100644 --- a/packages/vue-apollo-components/package.json +++ b/packages/vue-apollo-components/package.json @@ -3,11 +3,11 @@ "version": "4.0.0-beta.12", "description": "Apollo GraphQL components for Vue.js", "main": "dist/vue-apollo-components.umd.js", - "module": "dist/vue-apollo-components.esm.js", + "module": "dist/vue-apollo-components.esm.mjs", "unpkg": "dist/vue-apollo-components.min.js", "exports": { ".": { - "import": "./dist/vue-apollo-components.esm.js", + "import": "./dist/vue-apollo-components.esm.mjs", "require": "./dist/vue-apollo-components.umd.js" }, "./*": "./*" diff --git a/packages/vue-apollo-option/build/rollup.config.es.js b/packages/vue-apollo-option/build/rollup.config.es.js index 317f9e85e..ddf0da084 100644 --- a/packages/vue-apollo-option/build/rollup.config.es.js +++ b/packages/vue-apollo-option/build/rollup.config.es.js @@ -2,7 +2,7 @@ import base from './rollup.config.base' const config = Object.assign({}, base, { output: { - file: 'dist/vue-apollo-option.esm.js', + file: 'dist/vue-apollo-option.esm.mjs', format: 'es', name: 'vue-apollo', }, diff --git a/packages/vue-apollo-option/package.json b/packages/vue-apollo-option/package.json index 3d0dbab90..d79d1ecd8 100644 --- a/packages/vue-apollo-option/package.json +++ b/packages/vue-apollo-option/package.json @@ -3,13 +3,13 @@ "version": "4.0.0-beta.12", "description": "Use Apollo and GraphQL with Vue.js using the `apollo` option", "main": "dist/vue-apollo-option.umd.js", - "module": "dist/vue-apollo-option.esm.js", + "module": "dist/vue-apollo-option.esm.mjs", "unpkg": "dist/vue-apollo-option.min.js", "types": "types/index.d.ts", "exports": { ".": { "types": "./types/index.d.ts", - "import": "./dist/vue-apollo-option.esm.js", + "import": "./dist/vue-apollo-option.esm.mjs", "require": "./dist/vue-apollo-option.umd.js" }, "./*": "./*" diff --git a/packages/vue-apollo-ssr/build.mjs b/packages/vue-apollo-ssr/build.mjs new file mode 100644 index 000000000..ea0ebfb26 --- /dev/null +++ b/packages/vue-apollo-ssr/build.mjs @@ -0,0 +1,8 @@ +import path from 'node:path' +import fs from 'node:fs' + +const file = path.join(process.cwd(), 'dist', 'esm', 'package.json') + +fs.writeFileSync(file, JSON.stringify({ + "type": "module", +}, null, 2), 'utf-8') diff --git a/packages/vue-apollo-ssr/package.json b/packages/vue-apollo-ssr/package.json index a0c34413e..df58ecd20 100644 --- a/packages/vue-apollo-ssr/package.json +++ b/packages/vue-apollo-ssr/package.json @@ -38,7 +38,7 @@ ], "scripts": { "dev": "pnpm run build --watch", - "build": "rm -rf dist && tsc --outDir dist/esm -d && tsc --outDir dist/cjs --module commonjs --target ES2015", + "build": "rm -rf dist && tsc --outDir dist/esm -d && tsc --outDir dist/cjs --module commonjs --target ES2015 && node ./build.mjs", "prepublishOnly": "pnpm run build" }, "dependencies": {