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

chore(cli): add build:plugin

上级 398690aa
......@@ -3,4 +3,5 @@ src/platforms/app-plus-nvue/runtime
build/rollup-plugin-require-context
packages/*/packages
packages/*/template/**/*
qh-api.js
packages/uni-h5/src
packages/uni-stat
const path = require('path')
const del = require('del')
const {
error
} = require('@vue/cli-shared-utils')
const Service = require('@vue/cli-service')
const vueConfig = require('./vue.config.js')
const extendsApiPath = path.resolve(__dirname, '../lib/h5/extends-api')
vueConfig.configureWebpack.resolve.alias['uni-invoke-api'] = extendsApiPath
const service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd(), {
inlineOptions: vueConfig
})
// 删除 cache 目录
del.sync(['node_modules/.cache'])
let pluginDir = process.argv[2]
if (!pluginDir) {
console.error(`缺少参数`)
process.exit(0)
}
if(pluginDir.indexOf('/') === -1){
pluginDir = path.resolve(__dirname,'../packages/uni-'+pluginDir)
}
const pkg = require(path.join(pluginDir, 'package.json'))
if (!pkg['uni-app']) {
console.error(`缺少 uni-app 配置`)
process.exit(0)
}
service.webpackRawConfigFns.push(function () {
return {
resolve: {
alias: {
'uni-platform/service/api.js': extendsApiPath,
'uni-sub-platform': path.resolve(pluginDir, 'src'),
'uni-platform-api': path.resolve(__dirname, '../src/platforms/h5/service/api'),
'uni-sub-platform-api': path.resolve(pluginDir, 'src/service/api')
}
},
module: {
rules: [{
test: path.resolve(__dirname, '../src/platforms/h5/service/api/index.js'),
use: [{
loader: path.resolve(__dirname, '../lib/extends-loader'),
options: {
'extends': path.resolve(pluginDir, 'src/service/api'),
'base': path.resolve(__dirname, '../src/platforms/h5/service/api')
}
}]
}]
}
}
})
service.run('build', {
name: 'index',
watch: process.env.UNI_WATCH === 'true',
target: 'lib',
formats: process.env.UNI_WATCH === 'true' ? 'umd' : 'umd-min',
entry: './lib/h5/main.js',
dest: path.join(pluginDir, 'dist'),
clean: true,
mode: process.env.NODE_ENV
}).then(function () {}).catch(err => {
error(err)
process.exit(1)
})
......@@ -48,12 +48,12 @@ const provides = {
if (process.env.UNI_VIEW) { // 方便调试
delete provides['console']
}
module.exports = function configureWebpack (config) {
if (process.env.UNI_VIEW === 'true') {
if (process.env.UNI_VIEW === 'true') {
alias['vue$'] = resolve('packages/vue-cli-plugin-uni/packages/h5-vue/dist/vue.runtime.esm.js')
}
}
return {
module.exports = {
mode: 'production',
devtool: false,
externals,
......@@ -70,5 +70,4 @@ module.exports = function configureWebpack (config) {
}),
new webpack.ProvidePlugin(provides)
]
}
}
const fs = require('fs')
const path = require('path')
const glob = require('glob')
const loaderUtils = require('loader-utils')
const isWin = /^win/.test(process.platform)
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
module.exports = function loader(source) {
const options = loaderUtils.getOptions(this)
const baseDir = options['base']
const extendsDir = options['extends']
const exportCode = []
const extendsFiles = []
// extends目录均导出
glob.sync('**/*.js', {
cwd: extendsDir
}).forEach(file => {
if (file === 'index.js') {
return
}
extendsFiles.push(file)
exportCode.push(`export * from 'uni-sub-platform-api/${normalizePath(file)}'`)
})
//base目录中有,extends无的导出
glob.sync('**/*.js', {
cwd: baseDir
}).forEach(file => {
if (file === 'index.js') {
return
}
if (!extendsFiles.includes(file)) {
exportCode.push(`export * from 'uni-platform-api/${normalizePath(file)}'`)
}
})
console.log(exportCode.join('\n'))
return exportCode.join('\n')
}
import 'uni-sub-platform/service/index'
import * as api from 'uni-platform/service/api/index'
export default api
......@@ -8,6 +8,8 @@
"dev:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=true UNI_PLATFORM=h5 node build/build.js",
"build:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.js",
"build:h5:ui": "cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 UNI_UI=true node build/build.js",
"dev:plugin": "cross-env NODE_ENV=production UNI_WATCH=true UNI_PLATFORM=h5 node build/build.plugin.js",
"build:plugin": "cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.plugin.js",
"build:app-plus": "cross-env UNI_PLATFORM=app-plus rollup -c build/rollup.config.mp.js",
"build:app:all": "npm run lint && npm run build:app:nvue && npm run build:app:legacy && npm run build:app:service && npm run build:app:view",
"build:app:v3": "npm run lint && npm run build:app:service && npm run dev:app:view",
......@@ -109,6 +111,7 @@
"swan": true,
"tt": true,
"qh": true,
"HWH5": true,
"weex": true,
"__id__": true,
"__uniConfig": true,
......
此差异已折叠。
import baseApi from 'uni-core/service/api'
import platformApi from 'uni-platform/service/api'
import platformApi from 'uni-invoke-api'
export default Object.assign(Object.create(null), baseApi, platformApi)
......@@ -18,16 +18,14 @@ function setNavigationBar (type, args) {
if (frontColor) {
page.navigationBar.textColor = frontColor === '#000000' ? 'black' : 'white'
UniServiceJSBridge.emit('onNavigationBarChange', {
textColor: frontColor === '#000000' ? '#000' : '#fff'
})
}
if (backgroundColor) {
page.navigationBar.backgroundColor = backgroundColor
}
UniServiceJSBridge.emit('onNavigationBarChange', {
backgroundColor
textColor: frontColor === '#000000' ? '#000' : '#fff',
backgroundColor: page.navigationBar.backgroundColor
})
}
page.navigationBar.duration = duration + 'ms'
page.navigationBar.timingFunc = timingFunc
break
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册