@dcloudio/uni-cli-shared
Advanced tools
Comparing version 0.2.984 to 0.2.985
@@ -29,14 +29,49 @@ const fs = require('fs') | ||
function getNormalCopy (files) { | ||
return files.map(file => { | ||
const from = path.resolve(process.env.UNI_INPUT_DIR, file) | ||
if (fs.existsSync(from)) { | ||
return { | ||
from, | ||
to: path.resolve(process.env.UNI_OUTPUT_DIR, file) | ||
} | ||
function getCopyOption (file, options) { | ||
const from = path.resolve(process.env.UNI_INPUT_DIR, file) | ||
if (fs.existsSync(from)) { | ||
return Object.assign({ | ||
from, | ||
to: path.resolve(process.env.UNI_OUTPUT_DIR, file) | ||
}, options) | ||
} | ||
} | ||
function getCopyOptions (files, options = {}, subPackages = true) { | ||
const copyOptions = [] | ||
files.forEach(file => { | ||
// 主包 | ||
const copyOption = getCopyOption(file, options) | ||
if (copyOption) { | ||
copyOptions.push(copyOption) | ||
} | ||
}).filter(item => item) | ||
if (subPackages) { | ||
// 分包 | ||
Object.keys(process.UNI_SUBPACKAGES).forEach(root => { // 分包静态资源 | ||
const subCopyOption = getCopyOption(path.join(root, file), options) | ||
if (subCopyOption) { | ||
copyOptions.push(subCopyOption) | ||
} | ||
}) | ||
} | ||
}) | ||
return copyOptions | ||
} | ||
function getStaticCopyOptions (assetsDir) { | ||
const ignore = [] | ||
Object.keys(PLATFORMS).forEach(platform => { | ||
if (process.env.UNI_PLATFORM !== platform) { | ||
ignore.push(platform + '/**/*') | ||
} | ||
}) | ||
return getCopyOptions( | ||
[assetsDir], { | ||
ignore | ||
} | ||
) | ||
} | ||
const PLATFORMS = { | ||
@@ -53,13 +88,19 @@ 'h5': { | ||
}, | ||
copyWebpackOptions (assetsDir) { | ||
return [{ | ||
from: require.resolve('@dcloudio/uni-h5/dist/index.css'), | ||
to: assetsDir, | ||
transform (content) { | ||
if (process.env.NODE_ENV === 'production') { | ||
return content + getShadowCss() | ||
copyWebpackOptions ({ | ||
assetsDir | ||
}) { | ||
return [ | ||
...getStaticCopyOptions(assetsDir), | ||
{ | ||
from: require.resolve('@dcloudio/uni-h5/dist/index.css'), | ||
to: assetsDir, | ||
transform (content) { | ||
if (process.env.NODE_ENV === 'production') { | ||
return content + getShadowCss() | ||
} | ||
return content | ||
} | ||
return content | ||
} | ||
}, ...getNormalCopy(['hybrid/html'])] | ||
}, | ||
...getCopyOptions(['hybrid/html']) | ||
] | ||
} | ||
@@ -81,8 +122,13 @@ }, | ||
}, | ||
copyWebpackOptions (assetsDir) { | ||
const options = [...getNormalCopy(['hybrid/html'])] | ||
copyWebpackOptions ({ | ||
assetsDir | ||
}) { | ||
const files = ['hybrid/html'] | ||
if (!process.env.UNI_USING_NATIVE) { | ||
options.push(...getNormalCopy(['wxcomponents'])) | ||
files.push('wxcomponents') | ||
} | ||
return options | ||
return [ | ||
...getStaticCopyOptions(assetsDir), | ||
...getCopyOptions(files) | ||
] | ||
} | ||
@@ -106,4 +152,9 @@ }, | ||
project: 'project.config.json', | ||
copyWebpackOptions (assetsDir) { | ||
return getNormalCopy(['wxcomponents']) | ||
copyWebpackOptions ({ | ||
assetsDir | ||
}) { | ||
return [ | ||
...getStaticCopyOptions(assetsDir), | ||
...getCopyOptions(['wxcomponents']) | ||
] | ||
} | ||
@@ -127,8 +178,10 @@ }, | ||
project: 'project.config.json', | ||
copyWebpackOptions (assetsDir, manifestPlatformOptions) { | ||
copyWebpackOptions ({ | ||
assetsDir, | ||
manifestPlatformOptions | ||
}) { | ||
const files = [ | ||
'sitemap.json', | ||
'ext.json', | ||
'custom-tab-bar', | ||
'wxcomponents' | ||
'custom-tab-bar' | ||
] | ||
@@ -138,3 +191,7 @@ if (manifestPlatformOptions.workers) { | ||
} | ||
return getNormalCopy(files) | ||
return [ | ||
...getStaticCopyOptions(assetsDir), | ||
...getCopyOptions(['wxcomponents']), | ||
...getCopyOptions(files, {}, false) | ||
] | ||
} | ||
@@ -158,4 +215,9 @@ }, | ||
project: 'project.swan.json', | ||
copyWebpackOptions (assetsDir) { | ||
return getNormalCopy(['swancomponents']) | ||
copyWebpackOptions ({ | ||
assetsDir | ||
}) { | ||
return [ | ||
...getStaticCopyOptions(assetsDir), | ||
...getCopyOptions(['swancomponents']) | ||
] | ||
} | ||
@@ -178,4 +240,9 @@ }, | ||
}, | ||
copyWebpackOptions (assetsDir) { | ||
return getNormalCopy(['mycomponents']) | ||
copyWebpackOptions ({ | ||
assetsDir | ||
}) { | ||
return [ | ||
...getStaticCopyOptions(assetsDir), | ||
...getCopyOptions(['mycomponents']) | ||
] | ||
} | ||
@@ -199,4 +266,9 @@ }, | ||
project: 'project.tt.json', | ||
copyWebpackOptions (assetsDir) { | ||
return getNormalCopy(['ttcomponents']) | ||
copyWebpackOptions ({ | ||
assetsDir | ||
}) { | ||
return [ | ||
...getStaticCopyOptions(assetsDir), | ||
...getCopyOptions(['ttcomponents']) | ||
] | ||
} | ||
@@ -203,0 +275,0 @@ } |
{ | ||
"name": "@dcloudio/uni-cli-shared", | ||
"version": "0.2.984", | ||
"version": "0.2.985", | ||
"description": "uni-cli-shared", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
51993
1379
50