Skip to content

Commit

Permalink
feat: use appropriate core-js polyfill for ie11
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed May 11, 2020
1 parent 1a4bbed commit 5281e66
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 15 deletions.
3 changes: 2 additions & 1 deletion .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ example
.nuxt
./dist
docs
coverage
coverage
src/plugin.js
9 changes: 9 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
lib
test/fixture
test/e2e
example
.nuxt
./dist
docs
coverage
src/plugin.js
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
18 changes: 5 additions & 13 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import typescript from 'rollup-plugin-typescript2'
import copy from 'rollup-plugin-copy'

import pkg from './package.json'

export default [
Expand All @@ -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' }],
}),
],
},
{
Expand Down
16 changes: 15 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,24 @@ import { Module } from '@nuxt/types'

const compositionApiModule: Module<any> = 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 || {}
Expand Down
8 changes: 8 additions & 0 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand Down
37 changes: 37 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 5281e66

Please sign in to comment.