提交 ac42e79d 编写于 作者: Q qiang

fix(nvue): move polyfill to top

上级 7a2d250f
......@@ -35,3 +35,4 @@ packages/uni-stat
node_modules
automator.js
uni.automator.js
uni-polyfill.js
if (typeof Promise !== 'undefined' && !Promise.prototype.finally) {
Promise.prototype.finally = function (callback) {
var promise = this.constructor
return this.then(function (value) {
return promise.resolve(callback()).then(function () {
return value
})
}, function (reason) {
return promise.resolve(callback()).then(function () {
throw reason
})
})
}
}
if (uni.base64ToArrayBuffer) {
ArrayBuffer = uni.base64ToArrayBuffer('').constructor
}
......@@ -316,6 +316,7 @@ module.exports = function () {
extensions: ['.js', '.nvue', '.vue', '.json'],
alias: {
'@': process.env.UNI_INPUT_DIR,
'uni-polyfill': require.resolve('@dcloudio/uni-cli-shared/lib/uni-polyfill.js'),
'uni-pages': path.resolve(process.env.UNI_INPUT_DIR, 'pages.json'),
'uni-app-style': path.resolve(process.env.UNI_INPUT_DIR, getNVueMainEntry()) + '?' + JSON.stringify({
type: 'appStyle'
......
......@@ -59,22 +59,8 @@ module.exports = function (content, map) {
return `
${statCode}
import 'uni-app-style'
import 'uni-polyfill'
import App from './${normalizePath(params.page)}.nvue?mpType=page'
if (typeof Promise !== 'undefined' && !Promise.prototype.finally) {
Promise.prototype.finally = function(callback) {
var promise = this.constructor
return this.then(function(value) {
return promise.resolve(callback()).then(function() {
return value
})
}, function(reason) {
return promise.resolve(callback()).then(function() {
throw reason
})
})
}
}
ArrayBuffer = uni.base64ToArrayBuffer('').constructor
App.mpType = 'page'
App.route = '${params.page}'
App.el = '#root'
......
const fs = require('fs')
function generatePageCode (pages, pageOptions) {
return pages.map(pagePath => {
if (pageOptions[pagePath].nvue) {
......@@ -11,24 +13,15 @@ function generateUniConfig (appJson, isAppView) {
return isAppView ? `window.__uniConfig = ${JSON.stringify({ window: appJson.window }, null)};` : ''
}
function generatePolyfill () {
return fs.readFileSync(require.resolve('@dcloudio/uni-cli-shared/lib/uni-polyfill.js'), { encoding: 'utf8' })
}
module.exports = function definePages (appJson, isAppView) {
return {
name: 'define-pages.js',
content: `
if (typeof Promise !== 'undefined' && !Promise.prototype.finally) {
Promise.prototype.finally = function(callback) {
const promise = this.constructor
return this.then(
value => promise.resolve(callback()).then(() => value),
reason => promise.resolve(callback()).then(() => {
throw reason
})
)
}
}
if(uni.base64ToArrayBuffer){
ArrayBuffer = uni.base64ToArrayBuffer('').constructor
}
${generatePolyfill()}
${generateUniConfig(appJson, isAppView)}
if(uni.restoreGlobal){
uni.restoreGlobal(weex,plus,setTimeout,clearTimeout,setInterval,clearInterval)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册