提交 b381a51d 编写于 作者: Q qiang

fix: support copy-webpack-plugin version 6+

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