@mpxjs/webpack-plugin 2.9.12 → 2.9.13
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
const path = require('path')
|
|
1
2
|
const postcss = require('postcss')
|
|
2
3
|
const loadPostcssConfig = require('./load-postcss-config')
|
|
3
4
|
const { MPX_ROOT_VIEW, MPX_APP_MODULE_ID } = require('../utils/const')
|
|
@@ -27,7 +28,7 @@ module.exports = function (css, map) {
|
|
|
27
28
|
return matchCondition(this.resourcePath, { include, exclude })
|
|
28
29
|
}
|
|
29
30
|
|
|
30
|
-
const inlineConfig = Object.assign({}, mpx.postcssInlineConfig, { defs })
|
|
31
|
+
const inlineConfig = Object.assign({}, mpx.postcssInlineConfig, { defs, inlineConfigFile: path.join(mpx.projectRoot, 'vue.config.js') })
|
|
31
32
|
loadPostcssConfig(this, inlineConfig).then(config => {
|
|
32
33
|
const plugins = [] // init with trim plugin
|
|
33
34
|
const options = Object.assign(
|
|
@@ -3,6 +3,10 @@ const loadPlugins = require('postcss-load-config/src/plugins')
|
|
|
3
3
|
|
|
4
4
|
let loaded
|
|
5
5
|
|
|
6
|
+
function formatPlugins (plugins, file) {
|
|
7
|
+
return plugins ? loadPlugins({ plugins }, file) : []
|
|
8
|
+
}
|
|
9
|
+
|
|
6
10
|
module.exports = function loadPostcssConfig (loaderContext, inlineConfig = {}) {
|
|
7
11
|
if (inlineConfig.ignoreConfigFile) {
|
|
8
12
|
loaded = Promise.resolve({
|
|
@@ -30,9 +34,9 @@ module.exports = function loadPostcssConfig (loaderContext, inlineConfig = {}) {
|
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
return loaded.then((config = {}) => {
|
|
33
|
-
let plugins = inlineConfig.plugins
|
|
37
|
+
let plugins = formatPlugins(inlineConfig.plugins, inlineConfig.inlineConfigFile)
|
|
38
|
+
let prePlugins = formatPlugins(inlineConfig.mpxPrePlugins, inlineConfig.inlineConfigFile)
|
|
34
39
|
let options = inlineConfig.options || {}
|
|
35
|
-
let prePlugins = inlineConfig.prePlugins || []
|
|
36
40
|
|
|
37
41
|
// merge postcss config file
|
|
38
42
|
if (config.plugins) {
|
|
@@ -41,7 +45,7 @@ module.exports = function loadPostcssConfig (loaderContext, inlineConfig = {}) {
|
|
|
41
45
|
if (config.options) {
|
|
42
46
|
if (config.options.mpxPrePlugins) {
|
|
43
47
|
// 使入参和postcss格式保持一致
|
|
44
|
-
prePlugins = prePlugins.concat(
|
|
48
|
+
prePlugins = prePlugins.concat(formatPlugins(config.options.mpxPrePlugins, config.file))
|
|
45
49
|
delete config.options.mpxPrePlugins
|
|
46
50
|
}
|
|
47
51
|
options = Object.assign({}, config.options, options)
|
|
@@ -69,13 +69,13 @@ module.exports = function (script, {
|
|
|
69
69
|
|
|
70
70
|
output += `
|
|
71
71
|
export default processAppOption({
|
|
72
|
-
App,
|
|
72
|
+
App: App,
|
|
73
73
|
tabBarMap: ${JSON.stringify(tabBarMap)},
|
|
74
74
|
firstPage: ${JSON.stringify(firstPage)},
|
|
75
75
|
pagesMap: ${shallowStringify(pagesMap)},
|
|
76
76
|
componentsMap: ${shallowStringify(componentsMap)},
|
|
77
|
-
Vue,
|
|
78
|
-
VueRouter,
|
|
77
|
+
Vue: Vue,
|
|
78
|
+
VueRouter: VueRouter,
|
|
79
79
|
el: ${JSON.stringify(webConfig.el || '#app')}
|
|
80
80
|
})\n`
|
|
81
81
|
|
package/lib/web/processScript.js
CHANGED
|
@@ -56,7 +56,7 @@ module.exports = function (script, {
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
// 获取组件集合
|
|
59
|
-
const componentsMap = buildComponentsMap({ localComponentsMap, builtInComponentsMap, loaderContext })
|
|
59
|
+
const componentsMap = buildComponentsMap({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig })
|
|
60
60
|
|
|
61
61
|
// 获取pageConfig
|
|
62
62
|
const pageConfig = {}
|
package/lib/web/script-helper.js
CHANGED
|
@@ -31,14 +31,27 @@ function getAsyncChunkName (chunkName) {
|
|
|
31
31
|
return ''
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderContext }) {
|
|
34
|
+
function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderContext, jsonConfig }) {
|
|
35
35
|
const componentsMap = {}
|
|
36
36
|
if (localComponentsMap) {
|
|
37
37
|
Object.keys(localComponentsMap).forEach((componentName) => {
|
|
38
38
|
const componentCfg = localComponentsMap[componentName]
|
|
39
39
|
const componentRequest = stringifyRequest(loaderContext, componentCfg.resource)
|
|
40
40
|
if (componentCfg.async) {
|
|
41
|
-
|
|
41
|
+
// todo 暂时只处理局部注册的组件作为componentPlaceholder,暂不支持全局组件和原生组件,如使用了支持范围外的组件将不进行placeholder渲染及替换
|
|
42
|
+
if (jsonConfig.componentPlaceholder && jsonConfig.componentPlaceholder[componentName] && localComponentsMap[jsonConfig.componentPlaceholder[componentName]]) {
|
|
43
|
+
const placeholder = jsonConfig.componentPlaceholder[componentName]
|
|
44
|
+
const placeholderCfg = localComponentsMap[placeholder]
|
|
45
|
+
const placeholderRequest = stringifyRequest(loaderContext, placeholderCfg.resource)
|
|
46
|
+
if (placeholderCfg.async) {
|
|
47
|
+
loaderContext.emitWarning(
|
|
48
|
+
new Error(`[json processor][${loaderContext.resource}]: componentPlaceholder ${placeholder} should not be a async component, please check!`)
|
|
49
|
+
)
|
|
50
|
+
}
|
|
51
|
+
componentsMap[componentName] = `function(){return {component: import(${getAsyncChunkName(componentCfg.async)}${componentRequest}).then(function(res){return getComponent(res)}), loading: getComponent(require(${placeholderRequest}))}}`
|
|
52
|
+
} else {
|
|
53
|
+
componentsMap[componentName] = `function(){return import(${getAsyncChunkName(componentCfg.async)}${componentRequest}).then(function(res){return getComponent(res)})}`
|
|
54
|
+
}
|
|
42
55
|
} else {
|
|
43
56
|
componentsMap[componentName] = `getComponent(require(${componentRequest}))`
|
|
44
57
|
}
|
|
@@ -48,7 +61,7 @@ function buildComponentsMap ({ localComponentsMap, builtInComponentsMap, loaderC
|
|
|
48
61
|
Object.keys(builtInComponentsMap).forEach((componentName) => {
|
|
49
62
|
const componentCfg = builtInComponentsMap[componentName]
|
|
50
63
|
const componentRequest = stringifyRequest(loaderContext, componentCfg.resource)
|
|
51
|
-
componentsMap[componentName] = `getComponent(require(${componentRequest}), {
|
|
64
|
+
componentsMap[componentName] = `getComponent(require(${componentRequest}), {__mpxBuiltIn: true})`
|
|
52
65
|
})
|
|
53
66
|
}
|
|
54
67
|
return componentsMap
|
|
@@ -69,15 +82,13 @@ function buildPagesMap ({ localPagesMap, loaderContext, tabBar, tabBarMap, tabBa
|
|
|
69
82
|
if (pageCfg) {
|
|
70
83
|
const pageRequest = stringifyRequest(loaderContext, pageCfg.resource)
|
|
71
84
|
if (pageCfg.async) {
|
|
72
|
-
tabBarPagesMap[pagePath] = `function() {
|
|
73
|
-
return import(${getAsyncChunkName(pageCfg.async)}${pageRequest}).then(function(res) {return getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} })});
|
|
74
|
-
}`
|
|
85
|
+
tabBarPagesMap[pagePath] = `function(){return import(${getAsyncChunkName(pageCfg.async)}${pageRequest}).then(function(res) {return getComponent(res, {__mpxPageRoute: ${JSON.stringify(pagePath)}})})}`
|
|
75
86
|
} else {
|
|
76
|
-
tabBarPagesMap[pagePath] = `getComponent(require(${pageRequest}), {
|
|
87
|
+
tabBarPagesMap[pagePath] = `getComponent(require(${pageRequest}), {__mpxPageRoute: ${JSON.stringify(pagePath)}})`
|
|
77
88
|
}
|
|
78
89
|
} else {
|
|
79
90
|
loaderContext.emitWarning(
|
|
80
|
-
new Error(
|
|
91
|
+
new Error(`[json processor][${loaderContext.resource}]: TabBar page path ${pagePath} is not exist in local page map, please check!`)
|
|
81
92
|
)
|
|
82
93
|
}
|
|
83
94
|
})
|
|
@@ -93,15 +104,13 @@ function buildPagesMap ({ localPagesMap, loaderContext, tabBar, tabBarMap, tabBa
|
|
|
93
104
|
const pageCfg = localPagesMap[pagePath]
|
|
94
105
|
const pageRequest = stringifyRequest(loaderContext, pageCfg.resource)
|
|
95
106
|
if (tabBarMap && tabBarMap[pagePath]) {
|
|
96
|
-
pagesMap[pagePath] = `getComponent(require(${stringifyRequest(loaderContext, tabBarContainerPath)}), {
|
|
107
|
+
pagesMap[pagePath] = `getComponent(require(${stringifyRequest(loaderContext, tabBarContainerPath)}), {__mpxBuiltIn: true})`
|
|
97
108
|
} else {
|
|
98
109
|
if (pageCfg.async) {
|
|
99
|
-
pagesMap[pagePath] = `function() {
|
|
100
|
-
return import(${getAsyncChunkName(pageCfg.async)} ${pageRequest}).then(function(res){ return getComponent(res, { __mpxPageRoute: ${JSON.stringify(pagePath)} })});
|
|
101
|
-
}`
|
|
110
|
+
pagesMap[pagePath] = `function(){return import(${getAsyncChunkName(pageCfg.async)} ${pageRequest}).then(function(res){return getComponent(res, {__mpxPageRoute: ${JSON.stringify(pagePath)}})})}`
|
|
102
111
|
} else {
|
|
103
112
|
// 为了保持小程序中app->page->component的js执行顺序,所有的page和component都改为require引入
|
|
104
|
-
pagesMap[pagePath] = `getComponent(require(${pageRequest}), {
|
|
113
|
+
pagesMap[pagePath] = `getComponent(require(${pageRequest}), {__mpxPageRoute: ${JSON.stringify(pagePath)}})`
|
|
105
114
|
}
|
|
106
115
|
}
|
|
107
116
|
|
|
@@ -127,7 +136,16 @@ function getRequireScript ({ ctorType, script, loaderContext }) {
|
|
|
127
136
|
return content
|
|
128
137
|
}
|
|
129
138
|
|
|
130
|
-
function buildGlobalParams ({
|
|
139
|
+
function buildGlobalParams ({
|
|
140
|
+
moduleId,
|
|
141
|
+
scriptSrcMode,
|
|
142
|
+
loaderContext,
|
|
143
|
+
isProduction,
|
|
144
|
+
jsonConfig,
|
|
145
|
+
webConfig,
|
|
146
|
+
isMain,
|
|
147
|
+
globalTabBar
|
|
148
|
+
}) {
|
|
131
149
|
let content = ''
|
|
132
150
|
if (isMain) {
|
|
133
151
|
content += `
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.13",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -83,5 +83,5 @@
|
|
|
83
83
|
"engines": {
|
|
84
84
|
"node": ">=14.14.0"
|
|
85
85
|
},
|
|
86
|
-
"gitHead": "
|
|
86
|
+
"gitHead": "2c67b32fe01ff15fc1b728f91b4b5652244c2f35"
|
|
87
87
|
}
|