@mpxjs/webpack-plugin 2.7.53 → 2.7.55
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 +2 -2
- package/lib/loader.js +4 -5
- package/lib/runtime/animation.js +59 -0
- package/lib/runtime/optionProcessor.js +9 -100
- package/lib/runtime/transRpxStyle.js +44 -0
- package/lib/web/processJSON.js +1 -3
- package/lib/web/processScript.js +8 -4
- package/lib/wxss/CssSyntaxError.js +29 -0
- package/lib/wxss/Warning.js +22 -0
- package/lib/wxss/index.js +5 -0
- package/lib/wxss/loader.js +233 -131
- package/lib/wxss/options.json +209 -0
- package/lib/wxss/plugins/index.js +5 -0
- package/lib/wxss/plugins/postcss-icss-parser.js +124 -0
- package/lib/wxss/plugins/postcss-import-parser.js +372 -0
- package/lib/wxss/plugins/postcss-url-parser.js +447 -0
- package/lib/wxss/runtime/api.js +104 -0
- package/lib/wxss/runtime/getUrl.js +28 -0
- package/lib/wxss/runtime/noSourceMaps.js +1 -0
- package/lib/wxss/runtime/sourceMaps.js +25 -0
- package/lib/wxss/utils.js +1313 -0
- package/package.json +2 -2
- package/lib/wxss/compile-exports.js +0 -52
- package/lib/wxss/createResolver.js +0 -36
- package/lib/wxss/css-base.js +0 -79
- package/lib/wxss/getLocalIdent.js +0 -24
- package/lib/wxss/localsLoader.js +0 -44
- package/lib/wxss/processCss.js +0 -271
- package/lib/wxss/url/escape.js +0 -16
package/lib/index.js
CHANGED
|
@@ -44,7 +44,7 @@ const { matchCondition } = require('./utils/match-condition')
|
|
|
44
44
|
const { preProcessDefs } = require('./utils/index')
|
|
45
45
|
const config = require('./config')
|
|
46
46
|
const hash = require('hash-sum')
|
|
47
|
-
const wxssLoaderPath = normalize.lib('wxss/
|
|
47
|
+
const wxssLoaderPath = normalize.lib('wxss/index')
|
|
48
48
|
const wxmlLoaderPath = normalize.lib('wxml/loader')
|
|
49
49
|
const wxsLoaderPath = normalize.lib('wxs/loader')
|
|
50
50
|
const styleCompilerPath = normalize.lib('style-compiler/index')
|
|
@@ -196,7 +196,7 @@ class MpxWebpackPlugin {
|
|
|
196
196
|
|
|
197
197
|
static wxssLoader (options) {
|
|
198
198
|
return {
|
|
199
|
-
loader: normalize.lib('wxss/
|
|
199
|
+
loader: normalize.lib('wxss/index'),
|
|
200
200
|
options
|
|
201
201
|
}
|
|
202
202
|
}
|
package/lib/loader.js
CHANGED
|
@@ -65,6 +65,10 @@ module.exports = function (content) {
|
|
|
65
65
|
this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, ctorType, entryName, packageRoot))
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
if (ctorType === 'app') {
|
|
69
|
+
const appName = getEntryName(this)
|
|
70
|
+
this._module.addPresentationalDependency(new AppEntryDependency(resourcePath, appName))
|
|
71
|
+
}
|
|
68
72
|
const loaderContext = this
|
|
69
73
|
const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
|
|
70
74
|
const isProduction = this.minimize || process.env.NODE_ENV === 'production'
|
|
@@ -222,11 +226,6 @@ module.exports = function (content) {
|
|
|
222
226
|
return callback(new Error(`Current ${ctorType} [${this.resourcePath}] is issued by [${issuer.resource}], which is not allowed!`))
|
|
223
227
|
}
|
|
224
228
|
|
|
225
|
-
if (ctorType === 'app') {
|
|
226
|
-
const appName = getEntryName(this)
|
|
227
|
-
this._module.addPresentationalDependency(new AppEntryDependency(resourcePath, appName))
|
|
228
|
-
}
|
|
229
|
-
|
|
230
229
|
// 注入模块id及资源路径
|
|
231
230
|
output += `global.currentModuleId = ${JSON.stringify(moduleId)}\n`
|
|
232
231
|
if (!isProduction) {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module.exports = function (el, binding) {
|
|
2
|
+
const newActions = binding && binding.value && binding.value.actions
|
|
3
|
+
if (el.actions === newActions) {
|
|
4
|
+
Promise.resolve().then(() => {
|
|
5
|
+
Object.assign(el.style, el.lastDynamicStyle)
|
|
6
|
+
})
|
|
7
|
+
return
|
|
8
|
+
}
|
|
9
|
+
el.actions = newActions
|
|
10
|
+
if (typeof el.setAnimation === 'function') {
|
|
11
|
+
el.removeEventListener('transitionend', el.setAnimation, false)
|
|
12
|
+
el.setAnimation = undefined
|
|
13
|
+
}
|
|
14
|
+
el.dynamicStyleQueue = []
|
|
15
|
+
el.lastDynamicStyle = undefined
|
|
16
|
+
if (Array.isArray(newActions) && newActions.length) {
|
|
17
|
+
newActions.forEach((item) => {
|
|
18
|
+
const property = []
|
|
19
|
+
const { animates, option } = item
|
|
20
|
+
// 存储动画需要改变的样式属性
|
|
21
|
+
const dynamicStyle = {
|
|
22
|
+
transform: ''
|
|
23
|
+
}
|
|
24
|
+
animates.forEach((itemAnimation) => {
|
|
25
|
+
switch (itemAnimation.type) {
|
|
26
|
+
case 'style':
|
|
27
|
+
const [key, value] = itemAnimation.args
|
|
28
|
+
dynamicStyle[key] = value
|
|
29
|
+
property.push(key)
|
|
30
|
+
break
|
|
31
|
+
default:
|
|
32
|
+
dynamicStyle.transform += `${itemAnimation.type}(${itemAnimation.args}) `
|
|
33
|
+
if (!property.includes('transform')) {
|
|
34
|
+
property.push('transform')
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
Object.assign(dynamicStyle, {
|
|
39
|
+
transition: `${parseInt(option.duration)}ms ${option.timingFunction} ${parseInt(option.delay)}ms`,
|
|
40
|
+
transitionProperty: `${property}`,
|
|
41
|
+
transformOrigin: option.transformOrigin
|
|
42
|
+
})
|
|
43
|
+
el.dynamicStyleQueue.push(dynamicStyle)
|
|
44
|
+
})
|
|
45
|
+
el.setAnimation = function () {
|
|
46
|
+
if (!el.dynamicStyleQueue.length) {
|
|
47
|
+
el.removeEventListener('transitionend', el.setAnimation, false)
|
|
48
|
+
return
|
|
49
|
+
}
|
|
50
|
+
const dynamicStyle = el.dynamicStyleQueue.shift()
|
|
51
|
+
Object.assign(el.style, dynamicStyle)
|
|
52
|
+
el.lastDynamicStyle = dynamicStyle
|
|
53
|
+
}
|
|
54
|
+
// 首次动画属性设置
|
|
55
|
+
setTimeout(el.setAnimation, 0)
|
|
56
|
+
// 在transitionend事件内设置动画样式
|
|
57
|
+
el.addEventListener('transitionend', el.setAnimation, false)
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { inBrowser } from '../utils/env'
|
|
2
|
+
import transRpxStyle from './transRpxStyle'
|
|
3
|
+
import animation from './animation'
|
|
2
4
|
|
|
3
5
|
export default function processOption (
|
|
4
6
|
option,
|
|
@@ -12,6 +14,7 @@ export default function processOption (
|
|
|
12
14
|
componentGenerics,
|
|
13
15
|
genericsInfo,
|
|
14
16
|
mixin,
|
|
17
|
+
hasApp,
|
|
15
18
|
Vue,
|
|
16
19
|
VueRouter,
|
|
17
20
|
i18n
|
|
@@ -26,108 +29,11 @@ export default function processOption (
|
|
|
26
29
|
}
|
|
27
30
|
|
|
28
31
|
Vue.directive('animation', (el, binding) => {
|
|
29
|
-
|
|
30
|
-
if (el.actions === newActions) {
|
|
31
|
-
Promise.resolve().then(() => {
|
|
32
|
-
Object.assign(el.style, el.lastDynamicStyle)
|
|
33
|
-
})
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
el.actions = newActions
|
|
37
|
-
if (typeof el.setAnimation === 'function') {
|
|
38
|
-
el.removeEventListener('transitionend', el.setAnimation, false)
|
|
39
|
-
el.setAnimation = undefined
|
|
40
|
-
}
|
|
41
|
-
el.dynamicStyleQueue = []
|
|
42
|
-
el.lastDynamicStyle = undefined
|
|
43
|
-
if (Array.isArray(newActions) && newActions.length) {
|
|
44
|
-
newActions.forEach((item) => {
|
|
45
|
-
const property = []
|
|
46
|
-
const { animates, option } = item
|
|
47
|
-
// 存储动画需要改变的样式属性
|
|
48
|
-
const dynamicStyle = {
|
|
49
|
-
transform: ''
|
|
50
|
-
}
|
|
51
|
-
animates.forEach((itemAnimation) => {
|
|
52
|
-
switch (itemAnimation.type) {
|
|
53
|
-
case 'style':
|
|
54
|
-
const [key, value] = itemAnimation.args
|
|
55
|
-
dynamicStyle[key] = value
|
|
56
|
-
property.push(key)
|
|
57
|
-
break
|
|
58
|
-
default:
|
|
59
|
-
dynamicStyle.transform += `${itemAnimation.type}(${itemAnimation.args}) `
|
|
60
|
-
if (!property.includes('transform')) {
|
|
61
|
-
property.push('transform')
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
Object.assign(dynamicStyle, {
|
|
66
|
-
transition: `${parseInt(option.duration)}ms ${option.timingFunction} ${parseInt(option.delay)}ms`,
|
|
67
|
-
transitionProperty: `${property}`,
|
|
68
|
-
transformOrigin: option.transformOrigin
|
|
69
|
-
})
|
|
70
|
-
el.dynamicStyleQueue.push(dynamicStyle)
|
|
71
|
-
})
|
|
72
|
-
el.setAnimation = function () {
|
|
73
|
-
if (!el.dynamicStyleQueue.length) {
|
|
74
|
-
el.removeEventListener('transitionend', el.setAnimation, false)
|
|
75
|
-
return
|
|
76
|
-
}
|
|
77
|
-
const dynamicStyle = el.dynamicStyleQueue.shift()
|
|
78
|
-
Object.assign(el.style, dynamicStyle)
|
|
79
|
-
el.lastDynamicStyle = dynamicStyle
|
|
80
|
-
}
|
|
81
|
-
// 首次动画属性设置
|
|
82
|
-
setTimeout(el.setAnimation, 0)
|
|
83
|
-
// 在transitionend事件内设置动画样式
|
|
84
|
-
el.addEventListener('transitionend', el.setAnimation, false)
|
|
85
|
-
}
|
|
32
|
+
return animation(el, binding)
|
|
86
33
|
})
|
|
87
34
|
|
|
88
35
|
Vue.filter('transRpxStyle', style => {
|
|
89
|
-
|
|
90
|
-
const rpx2vwRatio = +(100 / 750).toFixed(8)
|
|
91
|
-
return '' + ($1 * rpx2vwRatio) + 'vw'
|
|
92
|
-
}
|
|
93
|
-
const transRpxFn = global.__mpxTransRpxFn || defaultTransRpxFn
|
|
94
|
-
const parsedStyleObj = {}
|
|
95
|
-
const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
|
|
96
|
-
const parseStyleText = (cssText) => {
|
|
97
|
-
const listDelimiter = /;(?![^(]*\))/g
|
|
98
|
-
const propertyDelimiter = /:(.+)/
|
|
99
|
-
if (typeof cssText === 'string') {
|
|
100
|
-
cssText.split(listDelimiter).forEach((item) => {
|
|
101
|
-
if (item) {
|
|
102
|
-
var tmp = item.split(propertyDelimiter)
|
|
103
|
-
tmp.length > 1 && (parsedStyleObj[tmp[0].trim()] = tmp[1].trim())
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
} else if (typeof cssText === 'object') {
|
|
107
|
-
if (Array.isArray(cssText)) {
|
|
108
|
-
cssText.forEach(cssItem => {
|
|
109
|
-
parseStyleText(cssItem)
|
|
110
|
-
})
|
|
111
|
-
} else {
|
|
112
|
-
Object.assign(parsedStyleObj, cssText)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
const transRpxStyleFn = (val) => {
|
|
117
|
-
if (typeof val === 'string' && val.indexOf('rpx') > 0) {
|
|
118
|
-
return val.replace(rpxRegExpG, transRpxFn).replace(/"/g, '')
|
|
119
|
-
}
|
|
120
|
-
return val
|
|
121
|
-
}
|
|
122
|
-
if (style) {
|
|
123
|
-
style.forEach(item => {
|
|
124
|
-
parseStyleText(item)
|
|
125
|
-
for (let key in parsedStyleObj) {
|
|
126
|
-
parsedStyleObj[key] = transRpxStyleFn(parsedStyleObj[key])
|
|
127
|
-
}
|
|
128
|
-
})
|
|
129
|
-
}
|
|
130
|
-
return parsedStyleObj
|
|
36
|
+
return transRpxStyle(style)
|
|
131
37
|
})
|
|
132
38
|
|
|
133
39
|
const routes = []
|
|
@@ -376,6 +282,10 @@ registered in parent context!`)
|
|
|
376
282
|
if (ctorType === 'page') {
|
|
377
283
|
option.__mpxPageConfig = Object.assign({}, global.__mpxPageConfig, pageConfig)
|
|
378
284
|
}
|
|
285
|
+
if (!hasApp) {
|
|
286
|
+
option.directives = { animation }
|
|
287
|
+
option.filters = { transRpxStyle }
|
|
288
|
+
}
|
|
379
289
|
}
|
|
380
290
|
|
|
381
291
|
if (option.mixins) {
|
|
@@ -387,7 +297,6 @@ registered in parent context!`)
|
|
|
387
297
|
if (outputPath) {
|
|
388
298
|
option.componentPath = '/' + outputPath
|
|
389
299
|
}
|
|
390
|
-
|
|
391
300
|
return option
|
|
392
301
|
}
|
|
393
302
|
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
module.exports = function (style) {
|
|
2
|
+
const defaultTransRpxFn = function (match, $1) {
|
|
3
|
+
const rpx2vwRatio = +(100 / 750).toFixed(8)
|
|
4
|
+
return '' + ($1 * rpx2vwRatio) + 'vw'
|
|
5
|
+
}
|
|
6
|
+
const transRpxFn = global.__mpxTransRpxFn || defaultTransRpxFn
|
|
7
|
+
const parsedStyleObj = {}
|
|
8
|
+
const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
|
|
9
|
+
const parseStyleText = (cssText) => {
|
|
10
|
+
const listDelimiter = /;(?![^(]*\))/g
|
|
11
|
+
const propertyDelimiter = /:(.+)/
|
|
12
|
+
if (typeof cssText === 'string') {
|
|
13
|
+
cssText.split(listDelimiter).forEach((item) => {
|
|
14
|
+
if (item) {
|
|
15
|
+
var tmp = item.split(propertyDelimiter)
|
|
16
|
+
tmp.length > 1 && (parsedStyleObj[tmp[0].trim()] = tmp[1].trim())
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
} else if (typeof cssText === 'object') {
|
|
20
|
+
if (Array.isArray(cssText)) {
|
|
21
|
+
cssText.forEach(cssItem => {
|
|
22
|
+
parseStyleText(cssItem)
|
|
23
|
+
})
|
|
24
|
+
} else {
|
|
25
|
+
Object.assign(parsedStyleObj, cssText)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
const transRpxStyleFn = (val) => {
|
|
30
|
+
if (typeof val === 'string' && val.indexOf('rpx') > 0) {
|
|
31
|
+
return val.replace(rpxRegExpG, transRpxFn).replace(/"/g, '')
|
|
32
|
+
}
|
|
33
|
+
return val
|
|
34
|
+
}
|
|
35
|
+
if (style) {
|
|
36
|
+
style.forEach(item => {
|
|
37
|
+
parseStyleText(item)
|
|
38
|
+
for (let key in parsedStyleObj) {
|
|
39
|
+
parsedStyleObj[key] = transRpxStyleFn(parsedStyleObj[key])
|
|
40
|
+
}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
return parsedStyleObj
|
|
44
|
+
}
|
package/lib/web/processJSON.js
CHANGED
|
@@ -263,9 +263,7 @@ module.exports = function (json, {
|
|
|
263
263
|
if (components) {
|
|
264
264
|
async.eachOf(components, (component, name, callback) => {
|
|
265
265
|
processComponent(component, context, {}, (err, { resource, outputPath } = {}) => {
|
|
266
|
-
if (err === RESOLVE_IGNORED_ERR)
|
|
267
|
-
return callback()
|
|
268
|
-
}
|
|
266
|
+
if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
|
|
269
267
|
const { resourcePath, queryObj } = parseRequest(resource)
|
|
270
268
|
componentsMap[resourcePath] = outputPath
|
|
271
269
|
loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
|
package/lib/web/processScript.js
CHANGED
|
@@ -48,9 +48,9 @@ module.exports = function (script, {
|
|
|
48
48
|
const {
|
|
49
49
|
i18n,
|
|
50
50
|
projectRoot,
|
|
51
|
-
webConfig
|
|
51
|
+
webConfig,
|
|
52
|
+
appInfo
|
|
52
53
|
} = loaderContext.getMpx()
|
|
53
|
-
|
|
54
54
|
const { getRequire } = createHelpers(loaderContext)
|
|
55
55
|
const tabBar = jsonConfig.tabBar
|
|
56
56
|
|
|
@@ -153,6 +153,10 @@ module.exports = function (script, {
|
|
|
153
153
|
\n`
|
|
154
154
|
}
|
|
155
155
|
}
|
|
156
|
+
let hasApp = true
|
|
157
|
+
if (!appInfo.name) {
|
|
158
|
+
hasApp = false
|
|
159
|
+
}
|
|
156
160
|
// 注入wxs模块
|
|
157
161
|
content += ' const wxsModules = {}\n'
|
|
158
162
|
if (wxsModuleMap) {
|
|
@@ -238,7 +242,6 @@ module.exports = function (script, {
|
|
|
238
242
|
// @ts-ignore
|
|
239
243
|
global.__tabBarPagesMap = ${shallowStringify(tabBarPagesMap)}\n`
|
|
240
244
|
}
|
|
241
|
-
|
|
242
245
|
// 配置平台转换通过createFactory在core中convertor中定义和进行
|
|
243
246
|
// 通过processOption进行组件注册和路由注入
|
|
244
247
|
content += ` export default processOption(
|
|
@@ -254,7 +257,8 @@ module.exports = function (script, {
|
|
|
254
257
|
${JSON.stringify(tabBarMap)},
|
|
255
258
|
${JSON.stringify(componentGenerics)},
|
|
256
259
|
${JSON.stringify(genericsInfo)},
|
|
257
|
-
getWxsMixin(wxsModules)
|
|
260
|
+
getWxsMixin(wxsModules),
|
|
261
|
+
${hasApp}`
|
|
258
262
|
if (ctorType === 'app') {
|
|
259
263
|
content += `,
|
|
260
264
|
Vue,
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module.exports = class CssSyntaxError extends Error {
|
|
2
|
+
constructor (error) {
|
|
3
|
+
super(error)
|
|
4
|
+
|
|
5
|
+
const { reason, line, column, file } = error
|
|
6
|
+
|
|
7
|
+
this.name = 'CssSyntaxError'
|
|
8
|
+
|
|
9
|
+
// Based on https://github.com/postcss/postcss/blob/master/lib/css-syntax-error.es6#L132
|
|
10
|
+
// We don't need `plugin` and `file` properties.
|
|
11
|
+
this.message = `${this.name}\n\n`
|
|
12
|
+
|
|
13
|
+
if (typeof line !== 'undefined') {
|
|
14
|
+
this.message += `(${line}:${column}) `
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
this.message += file ? `${file} ` : '<css input> '
|
|
18
|
+
this.message += `${reason}`
|
|
19
|
+
|
|
20
|
+
const code = error.showSourceCode()
|
|
21
|
+
|
|
22
|
+
if (code) {
|
|
23
|
+
this.message += `\n\n${code}\n`
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// We don't need stack https://github.com/postcss/postcss/blob/master/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
|
|
27
|
+
this.stack = false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module.exports = class Warning extends Error {
|
|
2
|
+
constructor (warning) {
|
|
3
|
+
super(warning)
|
|
4
|
+
|
|
5
|
+
const { text, line, column } = warning
|
|
6
|
+
|
|
7
|
+
this.name = 'Warning'
|
|
8
|
+
|
|
9
|
+
// Based on https://github.com/postcss/postcss/blob/master/lib/warning.es6#L74
|
|
10
|
+
// We don't need `plugin` properties.
|
|
11
|
+
this.message = `${this.name}\n\n`
|
|
12
|
+
|
|
13
|
+
if (typeof line !== 'undefined') {
|
|
14
|
+
this.message += `(${line}:${column}) `
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
this.message += `${text}`
|
|
18
|
+
|
|
19
|
+
// We don't need stack https://github.com/postcss/postcss/blob/master/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
|
|
20
|
+
this.stack = false
|
|
21
|
+
}
|
|
22
|
+
}
|