@mpxjs/webpack-plugin 2.7.1-beta.0 → 2.7.1-beta.1
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 +35 -7
- package/lib/native-loader.js +1 -1
- package/lib/runtime/components/web/mpx-swiper.vue +19 -5
- package/lib/runtime/components/web/mpx-textarea.vue +1 -1
- package/lib/style-compiler/index.js +2 -1
- package/lib/style-compiler/plugins/vw.js +5 -4
- package/lib/web/processScript.js +2 -2
- package/lib/wxs/pre-loader.js +6 -1
- package/package.json +5 -2
package/lib/index.js
CHANGED
|
@@ -139,9 +139,6 @@ class MpxWebpackPlugin {
|
|
|
139
139
|
options.transRpxRules = options.transRpxRules || null
|
|
140
140
|
options.auditResource = options.auditResource || false
|
|
141
141
|
options.decodeHTMLText = options.decodeHTMLText || false
|
|
142
|
-
options.nativeOptions = Object.assign({
|
|
143
|
-
cssLangs: ['css', 'less', 'stylus', 'scss', 'sass']
|
|
144
|
-
}, options.nativeOptions)
|
|
145
142
|
options.i18n = options.i18n || null
|
|
146
143
|
options.checkUsingComponents = options.checkUsingComponents || false
|
|
147
144
|
options.reportSize = options.reportSize || null
|
|
@@ -156,6 +153,10 @@ class MpxWebpackPlugin {
|
|
|
156
153
|
include: () => true
|
|
157
154
|
}
|
|
158
155
|
options.customOutputPath = options.customOutputPath || null
|
|
156
|
+
options.nativeConfig = Object.assign({
|
|
157
|
+
cssLangs: ['css', 'less', 'stylus', 'scss', 'sass']
|
|
158
|
+
}, options.nativeConfig)
|
|
159
|
+
options.webConfig = options.webConfig || {}
|
|
159
160
|
this.options = options
|
|
160
161
|
}
|
|
161
162
|
|
|
@@ -315,6 +316,7 @@ class MpxWebpackPlugin {
|
|
|
315
316
|
originalWriteFile(filePath, content, callback)
|
|
316
317
|
}
|
|
317
318
|
}
|
|
319
|
+
|
|
318
320
|
const defs = this.options.defs
|
|
319
321
|
|
|
320
322
|
const typeExtMap = config[this.options.mode].typeExtMap
|
|
@@ -504,8 +506,10 @@ class MpxWebpackPlugin {
|
|
|
504
506
|
transRpxRules: this.options.transRpxRules,
|
|
505
507
|
postcssInlineConfig: this.options.postcssInlineConfig,
|
|
506
508
|
decodeHTMLText: this.options.decodeHTMLText,
|
|
507
|
-
// native
|
|
508
|
-
|
|
509
|
+
// native文件专用配置
|
|
510
|
+
nativeConfig: this.options.nativeConfig,
|
|
511
|
+
// 输出web专用配置
|
|
512
|
+
webConfig: this.options.webConfig,
|
|
509
513
|
tabBarMap: {},
|
|
510
514
|
defs: preProcessDefs(this.options.defs),
|
|
511
515
|
i18n: this.options.i18n,
|
|
@@ -1273,7 +1277,7 @@ try {
|
|
|
1273
1277
|
})
|
|
1274
1278
|
})
|
|
1275
1279
|
|
|
1276
|
-
compiler.hooks.emit.
|
|
1280
|
+
compiler.hooks.emit.tap('MpxWebpackPlugin', (compilation) => {
|
|
1277
1281
|
if (this.options.generateBuildMap) {
|
|
1278
1282
|
const pagesMap = compilation.__mpx__.pagesMap
|
|
1279
1283
|
const componentsPackageMap = compilation.__mpx__.componentsMap
|
|
@@ -1290,7 +1294,31 @@ try {
|
|
|
1290
1294
|
}
|
|
1291
1295
|
}
|
|
1292
1296
|
}
|
|
1293
|
-
|
|
1297
|
+
})
|
|
1298
|
+
|
|
1299
|
+
const clearFileCache = () => {
|
|
1300
|
+
const fs = compiler.intermediateFileSystem
|
|
1301
|
+
const cacheLocation = compiler.options.cache.cacheLocation
|
|
1302
|
+
return new Promise((resolve, reject) => {
|
|
1303
|
+
fs.rm(cacheLocation, {
|
|
1304
|
+
recursive: true,
|
|
1305
|
+
force: true
|
|
1306
|
+
}, (err) => {
|
|
1307
|
+
if (err) return reject(err)
|
|
1308
|
+
resolve()
|
|
1309
|
+
})
|
|
1310
|
+
})
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
compiler.hooks.done.tapPromise('MpxWebpackPlugin', async () => {
|
|
1314
|
+
const cache = compiler.getCache('MpxWebpackPlugin')
|
|
1315
|
+
const cacheIsValid = await cache.getPromise('cacheIsValid', null)
|
|
1316
|
+
if (!cacheIsValid) {
|
|
1317
|
+
await Promise.all([
|
|
1318
|
+
clearFileCache(),
|
|
1319
|
+
cache.storePromise('cacheIsValid', null, true)
|
|
1320
|
+
])
|
|
1321
|
+
}
|
|
1294
1322
|
})
|
|
1295
1323
|
}
|
|
1296
1324
|
}
|
package/lib/native-loader.js
CHANGED
|
@@ -55,7 +55,7 @@ module.exports = function (content) {
|
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
function checkCSSLangFiles (callback) {
|
|
58
|
-
const langs = mpx.
|
|
58
|
+
const langs = mpx.nativeConfig.cssLangs || ['less', 'stylus', 'scss', 'sass']
|
|
59
59
|
const results = []
|
|
60
60
|
async.eachOf(langs, function (lang, i, callback) {
|
|
61
61
|
if (!CSS_LANG_EXT_MAP[lang]) {
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
easingFunction: {
|
|
37
37
|
type: String,
|
|
38
38
|
default: 'default'
|
|
39
|
-
}
|
|
39
|
+
},
|
|
40
|
+
scrollOptions: Object
|
|
40
41
|
},
|
|
41
42
|
data () {
|
|
42
43
|
return {
|
|
@@ -90,11 +91,21 @@
|
|
|
90
91
|
this.goto(val)
|
|
91
92
|
}
|
|
92
93
|
},
|
|
94
|
+
activated () {
|
|
95
|
+
if (this.bs && this.autoplay) {
|
|
96
|
+
this.bs.startPlay()
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
deactivated () {
|
|
100
|
+
if (this.bs && this.autoplay) {
|
|
101
|
+
this.bs.pausePlay()
|
|
102
|
+
}
|
|
103
|
+
},
|
|
93
104
|
beforeCreate () {
|
|
94
105
|
this.itemIds = []
|
|
95
106
|
},
|
|
96
107
|
mounted () {
|
|
97
|
-
|
|
108
|
+
const originBsOptions = {
|
|
98
109
|
scrollX: !this.vertical,
|
|
99
110
|
scrollY: this.vertical,
|
|
100
111
|
slide: {
|
|
@@ -103,14 +114,17 @@
|
|
|
103
114
|
speed: this.duration,
|
|
104
115
|
easing: this.easing,
|
|
105
116
|
interval: this.interval,
|
|
106
|
-
autoplay: this.autoplay
|
|
117
|
+
autoplay: this.autoplay,
|
|
118
|
+
startPageXIndex: this.vertical ? 0 : this.current,
|
|
119
|
+
startPageYIndex: this.vertical? this.current : 0
|
|
107
120
|
},
|
|
108
121
|
momentum: false,
|
|
109
122
|
bounce: false,
|
|
110
123
|
probeType: 3,
|
|
111
124
|
stopPropagation: true
|
|
112
|
-
}
|
|
113
|
-
|
|
125
|
+
}
|
|
126
|
+
const bsOptions = Object.assign({}, originBsOptions, this.scrollOptions)
|
|
127
|
+
this.bs = new BScroll(this.$refs.wrapper, bsOptions)
|
|
114
128
|
this.bs.on('slideWillChange', (page) => {
|
|
115
129
|
this.currentIndex = this.vertical ? page.pageY : page.pageX
|
|
116
130
|
this.$emit('change', getCustomEvent('change', {
|
|
@@ -23,6 +23,7 @@ module.exports = function (css, map) {
|
|
|
23
23
|
const transRpxRulesRaw = mpx.transRpxRules
|
|
24
24
|
const transRpxRules = transRpxRulesRaw ? (Array.isArray(transRpxRulesRaw) ? transRpxRulesRaw : [transRpxRulesRaw]) : []
|
|
25
25
|
|
|
26
|
+
const transRpxFn = mpx.webConfig.transRpxFn
|
|
26
27
|
const testResolveRange = (include = () => true, exclude) => {
|
|
27
28
|
return matchCondition(this.resourcePath, { include, exclude })
|
|
28
29
|
}
|
|
@@ -67,7 +68,7 @@ module.exports = function (css, map) {
|
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
if (mpx.mode === 'web') {
|
|
70
|
-
plugins.push(vw)
|
|
71
|
+
plugins.push(vw({ transRpxFn }))
|
|
71
72
|
}
|
|
72
73
|
// source map
|
|
73
74
|
if (this.sourceMap && !options.map) {
|
|
@@ -5,12 +5,13 @@ const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
|
|
|
5
5
|
module.exports = postcss.plugin('vw', (options = {}) => root => {
|
|
6
6
|
const rpx2vwRatio = +(100 / 750).toFixed(8)
|
|
7
7
|
|
|
8
|
+
const transRpxFn = options.transRpxFn && typeof options.transRpxFn === 'function' ? options.transRpxFn : function (match, $1) {
|
|
9
|
+
if ($1 === '0') return $1
|
|
10
|
+
return `${$1 * rpx2vwRatio}vw`
|
|
11
|
+
}
|
|
8
12
|
function transVw (declaration) {
|
|
9
13
|
if (rpxRegExp.test(declaration.value)) {
|
|
10
|
-
declaration.value = declaration.value.replace(rpxRegExpG,
|
|
11
|
-
if ($1 === '0') return $1
|
|
12
|
-
return `${$1 * rpx2vwRatio}vw`
|
|
13
|
-
})
|
|
14
|
+
declaration.value = declaration.value.replace(rpxRegExpG, transRpxFn)
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
|
package/lib/web/processScript.js
CHANGED
|
@@ -210,11 +210,11 @@ module.exports = function (script, {
|
|
|
210
210
|
content += ` global.currentResource = ${JSON.stringify(loaderContext.resourcePath)}\n`
|
|
211
211
|
}
|
|
212
212
|
// 为了正确获取currentSrcMode便于运行时进行转换,对于src引入的组件script采用require方式引入(由于webpack会将import的执行顺序上升至最顶),这意味着对于src引入脚本中的named export将不会生效,不过鉴于mpx和小程序中本身也没有在组件script中声明export的用法,所以应该没有影响
|
|
213
|
-
content += '\n\n\n/**
|
|
213
|
+
content += '\n\n\n/** Source start **/\n'
|
|
214
214
|
content += script.src
|
|
215
215
|
? `require(${stringifyRequest(script.src)})\n`
|
|
216
216
|
: script.content
|
|
217
|
-
content += '\n/**
|
|
217
|
+
content += '\n/** Source end **/\n\n\n'
|
|
218
218
|
// createApp/Page/Component执行完成后立刻获取当前的option并暂存
|
|
219
219
|
content += ` const currentOption = global.currentOption\n`
|
|
220
220
|
// 获取pageConfig
|
package/lib/wxs/pre-loader.js
CHANGED
|
@@ -39,11 +39,16 @@ module.exports = function (content) {
|
|
|
39
39
|
let results = targetPath.unshiftContainer('body', insertNodes) || []
|
|
40
40
|
targetPath.inserted = true
|
|
41
41
|
results.forEach((item) => {
|
|
42
|
-
item.
|
|
42
|
+
item.shouldStopTraverse = true
|
|
43
43
|
})
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
},
|
|
47
|
+
ForStatement (path) {
|
|
48
|
+
if (path.shouldStopTraverse) {
|
|
49
|
+
path.stop()
|
|
50
|
+
}
|
|
51
|
+
},
|
|
47
52
|
// 处理vant-aliapp中export var bem = bem;这种不被acorn支持的2b语法
|
|
48
53
|
ExportNamedDeclaration (path) {
|
|
49
54
|
if (
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.1-beta.
|
|
3
|
+
"version": "2.7.1-beta.1",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -77,5 +77,8 @@
|
|
|
77
77
|
"@types/babel-traverse": "^6.25.4",
|
|
78
78
|
"@types/babel-types": "^7.0.4"
|
|
79
79
|
},
|
|
80
|
-
"
|
|
80
|
+
"engines": {
|
|
81
|
+
"node": ">=14.14.0"
|
|
82
|
+
},
|
|
83
|
+
"gitHead": "0ea8bcfff2ccfc433cb2ce43275b7e2af2bc8a61"
|
|
81
84
|
}
|