add URLSearchParams polyfill

This commit is contained in:
Nolan Lawson 2018-01-07 23:00:15 -08:00
parent bd6e2827c9
commit a249b2a608
3 changed files with 21 additions and 2 deletions

5
package-lock.json generated
View File

@ -5011,6 +5011,11 @@
}
}
},
"url-search-params": {
"version": "0.10.0",
"resolved": "https://registry.npmjs.org/url-search-params/-/url-search-params-0.10.0.tgz",
"integrity": "sha512-oFPzmbPAbdthStgffGq8alULe47skPDt1X3KW6NOQnKkcLHP4IS1NfdfHG/CBP5lGsr2gDzNp87pfWLx/eIxjw=="
},
"util": {
"version": "0.10.3",
"resolved": "https://registry.npmjs.org/util/-/util-0.10.3.tgz",

View File

@ -27,6 +27,7 @@
"svelte": "^1.50.0",
"svelte-loader": "^2.3.3",
"uglifyjs-webpack-plugin": "^1.1.5",
"url-search-params": "^0.10.0",
"webpack": "^3.10.0"
},
"engines": {

View File

@ -1,4 +1,17 @@
import { init } from 'sapper/runtime.js';
// polyfills
Promise.all([
typeof URLSearchParams === 'undefined' && import('url-search-params').then(Params => {
window.URLSearchParams = Params
Object.defineProperty(window.URL.prototype, 'searchParams', {
get() {
return new Params(this.search)
}
})
})
]).then(() => {
console.log('done')
// `routes` is an array of route objects injected by Sapper
init(document.querySelector('#sapper'), __routes__);
init(document.querySelector('#sapper'), __routes__)
})