diff --git a/lib/h5/uni.config.js b/lib/h5/uni.config.js index 60be35d01b94deb343aafabbe21646af88cc27ee..0c1125fa0925bc0f907fe326b8e66b2af7372248 100644 --- a/lib/h5/uni.config.js +++ b/lib/h5/uni.config.js @@ -19,12 +19,13 @@ function transform(content) { } function getIndexCssPath(assetsDir, template) { + const CopyWebpackPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0]) const VUE_APP_INDEX_CSS_HASH = process.env.VUE_APP_INDEX_CSS_HASH if (VUE_APP_INDEX_CSS_HASH) { try { const templateContent = fs.readFileSync(getTemplatePath(template)) if (/\bVUE_APP_INDEX_CSS_HASH\b/.test(templateContent)) { - return path.join(assetsDir, `[name].${VUE_APP_INDEX_CSS_HASH}.[ext]`) + return path.join(assetsDir, `[name].${VUE_APP_INDEX_CSS_HASH}${CopyWebpackPluginVersion > 5 ? '' : '.'}[ext]`) } } catch (e) {} } diff --git a/packages/uni-app-plus/lib/uni.config.js b/packages/uni-app-plus/lib/uni.config.js index 2241958b9442940c5d5e77ea0d4932b7abbb5ba9..2434bb6a90c5a7c34a0b006a92dea2c8f9ee83d3 100644 --- a/packages/uni-app-plus/lib/uni.config.js +++ b/packages/uni-app-plus/lib/uni.config.js @@ -6,12 +6,17 @@ const COMPONENTS_DIR_NAME = 'wxcomponents' function getComponentsCopyOption () { if (process.env.UNI_OUTPUT_TMP_DIR) { // TODO v3不需要,即将废弃 const componentsDir = path.resolve(process.env.UNI_INPUT_DIR, COMPONENTS_DIR_NAME) + const CopyWebpackPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0]) if (fs.existsSync(componentsDir)) { - return { + const ignore = ['**/*.vue', '**/*.css'] + return Object.assign({ from: componentsDir, - to: COMPONENTS_DIR_NAME, - ignore: ['**/*.vue', '**/*.css'] - } + to: COMPONENTS_DIR_NAME + }, CopyWebpackPluginVersion > 5 ? { + globOptions: { ignore } + } : { + ignore + }) } } } diff --git a/packages/uni-mp-qq/lib/uni.config.js b/packages/uni-mp-qq/lib/uni.config.js index 96bbb194af1b21d0dad4bc757664fca4617dcea9..4d721528526e9e925d5cb37f97ebf13f15d4af0f 100644 --- a/packages/uni-mp-qq/lib/uni.config.js +++ b/packages/uni-mp-qq/lib/uni.config.js @@ -22,6 +22,7 @@ module.exports = { subPackages: true }, copyWebpackOptions (platformOptions, vueOptions) { + const CopyWebpackPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0]) const copyOptions = [ // 'sitemap.json', // 'ext.json', @@ -31,21 +32,29 @@ module.exports = { workers && copyOptions.push(workers) const wxcomponentsDir = path.resolve(process.env.UNI_INPUT_DIR, COMPONENTS_DIR_NAME) + const ignore = ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤 + if (fs.existsSync(wxcomponentsDir)) { - copyOptions.push({ + copyOptions.push(Object.assign({ from: wxcomponentsDir, - to: COMPONENTS_DIR_NAME, - ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤 - }) + to: COMPONENTS_DIR_NAME + }, CopyWebpackPluginVersion > 5 ? { + globOptions: { ignore } + } : { + ignore + })) } global.uniModules.forEach(module => { const wxcomponentsDir = path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', module, COMPONENTS_DIR_NAME) if (fs.existsSync(wxcomponentsDir)) { - copyOptions.push({ + copyOptions.push(Object.assign({ from: wxcomponentsDir, - to: 'uni_modules/' + module + '/' + COMPONENTS_DIR_NAME, - ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤 - }) + to: 'uni_modules/' + module + '/' + COMPONENTS_DIR_NAME + }, CopyWebpackPluginVersion > 5 ? { + globOptions: { ignore } + } : { + ignore + })) } }) return copyOptions diff --git a/packages/uni-mp-weixin/lib/uni.config.js b/packages/uni-mp-weixin/lib/uni.config.js index 562d4ccf4febe843cf3453b115b04a57a8e64b04..3c5b09c64225d241aaa619414a24e49824dc3470 100644 --- a/packages/uni-mp-weixin/lib/uni.config.js +++ b/packages/uni-mp-weixin/lib/uni.config.js @@ -24,12 +24,13 @@ module.exports = { darkmode: true }, copyWebpackOptions (platformOptions, vueOptions) { + const CopyWebpackPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0]) const copyOptions = [ 'theme.json', 'sitemap.json', 'ext.json', 'custom-tab-bar', - 'functional-pages', + 'functional-pages', 'project.private.config.json' ] @@ -46,25 +47,32 @@ module.exports = { const manifestConfig = process.UNI_MANIFEST const weixinConfig = manifestConfig['mp-weixin'] || {} const copyWxComponentsOnDemandSwitch = !!weixinConfig.copyWxComponentsOnDemand // 默认值false + const ignore = ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤 if (!copyWxComponentsOnDemandSwitch) { const wxcomponentsDir = path.resolve(process.env.UNI_INPUT_DIR, COMPONENTS_DIR_NAME) if (fs.existsSync(wxcomponentsDir)) { - copyOptions.push({ + copyOptions.push(Object.assign({ from: wxcomponentsDir, - to: COMPONENTS_DIR_NAME, - ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤 - }) + to: COMPONENTS_DIR_NAME + }, CopyWebpackPluginVersion > 5 ? { + globOptions: { ignore } + } : { + ignore + })) } } global.uniModules.forEach(module => { const wxcomponentsDir = path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', module, COMPONENTS_DIR_NAME) if (fs.existsSync(wxcomponentsDir)) { - copyOptions.push({ + copyOptions.push(Object.assign({ from: wxcomponentsDir, - to: 'uni_modules/' + module + '/' + COMPONENTS_DIR_NAME, - ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤 - }) + to: 'uni_modules/' + module + '/' + COMPONENTS_DIR_NAME + }, CopyWebpackPluginVersion > 5 ? { + globOptions: { ignore } + } : { + ignore + })) } }) return copyOptions diff --git a/packages/uni-quickapp-native/lib/configure-webpack.js b/packages/uni-quickapp-native/lib/configure-webpack.js index d6d5cc4df3b4a32ab0e7374ce8be462716b2b7fd..813c6a5d38b615e87af27effe58795012f55162f 100644 --- a/packages/uni-quickapp-native/lib/configure-webpack.js +++ b/packages/uni-quickapp-native/lib/configure-webpack.js @@ -2,6 +2,7 @@ const path = require('path') const webpack = require('webpack') const CopyPlugin = require('copy-webpack-plugin') +const CopyPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0]) const HandlerPlugin = require('@hap-toolkit/packager/lib/plugin/handler-plugin') const ZipPlugin = require('@hap-toolkit/packager/lib/plugin/zip-plugin') @@ -39,6 +40,11 @@ function genPriorities (entryPagePath) { const uniCloudPath = require.resolve('@dcloudio/vue-cli-plugin-uni/packages/uni-cloud/dist/index.js') +const patterns = [{ + from: path.resolve(__dirname, '../dist/' + dslFilename), + to: 'dsl.js' +}] + module.exports = { devtool: false, entry () { @@ -77,10 +83,7 @@ module.exports = { new webpack.ProvidePlugin({ uniCloud: [uniCloudPath, 'default'] }), - new CopyPlugin([{ - from: path.resolve(__dirname, '../dist/' + dslFilename), - to: 'dsl.js' - }]), + new CopyPlugin(CopyPluginVersion > 5 ? { patterns } : patterns), new HandlerPlugin({}), new Css2jsonPlugin(), new InstVuePlugin(), @@ -101,4 +104,4 @@ module.exports = { }), new NotifyPlugin() ] -} +} 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 df8c7627c81f03d1a8833baea482003775b3e746..d6d01474d2f9975f521874ca52f39f025baee1a1 100644 --- a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js +++ b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js @@ -3,6 +3,7 @@ const path = require('path') const webpack = require('webpack') const VueLoaderPlugin = require('@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/plugin') const CopyWebpackPlugin = require('copy-webpack-plugin') +const CopyWebpackPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0]) const TerserPlugin = require('terser-webpack-plugin') const { @@ -194,7 +195,7 @@ rules.unshift({ if (process.env.UNI_USING_V3_NATIVE) { try { const automatorJson = require.resolve('@dcloudio/uni-automator/dist/automator.json') - plugins.push(new CopyWebpackPlugin([{ + const patterns = [{ from: automatorJson, to: '../.automator/' + (process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM) + '/.automator.json', @@ -207,7 +208,8 @@ if (process.env.UNI_USING_V3_NATIVE) { } return '' } - }])) + }] + plugins.push(new CopyWebpackPlugin(CopyWebpackPluginVersion > 5 ? { patterns } : patterns)) } catch (e) { } } @@ -215,7 +217,7 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { plugins.push(new WebpackUniMPPlugin()) const assetsDir = 'static' const hybridDir = 'hybrid/html' - const array = [{ + const patterns = [{ from: path.resolve(process.env.UNI_INPUT_DIR, assetsDir), to: assetsDir }] @@ -223,7 +225,7 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { if (!process.env.UNI_AUTOMATOR_WS_ENDPOINT) { const androidPrivacyPath = path.resolve(process.env.UNI_INPUT_DIR, 'androidPrivacy.json') if (fs.existsSync(androidPrivacyPath)) { - array.push({ + patterns.push({ from: androidPrivacyPath, to: 'androidPrivacy.json' }) @@ -231,7 +233,7 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { } const hybridHtmlPath = path.resolve(process.env.UNI_INPUT_DIR, hybridDir) if (fs.existsSync(hybridHtmlPath)) { - array.push({ + patterns.push({ from: hybridHtmlPath, to: hybridDir }) @@ -242,7 +244,7 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { const assets = modules + module + '/' + assetsDir const assetsPath = path.resolve(process.env.UNI_INPUT_DIR, assets) if (fs.existsSync(assetsPath)) { - array.push({ + patterns.push({ from: assetsPath, to: assets }) @@ -250,7 +252,7 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { const hybridHtml = modules + module + '/' + hybridDir const hybridHtmlPath = path.resolve(process.env.UNI_INPUT_DIR, hybridHtml) if (fs.existsSync(hybridHtmlPath)) { - array.push({ + patterns.push({ from: hybridHtmlPath, to: hybridHtml }) @@ -258,12 +260,12 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { }) if (process.env.UNI_USING_NVUE_COMPILER) { - array.push({ + patterns.push({ from: path.resolve(getTemplatePath(), 'common'), to: process.env.UNI_OUTPUT_DIR }) } else if (process.env.UNI_USING_V3_NATIVE) { - array.push({ + patterns.push({ from: path.resolve(getTemplatePath(), 'weex'), to: process.env.UNI_OUTPUT_DIR }) @@ -275,7 +277,7 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { 'weapp-tools/template/v8' ) } - array.push({ + patterns.push({ from: nativeTemplatePath, to: process.env.UNI_OUTPUT_DIR }, { @@ -284,15 +286,17 @@ if (process.env.UNI_USING_NATIVE || process.env.UNI_USING_V3_NATIVE) { 'weapp-tools/template/common' ), to: process.env.UNI_OUTPUT_DIR, - ignore: [ - '*.js', - '*.json', - '__uniapppicker.html', - '__uniappview.html' - ] + globOptions: { + ignore: [ + '*.js', + '*.json', + '__uniapppicker.html', + '__uniappview.html' + ] + } }) } - plugins.push(new CopyWebpackPlugin(array)) + plugins.push(new CopyWebpackPlugin(CopyWebpackPluginVersion > 5 ? { patterns } : patterns)) } try { diff --git a/packages/vue-cli-plugin-hbuilderx/packages/webpack-app-plus-nvue-plugin/index.js b/packages/vue-cli-plugin-hbuilderx/packages/webpack-app-plus-nvue-plugin/index.js index c907cad89c8c60d6006f6325f827d17e5f587325..03f0f003296b14bacffe48d7a59e38fabf4ad7f5 100644 --- a/packages/vue-cli-plugin-hbuilderx/packages/webpack-app-plus-nvue-plugin/index.js +++ b/packages/vue-cli-plugin-hbuilderx/packages/webpack-app-plus-nvue-plugin/index.js @@ -14,13 +14,10 @@ class WebpackAppPlusNVuePlugin { const changedFiles = [] compiler.hooks.emit.tapAsync('webpack-uni-nvue', (compilation, callback) => { changedFiles.length = 0 - const changedChunks = compilation.chunks.filter(chunk => { + compilation.chunks.forEach(chunk => { const oldVersion = chunkVersions[chunk.name] chunkVersions[chunk.name] = chunk.hash - return chunk.hash !== oldVersion - }) - changedChunks.map(chunk => { - if (Array.isArray(chunk.files)) { + if (chunk.hash !== oldVersion && Array.isArray(chunk.files)) { chunk.files.forEach(file => { !changedFiles.includes(file) && (changedFiles.push(file)) }) diff --git a/packages/vue-cli-plugin-hbuilderx/packages/webpack-app-plus-plugin/index.js b/packages/vue-cli-plugin-hbuilderx/packages/webpack-app-plus-plugin/index.js index b99f48b934c87679d015baea5f11a9328dfb3840..d004f0818404e2fcdc70c749dd7be4312d263e3a 100644 --- a/packages/vue-cli-plugin-hbuilderx/packages/webpack-app-plus-plugin/index.js +++ b/packages/vue-cli-plugin-hbuilderx/packages/webpack-app-plus-plugin/index.js @@ -44,13 +44,10 @@ class WebpackAppPlusPlugin { }) compiler.hooks.emit.tapAsync('WebpackAppPlusPlugin', (compilation, callback) => { - const changedChunks = compilation.chunks.filter(chunk => { + compilation.chunks.forEach(chunk => { const oldVersion = chunkVersions[chunk.name] chunkVersions[chunk.name] = chunk.hash - return chunk.hash !== oldVersion - }) - changedChunks.map(chunk => { - if (Array.isArray(chunk.files)) { + if (chunk.hash !== oldVersion && Array.isArray(chunk.files)) { chunk.files.forEach(file => { if (isAppService) { !serviceChangedFiles.includes(file) && (serviceChangedFiles.push(file)) diff --git a/packages/vue-cli-plugin-uni/lib/configure-webpack.js b/packages/vue-cli-plugin-uni/lib/configure-webpack.js index 9ddf81b1ec0202feecc664df9443a7c45c003104..f5e0784ba6691edecb7ae76eb3620aa95d00542d 100644 --- a/packages/vue-cli-plugin-uni/lib/configure-webpack.js +++ b/packages/vue-cli-plugin-uni/lib/configure-webpack.js @@ -2,6 +2,7 @@ const fs = require('fs') const path = require('path') const webpack = require('webpack') const CopyWebpackPlugin = require('copy-webpack-plugin') +const CopyWebpackPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0]) const merge = require('webpack-merge') @@ -231,12 +232,13 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt vueOptions.pluginOptions['uni-app-plus'].view if (!isAppView) { // app-plus view不需要copy - plugins.push(new CopyWebpackPlugin(getCopyWebpackPluginOptions(manifestPlatformOptions, vueOptions))) + const patterns = getCopyWebpackPluginOptions(manifestPlatformOptions, vueOptions) + plugins.push(new CopyWebpackPlugin(CopyWebpackPluginVersion > 5 ? { patterns } : patterns)) } if (!process.env.UNI_SUBPACKGE || !process.env.UNI_MP_PLUGIN) { try { const automatorJson = require.resolve('@dcloudio/uni-automator/dist/automator.json') - plugins.push(new CopyWebpackPlugin([{ + const patterns = [{ from: automatorJson, to: '../.automator/' + (process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM) + '/.automator.json', @@ -249,8 +251,9 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt } return '' } - }])) - } catch (e) {} + }] + plugins.push(new CopyWebpackPlugin(CopyWebpackPluginVersion > 5 ? { patterns } : patterns)) + } catch (e) { } } if (process.UNI_SCRIPT_ENV && Object.keys(process.UNI_SCRIPT_ENV).length) { diff --git a/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js b/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js index a38ce5e5ae42b482faa02e1bd378c042a423a6d7..577f799ef0c02f3623934cfcabc475078e810dfd 100644 --- a/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js +++ b/packages/vue-cli-plugin-uni/lib/copy-webpack-options.js @@ -7,6 +7,7 @@ const { initI18nOptions } = require('@dcloudio/uni-cli-shared/lib/i18n') const assetsDir = 'static' +const CopyWebpackPluginVersion = Number(require('copy-webpack-plugin/package.json').version.split('.')[0]) function getAssetsCopyOption (from, options = {}) { if (path.isAbsolute(from)) { @@ -42,7 +43,9 @@ function getAssetsCopyOptions (assetsDir) { const copyOptions = [] // 主包静态资源 - const mainAssetsCopyOption = getAssetsCopyOption(assetsDir, { + const mainAssetsCopyOption = getAssetsCopyOption(assetsDir, CopyWebpackPluginVersion > 5 ? { + globOptions: { ignore } + } : { ignore }) if (mainAssetsCopyOption) { @@ -51,11 +54,11 @@ function getAssetsCopyOptions (assetsDir) { // 分包静态资源 process.UNI_SUBPACKAGES && Object.keys(process.UNI_SUBPACKAGES).forEach(root => { - const subAssetsCopyOption = getAssetsCopyOption( - path.join(root, assetsDir), { - ignore - } - ) + const subAssetsCopyOption = getAssetsCopyOption(path.join(root, assetsDir), CopyWebpackPluginVersion > 5 ? { + globOptions: { ignore } + } : { + ignore + }) if (subAssetsCopyOption) { copyOptions.push(subAssetsCopyOption) } @@ -91,7 +94,8 @@ function getCopyWebpackPluginOptions (platformOptions, vueOptions) { if (process.env.UNI_PLATFORM === 'app-plus' && !process.env.UNI_AUTOMATOR_WS_ENDPOINT) { copyOptions.push({ from: path.resolve(process.env.UNI_INPUT_DIR, 'android*.json'), - to: '[name].[ext]', + to: `[name]${CopyWebpackPluginVersion > 5 ? '' : '.'}[ext]`, + noErrorOnMissing: true, globOptions: { ignored: require('./util').getWatchOptions().ignored }, diff --git a/packages/vue-cli-plugin-uni/package.json b/packages/vue-cli-plugin-uni/package.json index 7566b66e1837038a81e8fd21c1e8c51b994333f5..09917c2d8aa6e70387c9f70f441f54222ae0c328 100644 --- a/packages/vue-cli-plugin-uni/package.json +++ b/packages/vue-cli-plugin-uni/package.json @@ -20,7 +20,6 @@ "@dcloudio/uni-stat": "^2.0.0-32920211029001", "buffer-json": "^2.0.0", "clone-deep": "^4.0.1", - "copy-webpack-plugin": "^5.1.1", "cross-env": "^5.2.0", "envinfo": "^6.0.1", "hash-sum": "^1.0.2", @@ -39,6 +38,7 @@ "xregexp": "4.0.0" }, "peerDependencies": { + "copy-webpack-plugin": ">=5", "postcss": ">=7" }, "gitHead": "9e2d0f8e244724fcd64880316c57d837d1778cf8"