diff --git a/.eslintignore b/.eslintignore index 6ff509fc..546965b3 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,4 +5,5 @@ example .nuxt ./dist docs -coverage \ No newline at end of file +coverage +src/plugin.js \ No newline at end of file diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..546965b3 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,9 @@ +lib +test/fixture +test/e2e +example +.nuxt +./dist +docs +coverage +src/plugin.js \ No newline at end of file diff --git a/package.json b/package.json index ec06032b..a4faa329 100644 --- a/package.json +++ b/package.json @@ -87,6 +87,7 @@ "prettier-eslint-cli": "^5.0.0", "release-it": "13.5.8", "rollup": "^2.9.0", + "rollup-plugin-copy": "^3.3.0", "rollup-plugin-typescript2": "^0.27.0", "start-server-and-test": "^1.11.0", "testcafe": "^1.8.4", diff --git a/rollup.config.js b/rollup.config.js index f23ce460..c059fad7 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,4 +1,6 @@ import typescript from 'rollup-plugin-typescript2' +import copy from 'rollup-plugin-copy' + import pkg from './package.json' export default [ @@ -23,19 +25,9 @@ export default [ typescript({ typescript: require('typescript'), }), - ], - }, - { - input: 'src/plugin.js', - output: [ - { - file: 'lib/plugin.js', - format: 'es', - }, - ], - external: [ - ...Object.keys(pkg.dependencies || {}), - ...Object.keys(pkg.peerDependencies || {}), + copy({ + targets: [{ src: 'src/plugin.js', dest: 'lib' }], + }), ], }, { diff --git a/src/index.ts b/src/index.ts index 6f502908..fcc150d6 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,10 +3,24 @@ import { Module } from '@nuxt/types' const compositionApiModule: Module = function () { const libRoot = resolve(__dirname, '..') + + let corejsPolyfill + try { + if (!this.options.modern) { + // eslint-disable-next-line + const corejsPkg = require('core-js/package.json') + corejsPolyfill = corejsPkg.version.slice(0, 1) + } + } catch { + corejsPolyfill = undefined + } + const { dst } = this.addTemplate({ src: resolve(libRoot, 'lib', 'plugin.js'), fileName: join('composition-api', 'plugin.js'), - options: {}, + options: { + corejsPolyfill, + }, }) this.options.build = this.options.build || {} diff --git a/src/plugin.js b/src/plugin.js index f59029ce..0737228a 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -2,6 +2,14 @@ * @typedef {import('@nuxt/types').Plugin} Plugin */ +<% if (options.corejsPolyfill === '3') { %> +// Necessary polyfill for Composition API support for IE11 +import 'core-js/features/reflect/own-keys' +<% } else if (options.corejsPolyfill === '2') { %> +// Necessary polyfill for Composition API support for IE11 +import 'core-js/modules/es6.reflect.own-keys' +<% } %> + import Vue from 'vue' import CompositionApi from '@vue/composition-api' diff --git a/yarn.lock b/yarn.lock index 13cd6fdd..8c5db783 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1979,6 +1979,13 @@ dependencies: "@types/webpack" "*" +"@types/fs-extra@^8.0.1": + version "8.1.0" + resolved "https://registry.yarnpkg.com/@types/fs-extra/-/fs-extra-8.1.0.tgz#1114834b53c3914806cd03b3304b37b3bd221a4d" + integrity sha512-UoOfVEzAUpeSPmjm7h1uk5MH6KZma2z2O7a75onTGjnNvAvMVrPzPL/vBbT65iIGHWj6rokwfmYcmxmlSf2uwg== + dependencies: + "@types/node" "*" + "@types/glob@^7.1.1": version "7.1.1" resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575" @@ -4694,6 +4701,11 @@ color@^3.0.0: color-convert "^1.9.1" color-string "^1.5.2" +colorette@^1.1.0: + version "1.1.0" + resolved "https://registry.yarnpkg.com/colorette/-/colorette-1.1.0.tgz#1f943e5a357fac10b4e0f5aaef3b14cdc1af6ec7" + integrity sha512-6S062WDQUXi6hOfkO/sBPVwE5ASXY4G2+b4atvhJfSsuUUhIaUKlkjLe9692Ipyt5/a+IPF5aVTu3V5gvXq5cg== + combined-stream@^1.0.6, combined-stream@^1.0.8, combined-stream@~1.0.6: version "1.0.8" resolved "https://registry.yarnpkg.com/combined-stream/-/combined-stream-1.0.8.tgz#c3d45a8b34fd730631a110a8a2520682b31d5a7f" @@ -7046,6 +7058,20 @@ globals@^9.18.0: resolved "https://registry.yarnpkg.com/globals/-/globals-9.18.0.tgz#aa3896b3e69b487f17e31ed2143d69a8e30c2d8a" integrity sha512-S0nG3CLEQiY/ILxqtztTWH/3iRRdyBLw6KMDxnKMchrtbj2OFmehVh0WUCfW3DUrIgx/qFrJPICrq4Z4sTR9UQ== +globby@10.0.1: + version "10.0.1" + resolved "https://registry.yarnpkg.com/globby/-/globby-10.0.1.tgz#4782c34cb75dd683351335c5829cc3420e606b22" + integrity sha512-sSs4inE1FB2YQiymcmTv6NWENryABjUNPeWhOvmn4SjtKybglsyPZxFB3U1/+L1bYi0rNZDqCLlHyLYDl1Pq5A== + dependencies: + "@types/glob" "^7.1.1" + array-union "^2.1.0" + dir-glob "^3.0.1" + fast-glob "^3.0.3" + glob "^7.1.3" + ignore "^5.1.1" + merge2 "^1.2.3" + slash "^3.0.0" + globby@11.0.0: version "11.0.0" resolved "https://registry.yarnpkg.com/globby/-/globby-11.0.0.tgz#56fd0e9f0d4f8fb0c456f1ab0dee96e1380bc154" @@ -12257,6 +12283,17 @@ ripemd160@^2.0.0, ripemd160@^2.0.1: hash-base "^3.0.0" inherits "^2.0.1" +rollup-plugin-copy@^3.3.0: + version "3.3.0" + resolved "https://registry.yarnpkg.com/rollup-plugin-copy/-/rollup-plugin-copy-3.3.0.tgz#5ba230047f86b9f703a29288f242948a5580e7b9" + integrity sha512-euDjCUSBXZa06nqnwCNADbkAcYDfzwowfZQkto9K/TFhiH+QG7I4PUsEMwM9tDgomGWJc//z7KLW8t+tZwxADA== + dependencies: + "@types/fs-extra" "^8.0.1" + colorette "^1.1.0" + fs-extra "^8.1.0" + globby "10.0.1" + is-plain-object "^3.0.0" + rollup-plugin-typescript2@^0.27.0: version "0.27.0" resolved "https://registry.yarnpkg.com/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.27.0.tgz#95ff96f9e07d5000a9d2df4d76b548f9a1f83511"