diff --git a/packages/uni-cli-shared/lib/platform.js b/packages/uni-cli-shared/lib/platform.js index c165ee5a114a0ed9f1876e732a3ac74df0ac9875..ce90984241bbaa0c79fee593d820b022ac617ce3 100644 --- a/packages/uni-cli-shared/lib/platform.js +++ b/packages/uni-cli-shared/lib/platform.js @@ -123,7 +123,9 @@ const PLATFORMS = { } = getH5Options() const to = path.join(assetsDir, `[name].${VUE_APP_INDEX_CSS_HASH}.[ext]`) if (process.env.NODE_ENV === 'production') { - const templateContent = fs.readFileSync(template, { encoding: 'utf8' }) + const templateContent = fs.readFileSync(template, { + encoding: 'utf8' + }) if (/\bVUE_APP_INDEX_CSS_HASH\b/.test(templateContent)) { indexCssCopyOptions[0].to = to } @@ -584,5 +586,18 @@ module.exports = { }, getPlatformSass () { return SASS + }, + getBabelParserOptions () { + return { + sourceType: 'module', + plugins: [ + 'optionalChaining', + 'typescript', + ['decorators', { + decoratorsBeforeExport: true + }], + 'classProperties' + ] + } } -} +} diff --git a/packages/webpack-uni-mp-loader/lib/main-new.js b/packages/webpack-uni-mp-loader/lib/main-new.js index 36545b8a617c44661fc69a1faad696f7ac65daf9..e6710378fa8c538e14150d6b71bf482be8536d7c 100644 --- a/packages/webpack-uni-mp-loader/lib/main-new.js +++ b/packages/webpack-uni-mp-loader/lib/main-new.js @@ -13,6 +13,10 @@ const { jsPreprocessOptions } = require('@dcloudio/uni-cli-shared') +const { + getBabelParserOptions +} = require('@dcloudio/uni-cli-shared/lib/platform') + const { updateUsingComponents } = require('@dcloudio/uni-cli-shared/lib/cache') @@ -55,14 +59,14 @@ module.exports = function (content) { const vuePagePath = path.resolve(process.env.UNI_INPUT_DIR, normalizePath(params.page) + '.vue') if (!fs.existsSync(vuePagePath)) { const nvuePagePath = path.resolve(process.env.UNI_INPUT_DIR, normalizePath(params.page) + - '.nvue') + '.nvue') if (fs.existsSync(nvuePagePath)) { ext = '.nvue' } } } return ` -import Vue from 'vue' +import Vue from 'vue' import Page from './${normalizePath(params.page)}${ext}' createPage(Page) ` @@ -78,16 +82,7 @@ createPage(Page) state: { components } - } = traverse(parser.parse(content, { - sourceType: 'module', - plugins: [ - 'typescript', - ['decorators', { - decoratorsBeforeExport: true - }], - 'classProperties' - ] - }), { + } = traverse(parser.parse(content, getBabelParserOptions()), { components: [] }) diff --git a/packages/webpack-uni-mp-loader/lib/script-new.js b/packages/webpack-uni-mp-loader/lib/script-new.js index 802ecb5f72c9563e4b71f1a665e4ca1192ccc974..73cd147d0dab970d16608e5c5005bb9295d8052d 100644 --- a/packages/webpack-uni-mp-loader/lib/script-new.js +++ b/packages/webpack-uni-mp-loader/lib/script-new.js @@ -10,6 +10,10 @@ const { jsPreprocessOptions } = require('@dcloudio/uni-cli-shared') +const { + getBabelParserOptions +} = require('@dcloudio/uni-cli-shared/lib/platform') + const { updateUsingComponents } = require('@dcloudio/uni-cli-shared/lib/cache') @@ -63,16 +67,7 @@ module.exports = function (content, map) { state: { components } - } = traverse(parser.parse(content, { - sourceType: 'module', - plugins: [ - 'typescript', - ['decorators', { - decoratorsBeforeExport: true - }], - 'classProperties' - ] - }), { + } = traverse(parser.parse(content, getBabelParserOptions()), { type, components: [] })