提交 829df827 编写于 作者: fxy060608's avatar fxy060608

feat(cli): copy assets (uni_modules)

上级 1d3a6119
const fs = require('fs') const fs = require('fs')
const path = require('path') const path = require('path')
function getTemplatePath (template) { function getTemplatePath(template) {
if (template) { if (template) {
const userTemplate = path.resolve(process.env.UNI_INPUT_DIR, template) const userTemplate = path.resolve(process.env.UNI_INPUT_DIR, template)
if (fs.existsSync(userTemplate)) if (fs.existsSync(userTemplate))
...@@ -40,12 +40,16 @@ module.exports = { ...@@ -40,12 +40,16 @@ module.exports = {
vue: '@dcloudio/vue-cli-plugin-uni/packages/h5-vue' vue: '@dcloudio/vue-cli-plugin-uni/packages/h5-vue'
}, },
copyWebpackOptions(platformOptions, vueOptions) { copyWebpackOptions(platformOptions, vueOptions) {
return [{ const copyOptions = [{
from: require.resolve('@dcloudio/uni-h5/dist/index.css'), from: require.resolve('@dcloudio/uni-h5/dist/index.css'),
to: getIndexCssPath(vueOptions.assetsDir, platformOptions.template), to: getIndexCssPath(vueOptions.assetsDir, platformOptions.template),
transform transform
}, },
'hybrid/html' 'hybrid/html'
] ]
global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/hybrid/html')
})
return copyOptions
} }
} }
...@@ -33,6 +33,9 @@ module.exports = { ...@@ -33,6 +33,9 @@ module.exports = {
copyOptions.push(componentsCopyOption) copyOptions.push(componentsCopyOption)
} }
copyOptions.push('hybrid/html') copyOptions.push('hybrid/html')
global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/hybrid/html')
})
if (process.env.UNI_USING_V3) { // TODO 将仅保留v3逻辑 if (process.env.UNI_USING_V3) { // TODO 将仅保留v3逻辑
copyOptions.push(path.resolve(__dirname, '../dist/view.css')) copyOptions.push(path.resolve(__dirname, '../dist/view.css'))
copyOptions.push(path.resolve(__dirname, '../dist/view.umd.min.js')) copyOptions.push(path.resolve(__dirname, '../dist/view.umd.min.js'))
......
...@@ -4,8 +4,8 @@ module.exports = { ...@@ -4,8 +4,8 @@ module.exports = {
cssVars: { cssVars: {
'--status-bar-height': '25px', '--status-bar-height': '25px',
'--window-top': '0px', '--window-top': '0px',
'--window-bottom': '0px', '--window-bottom': '0px',
'--window-left': '0px', '--window-left': '0px',
'--window-right': '0px' '--window-right': '0px'
}, },
extnames: { extnames: {
...@@ -17,6 +17,10 @@ module.exports = { ...@@ -17,6 +17,10 @@ module.exports = {
subPackages: true subPackages: true
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
return ['mycomponents'] const copyOptions = ['mycomponents']
global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/mycomponents')
})
return copyOptions
} }
} }
...@@ -3,8 +3,8 @@ module.exports = { ...@@ -3,8 +3,8 @@ module.exports = {
cssVars: { cssVars: {
'--status-bar-height': '25px', '--status-bar-height': '25px',
'--window-top': '0px', '--window-top': '0px',
'--window-bottom': '0px', '--window-bottom': '0px',
'--window-left': '0px', '--window-left': '0px',
'--window-right': '0px' '--window-right': '0px'
}, },
extnames: { extnames: {
...@@ -17,6 +17,10 @@ module.exports = { ...@@ -17,6 +17,10 @@ module.exports = {
subPackages: true subPackages: true
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
return ['swancomponents'] const copyOptions = ['swancomponents']
global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/swancomponents')
})
return copyOptions
} }
} }
...@@ -3,8 +3,8 @@ module.exports = { ...@@ -3,8 +3,8 @@ module.exports = {
cssVars: { cssVars: {
'--status-bar-height': '25px', '--status-bar-height': '25px',
'--window-top': '0px', '--window-top': '0px',
'--window-bottom': '0px', '--window-bottom': '0px',
'--window-left': '0px', '--window-left': '0px',
'--window-right': '0px' '--window-right': '0px'
}, },
extnames: { extnames: {
...@@ -14,6 +14,10 @@ module.exports = { ...@@ -14,6 +14,10 @@ module.exports = {
project: 'project.ks.json' project: 'project.ks.json'
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
return ['kscomponents'] const copyOptions = ['kscomponents']
global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/kscomponents')
})
return copyOptions
} }
} }
...@@ -8,8 +8,8 @@ module.exports = { ...@@ -8,8 +8,8 @@ module.exports = {
cssVars: { cssVars: {
'--status-bar-height': '25px', '--status-bar-height': '25px',
'--window-top': '0px', '--window-top': '0px',
'--window-bottom': '0px', '--window-bottom': '0px',
'--window-left': '0px', '--window-left': '0px',
'--window-right': '0px' '--window-right': '0px'
}, },
extnames: { extnames: {
...@@ -38,6 +38,16 @@ module.exports = { ...@@ -38,6 +38,16 @@ module.exports = {
ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤 ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤
}) })
} }
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({
from: wxcomponentsDir,
to: 'uni_modules/' + module + '/' + COMPONENTS_DIR_NAME,
ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤
})
}
})
return copyOptions return copyOptions
} }
} }
...@@ -3,8 +3,8 @@ module.exports = { ...@@ -3,8 +3,8 @@ module.exports = {
cssVars: { cssVars: {
'--status-bar-height': '25px', '--status-bar-height': '25px',
'--window-top': '0px', '--window-top': '0px',
'--window-bottom': '0px', '--window-bottom': '0px',
'--window-left': '0px', '--window-left': '0px',
'--window-right': '0px' '--window-right': '0px'
}, },
extnames: { extnames: {
...@@ -14,6 +14,10 @@ module.exports = { ...@@ -14,6 +14,10 @@ module.exports = {
project: 'project.tt.json' project: 'project.tt.json'
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
return ['ttcomponents'] const copyOptions = ['ttcomponents']
global.uniModules.forEach(module => {
copyOptions.push('uni_modules/' + module + '/ttcomponents')
})
return copyOptions
} }
} }
...@@ -8,8 +8,8 @@ module.exports = { ...@@ -8,8 +8,8 @@ module.exports = {
cssVars: { cssVars: {
'--status-bar-height': '25px', '--status-bar-height': '25px',
'--window-top': '0px', '--window-top': '0px',
'--window-bottom': '0px', '--window-bottom': '0px',
'--window-left': '0px', '--window-left': '0px',
'--window-right': '0px' '--window-right': '0px'
}, },
extnames: { extnames: {
...@@ -23,7 +23,7 @@ module.exports = { ...@@ -23,7 +23,7 @@ module.exports = {
darkmode: true darkmode: true
}, },
copyWebpackOptions (platformOptions, vueOptions) { copyWebpackOptions (platformOptions, vueOptions) {
const copyOptions = [ const copyOptions = [
'theme.json', 'theme.json',
'sitemap.json', 'sitemap.json',
'ext.json', 'ext.json',
...@@ -40,6 +40,16 @@ module.exports = { ...@@ -40,6 +40,16 @@ module.exports = {
ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤 ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤
}) })
} }
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({
from: wxcomponentsDir,
to: 'uni_modules/' + module + '/' + COMPONENTS_DIR_NAME,
ignore: ['**/*.vue', '**/*.css'] // v3 会自动转换生成vue,css文件,需要过滤
})
}
})
return copyOptions return copyOptions
} }
} }
...@@ -51,8 +51,16 @@ function getAssetsCopyOptions (assetsDir) { ...@@ -51,8 +51,16 @@ function getAssetsCopyOptions (assetsDir) {
return copyOptions return copyOptions
} }
function getUniModulesAssetsCopyOptions (assetsDir) {
const copyOptions = []
global.uniModules.forEach(module => {
copyOptions.push(...getAssetsCopyOptions('uni_modules/' + module + '/' + assetsDir))
})
return copyOptions
}
function getCopyWebpackPluginOptions (platformOptions, vueOptions) { function getCopyWebpackPluginOptions (platformOptions, vueOptions) {
const copyOptions = getAssetsCopyOptions(assetsDir) const copyOptions = getAssetsCopyOptions(assetsDir).concat(getUniModulesAssetsCopyOptions(assetsDir))
global.uniPlugin.copyWebpackOptions.forEach(copyWebpackOptions => { global.uniPlugin.copyWebpackOptions.forEach(copyWebpackOptions => {
const platformCopyOptions = copyWebpackOptions(platformOptions, vueOptions, copyOptions) || [] const platformCopyOptions = copyWebpackOptions(platformOptions, vueOptions, copyOptions) || []
platformCopyOptions.forEach(copyOption => { platformCopyOptions.forEach(copyOption => {
......
...@@ -19,6 +19,7 @@ process.env.UNI_INPUT_DIR = process.env.UNI_INPUT_DIR || path.resolve(process.cw ...@@ -19,6 +19,7 @@ process.env.UNI_INPUT_DIR = process.env.UNI_INPUT_DIR || path.resolve(process.cw
// 初始化全局插件对象 // 初始化全局插件对象
global.uniPlugin = require('@dcloudio/uni-cli-shared/lib/plugin').init() global.uniPlugin = require('@dcloudio/uni-cli-shared/lib/plugin').init()
const manifestJsonObj = require('@dcloudio/uni-cli-shared/lib/manifest').getManifestJson() const manifestJsonObj = require('@dcloudio/uni-cli-shared/lib/manifest').getManifestJson()
const platformOptions = manifestJsonObj[process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM] || {} const platformOptions = manifestJsonObj[process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM] || {}
// 插件校验环境 // 插件校验环境
...@@ -103,6 +104,17 @@ if (process.env.NODE_ENV === 'production') { // 发行模式,不启用 cache ...@@ -103,6 +104,17 @@ if (process.env.NODE_ENV === 'production') { // 发行模式,不启用 cache
delete process.env.UNI_USING_CACHE delete process.env.UNI_USING_CACHE
} }
global.uniModules = []
try {
global.uniModules = fs
.readdirSync(path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules'))
.filter(module =>
fs.existsSync(
path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules', module, 'package.json')
)
)
} catch (e) {}
const { const {
normalizePath, normalizePath,
isSupportSubPackages, isSupportSubPackages,
......
...@@ -22,12 +22,8 @@ function normalizeUniModulesPagesJson (pagesJson, pluginId) { ...@@ -22,12 +22,8 @@ function normalizeUniModulesPagesJson (pagesJson, pluginId) {
module.exports = function parsePages (content) { module.exports = function parsePages (content) {
const uniModulesDir = path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules') const uniModulesDir = path.resolve(process.env.UNI_INPUT_DIR, 'uni_modules')
let plugins = []
try {
plugins = fs.readdirSync(uniModulesDir)
} catch (e) {}
const pluginPagesJsons = [] const pluginPagesJsons = []
plugins.forEach(plugin => { global.uniModules.forEach(plugin => {
const pagesJsonPath = path.resolve(uniModulesDir, plugin, 'pages.json') const pagesJsonPath = path.resolve(uniModulesDir, plugin, 'pages.json')
if (fs.existsSync(pagesJsonPath)) { if (fs.existsSync(pagesJsonPath)) {
pluginPagesJsons.push( pluginPagesJsons.push(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册