diff --git a/packages/uni-cli-shared/lib/index.js b/packages/uni-cli-shared/lib/index.js index cbdc4dbff18e230e959e1ade5d197b0e9f7c3ed8..8fb634f92098a13b57c1dce603713bb26b50df57 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 67af52099d8b744b6d499ebdda6aaaa8a5b61d31..699c4c74c472134e0388544e6416bd48838d3016 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 1d0d04392bd0602dfa9d619e573e000a3c8b967a..49b4193e852af39dd1f0d81a946a2eac7b55cfea 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 } } -} +}