From f8e1cc20a49aa11a2cda87084c8af747b589de70 Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Fri, 10 Jan 2020 21:29:37 +0800 Subject: [PATCH] fix(h5): easycom with tree shaking --- packages/uni-template-compiler/lib/index.js | 10 ++++++++-- .../packages/vue-loader/lib/index.js | 7 ++++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/packages/uni-template-compiler/lib/index.js b/packages/uni-template-compiler/lib/index.js index 9c4f61d62..904536958 100644 --- a/packages/uni-template-compiler/lib/index.js +++ b/packages/uni-template-compiler/lib/index.js @@ -35,7 +35,13 @@ const { module.exports = { compile (source, options = {}) { - (options.modules || (options.modules = [])).push(autoComponentsModule) + if ( // 启用摇树优化后,需要过滤内置组件 + !options.autoComponentResourcePath || + options.autoComponentResourcePath.indexOf('@dcloudio/uni-h5/src') === -1 + ) { + (options.modules || (options.modules = [])).push(autoComponentsModule) + } + options.isUnaryTag = isUnaryTag // 将 autoComponents 挂在 isUnaryTag 上边 options.isUnaryTag.autoComponents = new Set() @@ -257,4 +263,4 @@ at ${resourcePath}.vue:1`) ssrCompile, ssrCompileToFunctions, generateCodeFrame -} +} diff --git a/packages/vue-cli-plugin-uni/packages/vue-loader/lib/index.js b/packages/vue-cli-plugin-uni/packages/vue-loader/lib/index.js index 46a938e2c..52e5f4118 100644 --- a/packages/vue-cli-plugin-uni/packages/vue-loader/lib/index.js +++ b/packages/vue-cli-plugin-uni/packages/vue-loader/lib/index.js @@ -77,8 +77,13 @@ module.exports = function (source) { if (options.isH5TreeShaking) { // 摇树优化逻辑(框架组件移除样式,禁用 modules) const isWin = /^win/.test(process.platform) - const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path) + + if(options.compilerOptions){ + options.compilerOptions = {} + } + options.compilerOptions.autoComponentResourcePath = normalizePath(resourcePath) + // fixed by xxxxxx if(!modules && options.compilerOptions && options.compilerOptions.modules){ modules = options.compilerOptions.modules -- GitLab