forked from dcloudio/uni-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.plugin.js
85 lines (74 loc) · 2.49 KB
/
build.plugin.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
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/core/view/components/index.js'),
use: [{
loader: path.resolve(__dirname, '../lib/extends-component-loader'),
options: {
extends: path.resolve(pluginDir, 'src/view/components'),
base: path.resolve(__dirname, '../src/core/view/components'),
platform: path.resolve(__dirname, '../src/platforms/h5/view/components')
}
}]
}, {
test: path.resolve(__dirname, '../src/platforms/h5/service/api/index.js'),
use: [{
loader: path.resolve(__dirname, '../lib/extends-api-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)
})