From a17ec656442757edfbf36a9a2985866a94ff9cf4 Mon Sep 17 00:00:00 2001 From: qiang Date: Fri, 8 Nov 2019 20:18:03 +0800 Subject: [PATCH] fix: nvue-native template --- packages/uni-cli-shared/lib/index.js | 60 ++++++------- packages/uni-cli-shared/lib/util.js | 7 +- .../build/webpack.nvue.conf.js | 85 ++++++++++++------- 3 files changed, 88 insertions(+), 64 deletions(-) diff --git a/packages/uni-cli-shared/lib/index.js b/packages/uni-cli-shared/lib/index.js index cbdc4dbff..8fb634f92 100644 --- a/packages/uni-cli-shared/lib/index.js +++ b/packages/uni-cli-shared/lib/index.js @@ -13,7 +13,7 @@ const { } = require('./manifest.js') const { - getMainEntry, + getMainEntry, getNVueMainEntry, parseEntry, parsePages, @@ -28,36 +28,37 @@ const { camelize, hyphenate, removeExt, - normalizePath, + normalizePath, getComponentName, - convertStaticStyle + convertStaticStyle, + getTemplatePath } = require('./util') -const { - getFlexDirection, - getPlatformProject, +const { + getFlexDirection, + getPlatformProject, isSupportSubPackages, - getPlatforms, + getPlatforms, getPlatformGlobal, - getPlatformScss, + getPlatformScss, getPlatformSass, - runByHBuilderX, - isInHBuilderX, + runByHBuilderX, + isInHBuilderX, isInHBuilderXAlpha, getPlatformExts, getPlatformTarget, getPlatformVue, - getPlatformCompiler, + getPlatformCompiler, getShadowCss, - getPlatformCssVars, - getPlatformCssnano, + getPlatformCssVars, + getPlatformCssnano, getShadowTemplate, jsPreprocessOptions, cssPreprocessOptions, htmlPreprocessOptions, - nvueJsPreprocessOptions, + nvueJsPreprocessOptions, nvueCssPreprocessOptions, - nvueHtmlPreprocessOptions, + nvueHtmlPreprocessOptions, devtoolModuleFilenameTemplate } = require('./platform') @@ -75,38 +76,39 @@ module.exports = { parseEntry, parsePages, getH5Options, - getMainEntry, + getMainEntry, getNVueMainEntry, getPagesJson, getManifestJson, getNetworkTimeout, - runByHBuilderX, - isInHBuilderX, - isInHBuilderXAlpha, + runByHBuilderX, + isInHBuilderX, + isInHBuilderXAlpha, isSupportSubPackages, - getPlatforms, + getPlatforms, getFlexDirection, - getPlatformScss, + getPlatformScss, getPlatformSass, getPlatformExts, - getPlatformTarget, + getPlatformTarget, getPlatformProject, - getPlatformVue, - getPlatformGlobal, + getPlatformVue, + getPlatformGlobal, getShadowCss, - getPlatformCssVars, + getPlatformCssVars, getPlatformCssnano, - getPlatformCompiler, + getPlatformCompiler, getShadowTemplate, parsePagesJson, - parseManifestJson, + parseManifestJson, getComponentName, convertStaticStyle, + getTemplatePath, jsPreprocessOptions, cssPreprocessOptions, htmlPreprocessOptions, - nvueJsPreprocessOptions, + nvueJsPreprocessOptions, nvueCssPreprocessOptions, - nvueHtmlPreprocessOptions, + nvueHtmlPreprocessOptions, devtoolModuleFilenameTemplate } diff --git a/packages/uni-cli-shared/lib/util.js b/packages/uni-cli-shared/lib/util.js index 67af52099..699c4c74c 100644 --- a/packages/uni-cli-shared/lib/util.js +++ b/packages/uni-cli-shared/lib/util.js @@ -115,5 +115,8 @@ module.exports = { return str.replace('wx-', 'weixin-') } return str - }) -} + }), + getTemplatePath () { + return path.join(__dirname, '../template') + } +} diff --git a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js index 1d0d04392..49b4193e8 100644 --- a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js +++ b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js @@ -8,7 +8,8 @@ const { getNVueMainEntry, nvueJsPreprocessOptions, nvueHtmlPreprocessOptions, - devtoolModuleFilenameTemplate + devtoolModuleFilenameTemplate, + getTemplatePath } = require('@dcloudio/uni-cli-shared') const WebpackAppPlusNVuePlugin = require('../packages/webpack-app-plus-nvue-plugin') @@ -95,7 +96,7 @@ const rules = [{ babelrc: false } }, - jsPreprocessorLoader + jsPreprocessorLoader ], exclude (modulePath) { return excludeModuleReg.test(modulePath) && modulePath.indexOf('@dcloudio') === -1 @@ -161,38 +162,56 @@ rules.unshift({ if (process.env.UNI_USING_NATIVE) { plugins.push(new WebpackUniMPPlugin()) - - let nativeTemplatePath = path.resolve( - process.env.UNI_HBUILDERX_PLUGINS, - 'weapp-tools/template/v8-native' - ) - - if (!fs.existsSync(nativeTemplatePath)) { // 兼容旧版本 - nativeTemplatePath = path.resolve( - process.env.UNI_HBUILDERX_PLUGINS, - 'weapp-tools/template/v8' - ) - } - - plugins.push(new CopyWebpackPlugin([{ + const array = [{ from: path.resolve(process.env.UNI_INPUT_DIR, 'static'), to: 'static' - }, { - from: nativeTemplatePath, - to: process.env.UNI_OUTPUT_DIR - }, { - from: path.resolve( - process.env.UNI_HBUILDERX_PLUGINS, - 'weapp-tools/template/common' - ), - to: process.env.UNI_OUTPUT_DIR, - ignore: [ - '*.js', - '*.json', - '__uniapppicker.html', - '__uniappview.html' - ] - }])) + }] + if (process.env.UNI_USING_NVUE_COMPILER) { + array.push({ + from: path.resolve(getTemplatePath(), 'common'), + to: process.env.UNI_OUTPUT_DIR + }, { + from: path.resolve( + process.env.UNI_HBUILDERX_PLUGINS, + 'weapp-tools/template/common' + ), + to: process.env.UNI_OUTPUT_DIR, + ignore: [ + '*.js', + '*.json', + '__uniapppicker.html', + '__uniappview.html', + '__uniappmarker@3x.png', + '__uniappopenlocation.html', + '__uniapppicker.html' + ] + }) + } else { + let nativeTemplatePath = path.resolve(process.env.UNI_HBUILDERX_PLUGINS, 'weapp-tools/template/v8-native') + if (!fs.existsSync(nativeTemplatePath)) { // 兼容旧版本 + nativeTemplatePath = path.resolve( + process.env.UNI_HBUILDERX_PLUGINS, + 'weapp-tools/template/v8' + ) + } + array.push({ + from: nativeTemplatePath, + to: process.env.UNI_OUTPUT_DIR + }, { + from: path.resolve( + process.env.UNI_HBUILDERX_PLUGINS, + 'weapp-tools/template/common' + ), + to: process.env.UNI_OUTPUT_DIR, + ignore: [ + '*.js', + '*.json', + '__uniapppicker.html', + '__uniappview.html' + ] + }) + } + plugins.push(new CopyWebpackPlugin(array)) } module.exports = function () { @@ -296,4 +315,4 @@ module.exports = function () { zlib: false } } -} +} -- GitLab