diff --git a/packages/vue-cli-plugin-uni/lib/h5/compiler-options.js b/packages/vue-cli-plugin-uni/lib/h5/compiler-options.js index 30782e39b2d9dc6400402931f228f7fba0db385a..82e2f52a4668f9f0a69f3c741c5a1a410e583e49 100644 --- a/packages/vue-cli-plugin-uni/lib/h5/compiler-options.js +++ b/packages/vue-cli-plugin-uni/lib/h5/compiler-options.js @@ -2,6 +2,10 @@ const { tags } = require('@dcloudio/uni-cli-shared') +const { + isUnaryTag +} = require('../util') + const simplePathRE = /^[A-Za-z_$][\w$]*(?:\.[A-Za-z_$][\w$]*|\['[^']*?']|\["[^"]*?"]|\[\d+]|\[[A-Za-z_$][\w$]*])*$/ function processEvent (expr, filterModules) { @@ -41,6 +45,7 @@ function addTag (tag) { } module.exports = { + isUnaryTag, preserveWhitespace: false, modules: [require('../format-text'), { preTransformNode (el, { diff --git a/packages/vue-cli-plugin-uni/lib/mp.js b/packages/vue-cli-plugin-uni/lib/mp.js index 5a5d7e25b200aa51196766909bcbac1c4147f9fc..99ad38f90c50f5a586fb9d77c19f332a6fcf70f1 100644 --- a/packages/vue-cli-plugin-uni/lib/mp.js +++ b/packages/vue-cli-plugin-uni/lib/mp.js @@ -13,6 +13,10 @@ const { getPlatformCssnano } = require('@dcloudio/uni-cli-shared') +const { + isUnaryTag +} = require('./util') + function createUniMPPlugin () { if (process.env.UNI_USING_COMPONENTS) { const WebpackUniMPPlugin = require('@dcloudio/webpack-uni-mp-loader/lib/plugin/index-new') @@ -154,6 +158,7 @@ module.exports = { .tap(options => Object.assign(options, { compiler: getPlatformCompiler(), compilerOptions: process.env.UNI_USING_COMPONENTS ? { + isUnaryTag, preserveWhitespace: false } : require('./mp-compiler-options'), cacheDirectory: false, diff --git a/packages/vue-cli-plugin-uni/lib/util.js b/packages/vue-cli-plugin-uni/lib/util.js new file mode 100644 index 0000000000000000000000000000000000000000..f2b9be2ee2f261d31ae2812ed264534433a47fa6 --- /dev/null +++ b/packages/vue-cli-plugin-uni/lib/util.js @@ -0,0 +1,17 @@ +function makeMap (str, expectsLowerCase) { + const map = Object.create(null) + const list = str.split(',') + for (let i = 0; i < list.length; i++) { + map[list[i]] = true + } + return expectsLowerCase + ? val => map[val.toLowerCase()] + : val => map[val] +} + +module.exports = { + isUnaryTag: makeMap( + 'image,area,base,br,col,embed,frame,hr,img,input,isindex,keygen,' + + 'link,meta,param,source,track,wbr' + ) +}