@dcloudio/uni-cli-shared 2.0.1-alpha-34220220310002 → 2.0.1-alpha-34320220401001
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +5 -3
- package/lib/platform.js +185 -176
- package/lib/plugin.js +122 -122
- package/lib/url-loader.js +52 -51
- package/package.json +2 -2
package/lib/index.js
CHANGED
|
@@ -57,7 +57,8 @@ const {
|
|
|
57
57
|
nvueJsPreprocessOptions,
|
|
58
58
|
nvueCssPreprocessOptions,
|
|
59
59
|
nvueHtmlPreprocessOptions,
|
|
60
|
-
getPlatformGlobal
|
|
60
|
+
getPlatformGlobal,
|
|
61
|
+
getPlatformStat
|
|
61
62
|
} = require('./platform')
|
|
62
63
|
|
|
63
64
|
module.exports = {
|
|
@@ -106,5 +107,6 @@ module.exports = {
|
|
|
106
107
|
nvueJsPreprocessOptions,
|
|
107
108
|
nvueCssPreprocessOptions,
|
|
108
109
|
nvueHtmlPreprocessOptions,
|
|
109
|
-
getPlatformGlobal
|
|
110
|
-
|
|
110
|
+
getPlatformGlobal,
|
|
111
|
+
getPlatformStat
|
|
112
|
+
}
|
package/lib/platform.js
CHANGED
|
@@ -1,177 +1,186 @@
|
|
|
1
|
-
const fs = require('fs')
|
|
2
|
-
const path = require('path')
|
|
3
|
-
|
|
4
|
-
const {
|
|
5
|
-
isInHBuilderX,
|
|
6
|
-
isInHBuilderXAlpha,
|
|
7
|
-
normalizeNodeModules
|
|
8
|
-
} = require('./util')
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
SCSS,
|
|
12
|
-
SASS
|
|
13
|
-
} = require('./scss')
|
|
14
|
-
|
|
15
|
-
function getShadowCss () {
|
|
16
|
-
let tagName = 'page'
|
|
17
|
-
if (process.env.UNI_PLATFORM === 'h5') {
|
|
18
|
-
tagName = 'body'
|
|
19
|
-
}
|
|
20
|
-
const cdn = getShadowCdn()
|
|
21
|
-
return `${tagName}::after{position:fixed;content:'';left:-1000px;top:-1000px;-webkit-animation:shadow-preload .1s;-webkit-animation-delay:3s;animation:shadow-preload .1s;animation-delay:3s}@-webkit-keyframes shadow-preload{0%{background-image:url(${cdn}/img/shadow-grey.png)}100%{background-image:url(${cdn}/img/shadow-grey.png)}}@keyframes shadow-preload{0%{background-image:url(${cdn}/img/shadow-grey.png)}100%{background-image:url(${cdn}/img/shadow-grey.png)}}`
|
|
22
|
-
}
|
|
23
|
-
const cdns = {
|
|
24
|
-
'mp-weixin': 1,
|
|
25
|
-
'mp-alipay': 2,
|
|
26
|
-
'mp-baidu': 3,
|
|
27
|
-
'mp-toutiao': 4,
|
|
28
|
-
'mp-qq': 5,
|
|
29
|
-
'mp-360': 7,
|
|
30
|
-
'mp-dingtalk': 8,
|
|
31
|
-
'mp-kuaishou': 9,
|
|
32
|
-
'mp-lark': 10,
|
|
33
|
-
'
|
|
34
|
-
'
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const {
|
|
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
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
'
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
3
|
+
|
|
4
|
+
const {
|
|
5
|
+
isInHBuilderX,
|
|
6
|
+
isInHBuilderXAlpha,
|
|
7
|
+
normalizeNodeModules
|
|
8
|
+
} = require('./util')
|
|
9
|
+
|
|
10
|
+
const {
|
|
11
|
+
SCSS,
|
|
12
|
+
SASS
|
|
13
|
+
} = require('./scss')
|
|
14
|
+
|
|
15
|
+
function getShadowCss () {
|
|
16
|
+
let tagName = 'page'
|
|
17
|
+
if (process.env.UNI_PLATFORM === 'h5') {
|
|
18
|
+
tagName = 'body'
|
|
19
|
+
}
|
|
20
|
+
const cdn = getShadowCdn()
|
|
21
|
+
return `${tagName}::after{position:fixed;content:'';left:-1000px;top:-1000px;-webkit-animation:shadow-preload .1s;-webkit-animation-delay:3s;animation:shadow-preload .1s;animation-delay:3s}@-webkit-keyframes shadow-preload{0%{background-image:url(${cdn}/img/shadow-grey.png)}100%{background-image:url(${cdn}/img/shadow-grey.png)}}@keyframes shadow-preload{0%{background-image:url(${cdn}/img/shadow-grey.png)}100%{background-image:url(${cdn}/img/shadow-grey.png)}}`
|
|
22
|
+
}
|
|
23
|
+
const cdns = {
|
|
24
|
+
'mp-weixin': 1,
|
|
25
|
+
'mp-alipay': 2,
|
|
26
|
+
'mp-baidu': 3,
|
|
27
|
+
'mp-toutiao': 4,
|
|
28
|
+
'mp-qq': 5,
|
|
29
|
+
'mp-360': 7,
|
|
30
|
+
'mp-dingtalk': 8,
|
|
31
|
+
'mp-kuaishou': 9,
|
|
32
|
+
'mp-lark': 10,
|
|
33
|
+
'mp-jd': 11,
|
|
34
|
+
'mp-xhs': 12,
|
|
35
|
+
'quickapp-webview-huawei': 200,
|
|
36
|
+
'quickapp-webview-union': 201
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function getShadowCdn () {
|
|
40
|
+
const index = cdns[process.env.UNI_SUB_PLATFORM || process.env.UNI_PLATFORM] || ''
|
|
41
|
+
return `https://cdn${index}.dcloud.net.cn`
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 解决 vue-cli-service lint 时 UNI_PLATFORM 不存在
|
|
45
|
+
process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5'
|
|
46
|
+
|
|
47
|
+
const uniPluginOptions = global.uniPlugin.options || {}
|
|
48
|
+
|
|
49
|
+
const {
|
|
50
|
+
vueContext: preprocessContext,
|
|
51
|
+
nvueContext: nvuePreprocessContext
|
|
52
|
+
} = global.uniPlugin.preprocess
|
|
53
|
+
// TODO 暂时保留原有导出,减少影响,后续再整理一下
|
|
54
|
+
module.exports = {
|
|
55
|
+
normalizeNodeModules,
|
|
56
|
+
isInHBuilderX,
|
|
57
|
+
isInHBuilderXAlpha,
|
|
58
|
+
runByHBuilderX: isInHBuilderX || fs.existsSync(path.resolve(process.env.UNI_HBUILDERX_PLUGINS || '',
|
|
59
|
+
'weapp-tools')),
|
|
60
|
+
getFlexDirection (json) {
|
|
61
|
+
let flexDir = 'column'
|
|
62
|
+
if (json && json.nvue && json.nvue['flex-direction']) {
|
|
63
|
+
flexDir = json.nvue['flex-direction']
|
|
64
|
+
const flexDirs = ['row', 'row-reverse', 'column', 'column-reverse']
|
|
65
|
+
if (flexDirs.indexOf(flexDir) === -1) {
|
|
66
|
+
flexDir = 'column'
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return flexDir
|
|
70
|
+
},
|
|
71
|
+
jsPreprocessOptions: {
|
|
72
|
+
type: 'js',
|
|
73
|
+
context: preprocessContext
|
|
74
|
+
},
|
|
75
|
+
cssPreprocessOptions: {
|
|
76
|
+
type: 'css',
|
|
77
|
+
context: preprocessContext
|
|
78
|
+
},
|
|
79
|
+
htmlPreprocessOptions: {
|
|
80
|
+
type: 'html',
|
|
81
|
+
context: preprocessContext
|
|
82
|
+
},
|
|
83
|
+
nvueCssPreprocessOptions: {
|
|
84
|
+
type: 'css',
|
|
85
|
+
context: nvuePreprocessContext
|
|
86
|
+
},
|
|
87
|
+
nvueJsPreprocessOptions: {
|
|
88
|
+
type: 'js',
|
|
89
|
+
context: nvuePreprocessContext
|
|
90
|
+
},
|
|
91
|
+
nvueHtmlPreprocessOptions: {
|
|
92
|
+
type: 'html',
|
|
93
|
+
context: nvuePreprocessContext
|
|
94
|
+
},
|
|
95
|
+
isSupportSubPackages () {
|
|
96
|
+
return !!uniPluginOptions.subPackages
|
|
97
|
+
},
|
|
98
|
+
getPlatforms () {
|
|
99
|
+
return global.uniPlugin.platforms
|
|
100
|
+
},
|
|
101
|
+
getPlatformGlobal () { // 目前仅mp-alipay有用
|
|
102
|
+
return uniPluginOptions.global
|
|
103
|
+
},
|
|
104
|
+
getPlatformExts () { // 小程序扩展名
|
|
105
|
+
return uniPluginOptions.extnames
|
|
106
|
+
},
|
|
107
|
+
getPlatformProject () { // 开发工具项目配置名
|
|
108
|
+
return uniPluginOptions.project
|
|
109
|
+
},
|
|
110
|
+
getPlatformFilterTag () {
|
|
111
|
+
return uniPluginOptions.filterTag
|
|
112
|
+
},
|
|
113
|
+
getMPRuntimePath () {
|
|
114
|
+
if (process.env.UNI_USING_VUE3) {
|
|
115
|
+
try {
|
|
116
|
+
return require.resolve('@dcloudio/uni-' + process.env.UNI_PLATFORM + '/dist/uni.mp.esm.js')
|
|
117
|
+
} catch (error) {
|
|
118
|
+
throw new Error('Vue3 项目暂不支持当前小程序')
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return require.resolve('@dcloudio/uni-' + process.env.UNI_PLATFORM)
|
|
122
|
+
},
|
|
123
|
+
getPlatformVue (vueOptions) {
|
|
124
|
+
if (uniPluginOptions.vue) {
|
|
125
|
+
return uniPluginOptions.vue
|
|
126
|
+
}
|
|
127
|
+
if (process.env.UNI_USING_VUE3) {
|
|
128
|
+
return '@dcloudio/uni-mp-vue'
|
|
129
|
+
}
|
|
130
|
+
return '@dcloudio/vue-cli-plugin-uni/packages/mp-vue'
|
|
131
|
+
},
|
|
132
|
+
getPlatformCssVars () {
|
|
133
|
+
return uniPluginOptions.cssVars || {}
|
|
134
|
+
},
|
|
135
|
+
getPlatformCssnano () {
|
|
136
|
+
return {
|
|
137
|
+
calc: false,
|
|
138
|
+
orderedValues: false,
|
|
139
|
+
mergeLonghand: false,
|
|
140
|
+
mergeRules: false,
|
|
141
|
+
cssDeclarationSorter: false,
|
|
142
|
+
uniqueSelectors: false, // 标签排序影响头条小程序
|
|
143
|
+
minifySelectors: false, // 标签排序影响头条小程序
|
|
144
|
+
discardComments: false,
|
|
145
|
+
discardDuplicates: false // 条件编译会导致重复
|
|
146
|
+
}
|
|
147
|
+
},
|
|
148
|
+
getShadowCss,
|
|
149
|
+
getShadowTemplate (colorType = 'grey') {
|
|
150
|
+
let tagName = 'cover-image'
|
|
151
|
+
if (process.env.UNI_PLATFORM === 'mp-toutiao' || process.env.UNI_PLATFORM === 'mp-lark' || process.env.UNI_PLATFORM === 'mp-xhs') {
|
|
152
|
+
tagName = 'image'
|
|
153
|
+
}
|
|
154
|
+
return `<${tagName} src="${getShadowCdn()}/img/shadow-${colorType}.png" style="z-index:998;position:fixed;left:0;top:0;width:100%;height:3px;"/>`
|
|
155
|
+
},
|
|
156
|
+
getPlatformScss () {
|
|
157
|
+
return SCSS
|
|
158
|
+
},
|
|
159
|
+
getPlatformSass () {
|
|
160
|
+
return SASS
|
|
161
|
+
},
|
|
162
|
+
getPlatformStat () {
|
|
163
|
+
if (!process.env.UNI_USING_STAT) {
|
|
164
|
+
return ''
|
|
165
|
+
}
|
|
166
|
+
return process.env.UNI_USING_STAT === '2' ? 'import \'@dcloudio/uni-stat/dist/uni-cloud-stat.es.js\';'
|
|
167
|
+
: 'import \'@dcloudio/uni-stat/dist/uni-stat.es.js\';'
|
|
168
|
+
},
|
|
169
|
+
getBabelParserOptions () {
|
|
170
|
+
return {
|
|
171
|
+
sourceType: 'module',
|
|
172
|
+
plugins: [
|
|
173
|
+
['pipelineOperator', {
|
|
174
|
+
proposal: 'minimal'
|
|
175
|
+
}],
|
|
176
|
+
'doExpressions',
|
|
177
|
+
'optionalChaining',
|
|
178
|
+
'typescript',
|
|
179
|
+
['decorators', {
|
|
180
|
+
decoratorsBeforeExport: true
|
|
181
|
+
}],
|
|
182
|
+
'classProperties'
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
}
|
|
177
186
|
}
|
package/lib/plugin.js
CHANGED
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const initPreprocessContext = require('./preprocess')
|
|
3
|
-
const uniI18n = require('@dcloudio/uni-cli-i18n')
|
|
4
|
-
|
|
5
|
-
const Plugin = {
|
|
6
|
-
options: {},
|
|
7
|
-
// 初步校验相关配置是否正确
|
|
8
|
-
validate: [], // (platformOptions, manifestJson) {},
|
|
9
|
-
configureEnv: [], // (){},
|
|
10
|
-
// 以 H5 为基准的平台特殊配置
|
|
11
|
-
configureH5: [], // (h5Options) {},
|
|
12
|
-
configurePages: [], // (pagesJson,manifestJson,loader) {},
|
|
13
|
-
// 链式修改 webpack config
|
|
14
|
-
chainWebpack: [], // (config, vueOptions, api) {},
|
|
15
|
-
// 修改 webpack config
|
|
16
|
-
configureWebpack: [], // (config, vueOptions, api) {},
|
|
17
|
-
// 配置额外的资源拷贝
|
|
18
|
-
copyWebpackOptions: [] // (platformOptions, vueOptions) {}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
const PLUGIN_KEYS = Object.keys(Plugin)
|
|
22
|
-
|
|
23
|
-
function initPlugin (plugin) {
|
|
24
|
-
let pluginApi
|
|
25
|
-
try {
|
|
26
|
-
pluginApi = require(path.join(plugin.id, (plugin.config.main || '/lib/uni.config.js')))
|
|
27
|
-
} catch (e) {
|
|
28
|
-
console.warn(uniI18n.__('cliShared.missingUniConfig', { 0: plugin.id }))
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
pluginApi && PLUGIN_KEYS.forEach(name => {
|
|
32
|
-
if (pluginApi[name]) {
|
|
33
|
-
if (Array.isArray(Plugin[name])) { // hooks
|
|
34
|
-
Plugin[name].push(pluginApi[name])
|
|
35
|
-
} else { // options
|
|
36
|
-
Object.assign(Plugin[name], pluginApi[name])
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
const pluginRE = /^(uni-|@[\w-]+(\.)?[\w-]+\/uni-)/
|
|
43
|
-
|
|
44
|
-
function resolvePlugins () {
|
|
45
|
-
const pkg = require(path.resolve(process.env.UNI_CLI_CONTEXT, 'package.json'))
|
|
46
|
-
return Object.keys(pkg.devDependencies || {})
|
|
47
|
-
.concat(Object.keys(pkg.dependencies || {}))
|
|
48
|
-
.map(id => {
|
|
49
|
-
if (!pluginRE.test(id)) {
|
|
50
|
-
return
|
|
51
|
-
}
|
|
52
|
-
try {
|
|
53
|
-
const pluginPkg = require(id + '/package.json')
|
|
54
|
-
const config = pluginPkg['uni-app']
|
|
55
|
-
if (!config) {
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
if (!config.name) {
|
|
59
|
-
return console.warn(uniI18n.__('cliShared.missingNameAttribute', { 0: `${id}/package.json->uni-app` }))
|
|
60
|
-
}
|
|
61
|
-
return {
|
|
62
|
-
id,
|
|
63
|
-
name: config.name,
|
|
64
|
-
config
|
|
65
|
-
}
|
|
66
|
-
} catch (e) {}
|
|
67
|
-
}).filter(Boolean)
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
function initExtends (name, plugin, plugins) {
|
|
71
|
-
const extendsPlatform = plugin.config.extends
|
|
72
|
-
if (extendsPlatform) {
|
|
73
|
-
if (extendsPlatform !== 'h5') {
|
|
74
|
-
console.error(uniI18n.__('cliShared.extendOnlySupportH5'))
|
|
75
|
-
process.exit(0)
|
|
76
|
-
}
|
|
77
|
-
if (!plugin) {
|
|
78
|
-
console.error(uniI18n.__('cliShared.noFoundPlatformPlugin', { 0: extendsPlatform }))
|
|
79
|
-
process.exit(0)
|
|
80
|
-
}
|
|
81
|
-
const extendsPlugin = plugins.find(plugin => plugin.name === extendsPlatform)
|
|
82
|
-
process.env.UNI_SUB_PLATFORM = name
|
|
83
|
-
process.env.UNI_PLATFORM = extendsPlatform
|
|
84
|
-
initPlugin(extendsPlugin)
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
module.exports = {
|
|
89
|
-
init () {
|
|
90
|
-
// compatible with vue-cli-service lint
|
|
91
|
-
process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5'
|
|
92
|
-
|
|
93
|
-
// hack
|
|
94
|
-
if (
|
|
95
|
-
process.env.UNI_PLATFORM === 'quickapp-webview-huawei' ||
|
|
96
|
-
process.env.UNI_PLATFORM === 'quickapp-webview-union'
|
|
97
|
-
) {
|
|
98
|
-
process.env.UNI_SUB_PLATFORM = process.env.UNI_PLATFORM
|
|
99
|
-
process.env.UNI_PLATFORM = 'quickapp-webview'
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const plugins = resolvePlugins()
|
|
103
|
-
const plugin = plugins.find(plugin => plugin.name === process.env.UNI_PLATFORM)
|
|
104
|
-
if (!plugin) {
|
|
105
|
-
console.error(uniI18n.__('cliShared.noFoundPlatformPlugin', { 0: process.env.UNI_PLATFORM }))
|
|
106
|
-
process.exit(0)
|
|
107
|
-
}
|
|
108
|
-
const name = plugin.name
|
|
109
|
-
|
|
110
|
-
initExtends(name, plugin, plugins)
|
|
111
|
-
|
|
112
|
-
initPlugin(plugin)
|
|
113
|
-
|
|
114
|
-
Plugin.name = name
|
|
115
|
-
Plugin.id = plugin.id
|
|
116
|
-
Plugin.config = plugin.config
|
|
117
|
-
Plugin.platforms = plugins.map(plugin => plugin.name)
|
|
118
|
-
Plugin.preprocess = initPreprocessContext(name, Plugin.platforms, process.UNI_SCRIPT_DEFINE)
|
|
119
|
-
|
|
120
|
-
return Plugin
|
|
121
|
-
}
|
|
122
|
-
}
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const initPreprocessContext = require('./preprocess')
|
|
3
|
+
const uniI18n = require('@dcloudio/uni-cli-i18n')
|
|
4
|
+
|
|
5
|
+
const Plugin = {
|
|
6
|
+
options: {},
|
|
7
|
+
// 初步校验相关配置是否正确
|
|
8
|
+
validate: [], // (platformOptions, manifestJson) {},
|
|
9
|
+
configureEnv: [], // (){},
|
|
10
|
+
// 以 H5 为基准的平台特殊配置
|
|
11
|
+
configureH5: [], // (h5Options) {},
|
|
12
|
+
configurePages: [], // (pagesJson,manifestJson,loader) {},
|
|
13
|
+
// 链式修改 webpack config
|
|
14
|
+
chainWebpack: [], // (config, vueOptions, api) {},
|
|
15
|
+
// 修改 webpack config
|
|
16
|
+
configureWebpack: [], // (config, vueOptions, api) {},
|
|
17
|
+
// 配置额外的资源拷贝
|
|
18
|
+
copyWebpackOptions: [] // (platformOptions, vueOptions) {}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const PLUGIN_KEYS = Object.keys(Plugin)
|
|
22
|
+
|
|
23
|
+
function initPlugin (plugin) {
|
|
24
|
+
let pluginApi
|
|
25
|
+
try {
|
|
26
|
+
pluginApi = require(path.join(plugin.id, (plugin.config.main || '/lib/uni.config.js')))
|
|
27
|
+
} catch (e) {
|
|
28
|
+
console.warn(uniI18n.__('cliShared.missingUniConfig', { 0: plugin.id }))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
pluginApi && PLUGIN_KEYS.forEach(name => {
|
|
32
|
+
if (pluginApi[name]) {
|
|
33
|
+
if (Array.isArray(Plugin[name])) { // hooks
|
|
34
|
+
Plugin[name].push(pluginApi[name])
|
|
35
|
+
} else { // options
|
|
36
|
+
Object.assign(Plugin[name], pluginApi[name])
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const pluginRE = /^(uni-|@[\w-]+(\.)?[\w-]+\/uni-)/
|
|
43
|
+
|
|
44
|
+
function resolvePlugins () {
|
|
45
|
+
const pkg = require(path.resolve(process.env.UNI_CLI_CONTEXT, 'package.json'))
|
|
46
|
+
return Object.keys(pkg.devDependencies || {})
|
|
47
|
+
.concat(Object.keys(pkg.dependencies || {}))
|
|
48
|
+
.map(id => {
|
|
49
|
+
if (!pluginRE.test(id)) {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
try {
|
|
53
|
+
const pluginPkg = require(id + '/package.json')
|
|
54
|
+
const config = pluginPkg['uni-app']
|
|
55
|
+
if (!config) {
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
if (!config.name) {
|
|
59
|
+
return console.warn(uniI18n.__('cliShared.missingNameAttribute', { 0: `${id}/package.json->uni-app` }))
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
id,
|
|
63
|
+
name: config.name,
|
|
64
|
+
config
|
|
65
|
+
}
|
|
66
|
+
} catch (e) {}
|
|
67
|
+
}).filter(Boolean)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function initExtends (name, plugin, plugins) {
|
|
71
|
+
const extendsPlatform = plugin.config.extends
|
|
72
|
+
if (extendsPlatform) {
|
|
73
|
+
if (extendsPlatform !== 'h5') {
|
|
74
|
+
console.error(uniI18n.__('cliShared.extendOnlySupportH5'))
|
|
75
|
+
process.exit(0)
|
|
76
|
+
}
|
|
77
|
+
if (!plugin) {
|
|
78
|
+
console.error(uniI18n.__('cliShared.noFoundPlatformPlugin', { 0: extendsPlatform }))
|
|
79
|
+
process.exit(0)
|
|
80
|
+
}
|
|
81
|
+
const extendsPlugin = plugins.find(plugin => plugin.name === extendsPlatform)
|
|
82
|
+
process.env.UNI_SUB_PLATFORM = name
|
|
83
|
+
process.env.UNI_PLATFORM = extendsPlatform
|
|
84
|
+
initPlugin(extendsPlugin)
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports = {
|
|
89
|
+
init () {
|
|
90
|
+
// compatible with vue-cli-service lint
|
|
91
|
+
process.env.UNI_PLATFORM = process.env.UNI_PLATFORM || 'h5'
|
|
92
|
+
|
|
93
|
+
// hack
|
|
94
|
+
if (
|
|
95
|
+
process.env.UNI_PLATFORM === 'quickapp-webview-huawei' ||
|
|
96
|
+
process.env.UNI_PLATFORM === 'quickapp-webview-union'
|
|
97
|
+
) {
|
|
98
|
+
process.env.UNI_SUB_PLATFORM = process.env.UNI_PLATFORM
|
|
99
|
+
process.env.UNI_PLATFORM = 'quickapp-webview'
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const plugins = resolvePlugins()
|
|
103
|
+
const plugin = plugins.find(plugin => plugin.name === process.env.UNI_PLATFORM)
|
|
104
|
+
if (!plugin) {
|
|
105
|
+
console.error(uniI18n.__('cliShared.noFoundPlatformPlugin', { 0: process.env.UNI_PLATFORM }))
|
|
106
|
+
process.exit(0)
|
|
107
|
+
}
|
|
108
|
+
const name = plugin.name
|
|
109
|
+
|
|
110
|
+
initExtends(name, plugin, plugins)
|
|
111
|
+
|
|
112
|
+
initPlugin(plugin)
|
|
113
|
+
|
|
114
|
+
Plugin.name = name
|
|
115
|
+
Plugin.id = plugin.id
|
|
116
|
+
Plugin.config = plugin.config
|
|
117
|
+
Plugin.platforms = plugins.map(plugin => plugin.name)
|
|
118
|
+
Plugin.preprocess = initPreprocessContext(name, Plugin.platforms, process.UNI_SCRIPT_DEFINE)
|
|
119
|
+
|
|
120
|
+
return Plugin
|
|
121
|
+
}
|
|
122
|
+
}
|
package/lib/url-loader.js
CHANGED
|
@@ -1,51 +1,52 @@
|
|
|
1
|
-
const fileLoader = require('./file-loader.js')
|
|
2
|
-
|
|
3
|
-
const defaultOptions = {
|
|
4
|
-
limit: -1,
|
|
5
|
-
fallback: fileLoader
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
const inlineLimit =
|
|
9
|
-
process.env.UNI_PLATFORM === 'mp-weixin' ||
|
|
10
|
-
process.env.UNI_PLATFORM === 'mp-qq' ||
|
|
11
|
-
process.env.UNI_PLATFORM === 'mp-toutiao' ||
|
|
12
|
-
process.env.UNI_PLATFORM === 'mp-kuaishou' ||
|
|
13
|
-
process.env.UNI_PLATFORM === 'mp-lark' ||
|
|
14
|
-
process.env.UNI_PLATFORM === 'mp-jd' ||
|
|
15
|
-
process.env.UNI_PLATFORM === '
|
|
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
|
-
|
|
1
|
+
const fileLoader = require('./file-loader.js')
|
|
2
|
+
|
|
3
|
+
const defaultOptions = {
|
|
4
|
+
limit: -1,
|
|
5
|
+
fallback: fileLoader
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const inlineLimit =
|
|
9
|
+
process.env.UNI_PLATFORM === 'mp-weixin' ||
|
|
10
|
+
process.env.UNI_PLATFORM === 'mp-qq' ||
|
|
11
|
+
process.env.UNI_PLATFORM === 'mp-toutiao' ||
|
|
12
|
+
process.env.UNI_PLATFORM === 'mp-kuaishou' ||
|
|
13
|
+
process.env.UNI_PLATFORM === 'mp-lark' ||
|
|
14
|
+
process.env.UNI_PLATFORM === 'mp-jd' ||
|
|
15
|
+
process.env.UNI_PLATFORM === 'mp-xhs' ||
|
|
16
|
+
process.env.UNI_PLATFORM === 'app-plus' // v2需要base64,v3需要rewriteUrl
|
|
17
|
+
|
|
18
|
+
// mp-weixin,mp-qq,app-plus 非v3(即:需要base64的平台)
|
|
19
|
+
// 将/static/logo.png转换为~@/static/logo.png
|
|
20
|
+
// @import,src,background,background-image
|
|
21
|
+
|
|
22
|
+
const rewriteUrl = inlineLimit ? require('postcss-urlrewrite')({
|
|
23
|
+
imports: true,
|
|
24
|
+
properties: ['src', 'background', 'background-image'],
|
|
25
|
+
rules: [{
|
|
26
|
+
from: /^@\//,
|
|
27
|
+
to: '~@/'
|
|
28
|
+
}, {
|
|
29
|
+
from: /^\/([^/])/,
|
|
30
|
+
to: '~@/$1'
|
|
31
|
+
}]
|
|
32
|
+
}) : () => {}
|
|
33
|
+
|
|
34
|
+
module.exports = {
|
|
35
|
+
loader: 'url-loader',
|
|
36
|
+
options () {
|
|
37
|
+
if (process.env.UNI_PLATFORM === 'h5') {
|
|
38
|
+
// h5平台,不对 url-loader 作调整,默认limit:4096,也不修改file-loader输出路径
|
|
39
|
+
return {}
|
|
40
|
+
}
|
|
41
|
+
if (inlineLimit) {
|
|
42
|
+
return {
|
|
43
|
+
...defaultOptions,
|
|
44
|
+
limit: process.env.UNI_USING_V3 ? -1 : 40960 // (主要用于background-image)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
...defaultOptions
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
rewriteUrl
|
|
52
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dcloudio/uni-cli-shared",
|
|
3
|
-
"version": "2.0.1-alpha-
|
|
3
|
+
"version": "2.0.1-alpha-34320220401001",
|
|
4
4
|
"description": "uni-cli-shared",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"postcss-urlrewrite": "^0.2.2",
|
|
24
24
|
"strip-json-comments": "^2.0.1"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "465307df6c6f92d6f939756c3d625edcf663fe25"
|
|
27
27
|
}
|