@mpxjs/webpack-plugin 2.8.44 → 2.8.46
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 -5
- package/lib/platform/template/wx/index.js +45 -6
- package/lib/runtime/components/web/mpx-keep-alive.vue +8 -17
- package/lib/runtime/optionProcessor.js +1 -1
- package/lib/utils/ts-loader-watch-run-loader-filter.js +1 -1
- 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 -25
- package/lib/wxss/localsLoader.js +0 -44
- package/lib/wxss/processCss.js +0 -274
package/lib/index.js
CHANGED
|
@@ -1453,8 +1453,8 @@ try {
|
|
|
1453
1453
|
})
|
|
1454
1454
|
|
|
1455
1455
|
const typeLoaderProcessInfo = {
|
|
1456
|
-
styles: ['css-loader', wxssLoaderPath, styleCompilerPath],
|
|
1457
|
-
template: ['html-loader', wxmlLoaderPath, templateCompilerPath]
|
|
1456
|
+
styles: ['node_modules/css-loader', wxssLoaderPath, styleCompilerPath],
|
|
1457
|
+
template: ['node_modules/html-loader', wxmlLoaderPath, templateCompilerPath]
|
|
1458
1458
|
}
|
|
1459
1459
|
|
|
1460
1460
|
// 应用过rules后,注入mpx相关资源编译loader
|
|
@@ -1517,15 +1517,15 @@ try {
|
|
|
1517
1517
|
if (mpx.mode === 'web') {
|
|
1518
1518
|
const mpxStyleOptions = queryObj.mpxStyleOptions
|
|
1519
1519
|
const firstLoader = loaders[0] ? toPosix(loaders[0].loader) : ''
|
|
1520
|
-
const isPitcherRequest = firstLoader.includes('vue-loader/lib/loaders/pitcher')
|
|
1520
|
+
const isPitcherRequest = firstLoader.includes('node_modules/vue-loader/lib/loaders/pitcher')
|
|
1521
1521
|
let cssLoaderIndex = -1
|
|
1522
1522
|
let vueStyleLoaderIndex = -1
|
|
1523
1523
|
let mpxStyleLoaderIndex = -1
|
|
1524
1524
|
loaders.forEach((loader, index) => {
|
|
1525
1525
|
const currentLoader = toPosix(loader.loader)
|
|
1526
|
-
if (currentLoader.includes('css-loader') && cssLoaderIndex === -1) {
|
|
1526
|
+
if (currentLoader.includes('node_modules/css-loader') && cssLoaderIndex === -1) {
|
|
1527
1527
|
cssLoaderIndex = index
|
|
1528
|
-
} else if (currentLoader.includes('vue-loader/lib/loaders/stylePostLoader') && vueStyleLoaderIndex === -1) {
|
|
1528
|
+
} else if (currentLoader.includes('node_modules/vue-loader/lib/loaders/stylePostLoader') && vueStyleLoaderIndex === -1) {
|
|
1529
1529
|
vueStyleLoaderIndex = index
|
|
1530
1530
|
} else if (currentLoader.includes(styleCompilerPath) && mpxStyleLoaderIndex === -1) {
|
|
1531
1531
|
mpxStyleLoaderIndex = index
|
|
@@ -195,7 +195,7 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
195
195
|
const parsed = parseMustache(item.value)
|
|
196
196
|
if (item.name === 'wx:style') {
|
|
197
197
|
styleBinding.push(parsed.result)
|
|
198
|
-
|
|
198
|
+
// item.name === 'style'
|
|
199
199
|
} else if (parsed.hasBinding || parsed.result.indexOf('rpx') > -1) {
|
|
200
200
|
styleBinding.push(parsed.result)
|
|
201
201
|
} else {
|
|
@@ -295,18 +295,39 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
295
295
|
},
|
|
296
296
|
swan ({ name, value }, { eventRules }) {
|
|
297
297
|
const match = this.test.exec(name)
|
|
298
|
+
const prefix = match[1]
|
|
298
299
|
const eventName = match[2]
|
|
299
|
-
|
|
300
|
+
const modifierStr = match[3] || ''
|
|
301
|
+
const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'swan' })
|
|
302
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'swan' })
|
|
303
|
+
return {
|
|
304
|
+
name: rPrefix + rEventName + modifierStr,
|
|
305
|
+
value
|
|
306
|
+
}
|
|
300
307
|
},
|
|
301
308
|
qq ({ name, value }, { eventRules }) {
|
|
302
309
|
const match = this.test.exec(name)
|
|
310
|
+
const prefix = match[1]
|
|
303
311
|
const eventName = match[2]
|
|
304
|
-
|
|
312
|
+
const modifierStr = match[3] || ''
|
|
313
|
+
const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'qq' })
|
|
314
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'qq' })
|
|
315
|
+
return {
|
|
316
|
+
name: rPrefix + rEventName + modifierStr,
|
|
317
|
+
value
|
|
318
|
+
}
|
|
305
319
|
},
|
|
306
320
|
jd ({ name, value }, { eventRules }) {
|
|
307
321
|
const match = this.test.exec(name)
|
|
322
|
+
const prefix = match[1]
|
|
308
323
|
const eventName = match[2]
|
|
309
|
-
|
|
324
|
+
const modifierStr = match[3] || ''
|
|
325
|
+
const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'jd' })
|
|
326
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'jd' })
|
|
327
|
+
return {
|
|
328
|
+
name: rPrefix + rEventName + modifierStr,
|
|
329
|
+
value
|
|
330
|
+
}
|
|
310
331
|
},
|
|
311
332
|
// tt ({ name, value }, { eventRules }) {
|
|
312
333
|
// const match = this.test.exec(name)
|
|
@@ -322,15 +343,33 @@ module.exports = function getSpec ({ warn, error }) {
|
|
|
322
343
|
// },
|
|
323
344
|
tt ({ name, value }, { eventRules }) {
|
|
324
345
|
const match = this.test.exec(name)
|
|
346
|
+
const prefix = match[1]
|
|
325
347
|
const eventName = match[2]
|
|
326
|
-
|
|
348
|
+
const modifierStr = match[3] || ''
|
|
349
|
+
const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'tt' })
|
|
350
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'tt' })
|
|
351
|
+
return {
|
|
352
|
+
name: rPrefix + rEventName + modifierStr,
|
|
353
|
+
value
|
|
354
|
+
}
|
|
327
355
|
},
|
|
328
356
|
dd ({ name, value }, { eventRules }) {
|
|
329
357
|
const match = this.test.exec(name)
|
|
358
|
+
const prefix = match[1]
|
|
330
359
|
const eventName = match[2]
|
|
331
|
-
|
|
360
|
+
const modifierStr = match[3] || ''
|
|
361
|
+
const rPrefix = runRules(spec.event.prefix, prefix, { mode: 'dd' })
|
|
362
|
+
const rEventName = runRules(eventRules, eventName, { mode: 'dd' })
|
|
363
|
+
return {
|
|
364
|
+
name: rPrefix + rEventName + modifierStr,
|
|
365
|
+
value
|
|
366
|
+
}
|
|
332
367
|
},
|
|
333
368
|
web ({ name, value }, { eventRules, el }) {
|
|
369
|
+
if (parseMustache(value).hasBinding) {
|
|
370
|
+
error('Web environment does not support mustache binding in event props!')
|
|
371
|
+
return
|
|
372
|
+
}
|
|
334
373
|
const match = this.test.exec(name)
|
|
335
374
|
const prefix = match[1]
|
|
336
375
|
const eventName = match[2]
|
|
@@ -30,9 +30,7 @@
|
|
|
30
30
|
}
|
|
31
31
|
|
|
32
32
|
function getVnodeKey (vnode) {
|
|
33
|
-
|
|
34
|
-
return vnode.componentOptions.Ctor.cid + (vnode.componentOptions.tag ? ('::' + (vnode.componentOptions.tag)) : '')
|
|
35
|
-
}
|
|
33
|
+
return vnode.tag + (vnode.key ? `::${vnode.key}` : '')
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
export default {
|
|
@@ -44,12 +42,13 @@
|
|
|
44
42
|
if (!isBrowser) {
|
|
45
43
|
return vnode || (slot && slot[0])
|
|
46
44
|
}
|
|
47
|
-
const vnodeKey = getVnodeKey(vnode)
|
|
48
45
|
const router = global.__mpxRouter
|
|
49
|
-
if (
|
|
46
|
+
if (router) {
|
|
47
|
+
// 存在routeCount的情况下修改vnode.key避免patch时复用旧节点实例
|
|
48
|
+
if (router.currentRoute.query.routeCount) vnode.key = router.currentRoute.query.routeCount
|
|
49
|
+
const vnodeKey = getVnodeKey(vnode)
|
|
50
50
|
if (router.needCache) {
|
|
51
51
|
router.needCache.vnode = vnode
|
|
52
|
-
router.needCache.vnodeKey = vnodeKey
|
|
53
52
|
router.needCache = null
|
|
54
53
|
}
|
|
55
54
|
|
|
@@ -69,25 +68,17 @@
|
|
|
69
68
|
|
|
70
69
|
const stack = router.stack
|
|
71
70
|
if (stack.length) {
|
|
72
|
-
//
|
|
71
|
+
// 只要历史栈缓存中存在对应的页面存活实例且vnodeKey相同,就进行复用
|
|
73
72
|
for (let i = stack.length; i > 0; i--) {
|
|
74
73
|
const current = stack[i - 1]
|
|
75
|
-
if (current.vnode && current.
|
|
74
|
+
if (current.vnode && getVnodeKey(current.vnode) === vnodeKey && current.vnode.componentInstance) {
|
|
76
75
|
vnode.componentInstance = current.vnode.componentInstance
|
|
77
|
-
// 避免组件实例复用但是vnode.key不一致带来的bad case
|
|
78
|
-
vnode.key = current.vnode.key
|
|
79
76
|
break
|
|
80
77
|
}
|
|
81
78
|
}
|
|
82
79
|
}
|
|
83
80
|
|
|
84
|
-
if (router.__mpxAction)
|
|
85
|
-
if (router.__mpxAction.type === 'reLaunch') {
|
|
86
|
-
// reLaunch时修改新vnode的key, 确保任何情况下都新创建组件实例
|
|
87
|
-
vnode.key = (vnode.key || '') + router.__mpxAction.reLaunchCount
|
|
88
|
-
}
|
|
89
|
-
router.__mpxAction = null
|
|
90
|
-
}
|
|
81
|
+
if (router.__mpxAction) router.__mpxAction = null
|
|
91
82
|
vnode.data.keepAlive = true
|
|
92
83
|
}
|
|
93
84
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module.exports = (loaders, loaderIndex) => {
|
|
2
2
|
for (let i = loaderIndex; i >= 0; i--) {
|
|
3
3
|
const currentLoader = loaders[i]
|
|
4
|
-
if (currentLoader.path.endsWith('ts-loader/dist/stringify-loader.js')) {
|
|
4
|
+
if (currentLoader.path.endsWith('node_modules/ts-loader/dist/stringify-loader.js')) {
|
|
5
5
|
return i
|
|
6
6
|
}
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.46",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -82,5 +82,5 @@
|
|
|
82
82
|
"engines": {
|
|
83
83
|
"node": ">=14.14.0"
|
|
84
84
|
},
|
|
85
|
-
"gitHead": "
|
|
85
|
+
"gitHead": "dcf6f000660d56207ff414cb776e8bc6d5ce651f"
|
|
86
86
|
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
const camelCase = require('lodash.camelcase')
|
|
2
|
-
|
|
3
|
-
function dashesCamelCase (str) {
|
|
4
|
-
return str.replace(/-+(\w)/g, function (match, firstLetter) {
|
|
5
|
-
return firstLetter.toUpperCase()
|
|
6
|
-
})
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
module.exports = function compileExports (result, importItemMatcher, camelCaseKeys) {
|
|
10
|
-
if (!Object.keys(result.exports).length) {
|
|
11
|
-
return ''
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const exportJs = Object.keys(result.exports).reduce(function (res, key) {
|
|
15
|
-
let valueAsString = JSON.stringify(result.exports[key])
|
|
16
|
-
valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher)
|
|
17
|
-
|
|
18
|
-
function addEntry (k) {
|
|
19
|
-
res.push('\t' + JSON.stringify(k) + ': ' + valueAsString)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
let targetKey
|
|
23
|
-
switch (camelCaseKeys) {
|
|
24
|
-
case true:
|
|
25
|
-
addEntry(key)
|
|
26
|
-
targetKey = camelCase(key)
|
|
27
|
-
if (targetKey !== key) {
|
|
28
|
-
addEntry(targetKey)
|
|
29
|
-
}
|
|
30
|
-
break
|
|
31
|
-
case 'dashes':
|
|
32
|
-
addEntry(key)
|
|
33
|
-
targetKey = dashesCamelCase(key)
|
|
34
|
-
if (targetKey !== key) {
|
|
35
|
-
addEntry(targetKey)
|
|
36
|
-
}
|
|
37
|
-
break
|
|
38
|
-
case 'only':
|
|
39
|
-
addEntry(camelCase(key))
|
|
40
|
-
break
|
|
41
|
-
case 'dashesOnly':
|
|
42
|
-
addEntry(dashesCamelCase(key))
|
|
43
|
-
break
|
|
44
|
-
default:
|
|
45
|
-
addEntry(key)
|
|
46
|
-
break
|
|
47
|
-
}
|
|
48
|
-
return res
|
|
49
|
-
}, []).join(',\n')
|
|
50
|
-
|
|
51
|
-
return '{\n' + exportJs + '\n}'
|
|
52
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
module.exports = function createResolver (alias) {
|
|
2
|
-
if (typeof alias !== 'object' || Array.isArray(alias)) {
|
|
3
|
-
return function (url) {
|
|
4
|
-
return url
|
|
5
|
-
}
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
alias = Object.keys(alias).map(function (key) {
|
|
9
|
-
let onlyModule = false
|
|
10
|
-
let obj = alias[key]
|
|
11
|
-
if (/\$$/.test(key)) {
|
|
12
|
-
onlyModule = true
|
|
13
|
-
key = key.substr(0, key.length - 1)
|
|
14
|
-
}
|
|
15
|
-
if (typeof obj === 'string') {
|
|
16
|
-
obj = {
|
|
17
|
-
alias: obj
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
obj = Object.assign({
|
|
21
|
-
name: key,
|
|
22
|
-
onlyModule: onlyModule
|
|
23
|
-
}, obj)
|
|
24
|
-
return obj
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
return function (url) {
|
|
28
|
-
alias.forEach(function (obj) {
|
|
29
|
-
const name = obj.name
|
|
30
|
-
if (url === name || (!obj.onlyModule && url.startsWith(name + '/'))) {
|
|
31
|
-
url = obj.alias + url.substr(name.length)
|
|
32
|
-
}
|
|
33
|
-
})
|
|
34
|
-
return url
|
|
35
|
-
}
|
|
36
|
-
}
|
package/lib/wxss/css-base.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
Modified by @hiyuki
|
|
5
|
-
*/
|
|
6
|
-
// css base code, injected by the css-loader
|
|
7
|
-
module.exports = function (useSourceMap) {
|
|
8
|
-
const list = []
|
|
9
|
-
|
|
10
|
-
// return the list of modules as css string
|
|
11
|
-
list.toString = function toString () {
|
|
12
|
-
return this.map(function (item) {
|
|
13
|
-
const content = cssWithMappingToString(item, useSourceMap)
|
|
14
|
-
if (item[2]) {
|
|
15
|
-
return '@media ' + item[2] + '{' + content + '}'
|
|
16
|
-
} else {
|
|
17
|
-
return content
|
|
18
|
-
}
|
|
19
|
-
}).join('')
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// import a list of modules into the list
|
|
23
|
-
list.i = function (modules, mediaQuery) {
|
|
24
|
-
if (typeof modules === 'string') {
|
|
25
|
-
modules = [[null, modules, '']]
|
|
26
|
-
}
|
|
27
|
-
const alreadyImportedModules = {}
|
|
28
|
-
for (let i = 0; i < this.length; i++) {
|
|
29
|
-
const id = this[i][0]
|
|
30
|
-
if (typeof id === 'number') {
|
|
31
|
-
alreadyImportedModules[id] = true
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
for (let i = 0; i < modules.length; i++) {
|
|
35
|
-
const item = modules[i]
|
|
36
|
-
// skip already imported module
|
|
37
|
-
// this implementation is not 100% perfect for weird media query combinations
|
|
38
|
-
// when a module is imported multiple times with different media queries.
|
|
39
|
-
// I hope this will never occur (Hey this way we have smaller bundles)
|
|
40
|
-
if (typeof item[0] !== 'number' || !alreadyImportedModules[item[0]]) {
|
|
41
|
-
if (mediaQuery && !item[2]) {
|
|
42
|
-
item[2] = mediaQuery
|
|
43
|
-
} else if (mediaQuery) {
|
|
44
|
-
item[2] = '(' + item[2] + ') and (' + mediaQuery + ')'
|
|
45
|
-
}
|
|
46
|
-
list.push(item)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return list
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function cssWithMappingToString (item, useSourceMap) {
|
|
54
|
-
const content = item[1] || ''
|
|
55
|
-
const cssMapping = item[3]
|
|
56
|
-
if (!cssMapping) {
|
|
57
|
-
return content
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (useSourceMap && typeof btoa === 'function') {
|
|
61
|
-
const sourceMapping = toComment(cssMapping)
|
|
62
|
-
const sourceURLs = cssMapping.sources.map(function (source) {
|
|
63
|
-
return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
return [content].concat(sourceURLs).concat([sourceMapping]).join('\n')
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
return [content].join('\n')
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Adapted from convert-source-map (MIT)
|
|
73
|
-
function toComment (sourceMap) {
|
|
74
|
-
// eslint-disable-next-line no-undef
|
|
75
|
-
const base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))))
|
|
76
|
-
const data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64
|
|
77
|
-
|
|
78
|
-
return '/*# ' + data + ' */'
|
|
79
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
Modified by @hiyuki
|
|
5
|
-
*/
|
|
6
|
-
const loaderUtils = require('loader-utils')
|
|
7
|
-
const path = require('path')
|
|
8
|
-
|
|
9
|
-
module.exports = function getLocalIdent (loaderContext, localIdentName, localName, options) {
|
|
10
|
-
if (!options.context) {
|
|
11
|
-
if (loaderContext.rootContext) {
|
|
12
|
-
options.context = loaderContext.rootContext
|
|
13
|
-
} else if (loaderContext.options && typeof loaderContext.options.context === 'string') {
|
|
14
|
-
options.context = loaderContext.options.context
|
|
15
|
-
} else {
|
|
16
|
-
options.context = loaderContext.context
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
const request = path.relative(options.context, loaderContext.resourcePath)
|
|
20
|
-
options.content = options.hashPrefix + request + '+' + localName
|
|
21
|
-
localIdentName = localIdentName.replace(/\[local\]/gi, localName)
|
|
22
|
-
const hash = loaderUtils.interpolateName(loaderContext, localIdentName, options)
|
|
23
|
-
/* eslint-disable prefer-regex-literals */
|
|
24
|
-
return hash.replace(new RegExp('[^a-zA-Z0-9\\-_\u00A0-\uFFFF]', 'g'), '-').replace(/^((-?[0-9])|--)/, '_$1')
|
|
25
|
-
}
|
package/lib/wxss/localsLoader.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
Modified by @hiyuki
|
|
5
|
-
*/
|
|
6
|
-
const loaderUtils = require('loader-utils')
|
|
7
|
-
const processCss = require('./processCss')
|
|
8
|
-
const compileExports = require('./compile-exports')
|
|
9
|
-
const createResolver = require('./createResolver')
|
|
10
|
-
|
|
11
|
-
module.exports = function (content) {
|
|
12
|
-
if (this.cacheable) this.cacheable()
|
|
13
|
-
const callback = this.async()
|
|
14
|
-
const query = loaderUtils.getOptions(this) || {}
|
|
15
|
-
const moduleMode = query.modules || query.module
|
|
16
|
-
const camelCaseKeys = query.camelCase || query.camelcase
|
|
17
|
-
const resolve = createResolver(query.alias)
|
|
18
|
-
|
|
19
|
-
processCss(content, null, {
|
|
20
|
-
mode: moduleMode ? 'local' : 'global',
|
|
21
|
-
query: query,
|
|
22
|
-
minimize: this.minimize,
|
|
23
|
-
loaderContext: this,
|
|
24
|
-
resolve: resolve
|
|
25
|
-
}, function (err, result) {
|
|
26
|
-
if (err) return callback(err)
|
|
27
|
-
|
|
28
|
-
function importItemMatcher (item) {
|
|
29
|
-
const match = result.importItemRegExp.exec(item)
|
|
30
|
-
const idx = +match[1]
|
|
31
|
-
const importItem = result.importItems[idx]
|
|
32
|
-
const importUrl = importItem.url
|
|
33
|
-
return '" + require(' + loaderUtils.stringifyRequest(this, importUrl) + ')' +
|
|
34
|
-
'[' + JSON.stringify(importItem.export) + '] + "'
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
let exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys)
|
|
38
|
-
if (exportJs) {
|
|
39
|
-
exportJs = 'module.exports = ' + exportJs + ';'
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
callback(null, exportJs)
|
|
43
|
-
}.bind(this))
|
|
44
|
-
}
|
package/lib/wxss/processCss.js
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
Modified by @hiyuki
|
|
5
|
-
*/
|
|
6
|
-
const formatCodeFrame = require('@babel/code-frame')
|
|
7
|
-
const Tokenizer = require('css-selector-tokenizer')
|
|
8
|
-
const postcss = require('postcss')
|
|
9
|
-
const loaderUtils = require('loader-utils')
|
|
10
|
-
const assign = require('object-assign')
|
|
11
|
-
const getLocalIdent = require('./getLocalIdent')
|
|
12
|
-
|
|
13
|
-
const icssUtils = require('icss-utils')
|
|
14
|
-
const localByDefault = require('postcss-modules-local-by-default')
|
|
15
|
-
const extractImports = require('postcss-modules-extract-imports')
|
|
16
|
-
const modulesScope = require('postcss-modules-scope')
|
|
17
|
-
const modulesValues = require('postcss-modules-values')
|
|
18
|
-
const valueParser = require('postcss-value-parser')
|
|
19
|
-
const isUrlRequest = require('../utils/is-url-request')
|
|
20
|
-
// css-loader-parser
|
|
21
|
-
|
|
22
|
-
const parserPlugin = function (options) {
|
|
23
|
-
return {
|
|
24
|
-
postcssPlugin: 'css-loader-parser',
|
|
25
|
-
Once (css) {
|
|
26
|
-
const imports = {}
|
|
27
|
-
let exports = {}
|
|
28
|
-
const importItems = []
|
|
29
|
-
const urlItems = []
|
|
30
|
-
|
|
31
|
-
function replaceImportsInString (str) {
|
|
32
|
-
if (options.import) {
|
|
33
|
-
const tokens = valueParser(str)
|
|
34
|
-
tokens.walk(function (node) {
|
|
35
|
-
if (node.type !== 'word') {
|
|
36
|
-
return
|
|
37
|
-
}
|
|
38
|
-
const token = node.value
|
|
39
|
-
const importIndex = imports['$' + token]
|
|
40
|
-
if (typeof importIndex === 'number') {
|
|
41
|
-
node.value = '___CSS_LOADER_IMPORT___' + importIndex + '___'
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
return tokens.toString()
|
|
45
|
-
}
|
|
46
|
-
return str
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (options.import) {
|
|
50
|
-
css.walkAtRules(/^import$/i, function (rule) {
|
|
51
|
-
const values = Tokenizer.parseValues(rule.params)
|
|
52
|
-
let url = values.nodes[0].nodes[0]
|
|
53
|
-
if (url && url.type === 'url') {
|
|
54
|
-
url = url.url
|
|
55
|
-
} else if (url && url.type === 'string') {
|
|
56
|
-
url = url.value
|
|
57
|
-
} else throw rule.error('Unexpected format ' + rule.params)
|
|
58
|
-
if (!url.replace(/\s/g, '').length) {
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
values.nodes[0].nodes.shift()
|
|
62
|
-
const mediaQuery = Tokenizer.stringifyValues(values)
|
|
63
|
-
|
|
64
|
-
if (isUrlRequest(url, options.root)) {
|
|
65
|
-
url = loaderUtils.urlToRequest(url, options.root)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
importItems.push({
|
|
69
|
-
url: url,
|
|
70
|
-
mediaQuery: mediaQuery
|
|
71
|
-
})
|
|
72
|
-
rule.remove()
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const icss = icssUtils.extractICSS(css)
|
|
77
|
-
exports = icss.icssExports
|
|
78
|
-
Object.keys(icss.icssImports).forEach(function (key) {
|
|
79
|
-
const url = loaderUtils.parseString(key)
|
|
80
|
-
Object.keys(icss.icssImports[key]).forEach(function (prop) {
|
|
81
|
-
imports['$' + prop] = importItems.length
|
|
82
|
-
importItems.push({
|
|
83
|
-
url: url,
|
|
84
|
-
export: icss.icssImports[key][prop]
|
|
85
|
-
})
|
|
86
|
-
})
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
Object.keys(exports).forEach(function (exportName) {
|
|
90
|
-
exports[exportName] = replaceImportsInString(exports[exportName])
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
function isAlias (url) {
|
|
94
|
-
// Handle alias starting by / and root disabled
|
|
95
|
-
return url !== options.resolve(url)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function processNode (item) {
|
|
99
|
-
switch (item.type) {
|
|
100
|
-
case 'value':
|
|
101
|
-
item.nodes.forEach(processNode)
|
|
102
|
-
break
|
|
103
|
-
case 'nested-item':
|
|
104
|
-
item.nodes.forEach(processNode)
|
|
105
|
-
break
|
|
106
|
-
case 'item': {
|
|
107
|
-
const importIndex = imports['$' + item.name]
|
|
108
|
-
if (typeof importIndex === 'number') {
|
|
109
|
-
item.name = '___CSS_LOADER_IMPORT___' + importIndex + '___'
|
|
110
|
-
}
|
|
111
|
-
break
|
|
112
|
-
}
|
|
113
|
-
case 'url':
|
|
114
|
-
if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && (isAlias(item.url) || isUrlRequest(item.url, options.root))) {
|
|
115
|
-
// Strip quotes, they will be re-added if the module needs them
|
|
116
|
-
item.stringType = ''
|
|
117
|
-
delete item.innerSpacingBefore
|
|
118
|
-
delete item.innerSpacingAfter
|
|
119
|
-
const url = item.url
|
|
120
|
-
item.url = '___CSS_LOADER_URL___' + urlItems.length + '___'
|
|
121
|
-
urlItems.push({
|
|
122
|
-
url: url
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
break
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
css.walkDecls(function (decl) {
|
|
130
|
-
const values = Tokenizer.parseValues(decl.value)
|
|
131
|
-
values.nodes.forEach(function (value) {
|
|
132
|
-
value.nodes.forEach(processNode)
|
|
133
|
-
})
|
|
134
|
-
decl.value = Tokenizer.stringifyValues(values)
|
|
135
|
-
})
|
|
136
|
-
css.walkAtRules(function (atrule) {
|
|
137
|
-
if (typeof atrule.params === 'string') {
|
|
138
|
-
atrule.params = replaceImportsInString(atrule.params)
|
|
139
|
-
}
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
options.importItems = importItems
|
|
143
|
-
options.urlItems = urlItems
|
|
144
|
-
options.exports = exports
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
module.exports = function processCss (inputSource, inputMap, options, callback) {
|
|
150
|
-
const query = options.query
|
|
151
|
-
const root = query.root && query.root.length > 0 ? query.root.replace(/\/$/, '') : query.root
|
|
152
|
-
const context = query.context
|
|
153
|
-
const localIdentName = query.localIdentName || '[hash:base64]'
|
|
154
|
-
const localIdentRegExp = query.localIdentRegExp
|
|
155
|
-
const forceMinimize = query.minimize
|
|
156
|
-
const minimize = typeof forceMinimize !== 'undefined' ? !!forceMinimize : options.minimize
|
|
157
|
-
|
|
158
|
-
const customGetLocalIdent = query.getLocalIdent || getLocalIdent
|
|
159
|
-
|
|
160
|
-
const parserOptions = {
|
|
161
|
-
root: root,
|
|
162
|
-
mode: options.mode,
|
|
163
|
-
url: query.url !== false,
|
|
164
|
-
import: query.import !== false,
|
|
165
|
-
resolve: options.resolve
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
const pipeline = postcss([
|
|
169
|
-
modulesValues,
|
|
170
|
-
localByDefault({
|
|
171
|
-
mode: options.mode,
|
|
172
|
-
rewriteUrl: function (global, url) {
|
|
173
|
-
if (parserOptions.url) {
|
|
174
|
-
url = url.trim()
|
|
175
|
-
|
|
176
|
-
if (!url.replace(/\s/g, '').length || !isUrlRequest(url, root)) {
|
|
177
|
-
return url
|
|
178
|
-
}
|
|
179
|
-
if (global) {
|
|
180
|
-
return loaderUtils.urlToRequest(url, root)
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
return url
|
|
184
|
-
}
|
|
185
|
-
}),
|
|
186
|
-
extractImports(),
|
|
187
|
-
modulesScope({
|
|
188
|
-
generateScopedName: function generateScopedName (exportName) {
|
|
189
|
-
return customGetLocalIdent(options.loaderContext, localIdentName, exportName, {
|
|
190
|
-
regExp: localIdentRegExp,
|
|
191
|
-
hashPrefix: query.hashPrefix || '',
|
|
192
|
-
context: context
|
|
193
|
-
})
|
|
194
|
-
}
|
|
195
|
-
}),
|
|
196
|
-
parserPlugin(parserOptions)
|
|
197
|
-
])
|
|
198
|
-
|
|
199
|
-
if (minimize) {
|
|
200
|
-
const cssnano = require('cssnano')
|
|
201
|
-
const minimizeOptions = assign({}, query.minimize);
|
|
202
|
-
['zindex', 'normalizeUrl', 'discardUnused', 'mergeIdents', 'reduceIdents', 'autoprefixer', 'svgo'].forEach(function (name) {
|
|
203
|
-
if (typeof minimizeOptions[name] === 'undefined') {
|
|
204
|
-
minimizeOptions[name] = false
|
|
205
|
-
}
|
|
206
|
-
})
|
|
207
|
-
pipeline.use(cssnano(minimizeOptions))
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
pipeline.process(inputSource, {
|
|
211
|
-
// we need a prefix to avoid path rewriting of PostCSS
|
|
212
|
-
from: '/css-loader!' + options.from,
|
|
213
|
-
to: options.to,
|
|
214
|
-
map: options.sourceMap
|
|
215
|
-
? {
|
|
216
|
-
prev: inputMap,
|
|
217
|
-
sourcesContent: true,
|
|
218
|
-
inline: false,
|
|
219
|
-
annotation: false
|
|
220
|
-
}
|
|
221
|
-
: null
|
|
222
|
-
}).then(function (result) {
|
|
223
|
-
callback(null, {
|
|
224
|
-
source: result.css,
|
|
225
|
-
map: result.map && result.map.toJSON(),
|
|
226
|
-
exports: parserOptions.exports,
|
|
227
|
-
importItems: parserOptions.importItems,
|
|
228
|
-
importItemRegExpG: /___CSS_LOADER_IMPORT___([0-9]+)___/g,
|
|
229
|
-
importItemRegExp: /___CSS_LOADER_IMPORT___([0-9]+)___/,
|
|
230
|
-
urlItems: parserOptions.urlItems,
|
|
231
|
-
urlItemRegExpG: /___CSS_LOADER_URL___([0-9]+)___/g,
|
|
232
|
-
urlItemRegExp: /___CSS_LOADER_URL___([0-9]+)___/
|
|
233
|
-
})
|
|
234
|
-
}).catch(function (err) {
|
|
235
|
-
if (err.name === 'CssSyntaxError') {
|
|
236
|
-
const wrappedError = new CSSLoaderError(
|
|
237
|
-
'Syntax Error',
|
|
238
|
-
err.reason,
|
|
239
|
-
err.line != null && err.column != null
|
|
240
|
-
? { line: err.line, column: err.column }
|
|
241
|
-
: null,
|
|
242
|
-
err.input.source
|
|
243
|
-
)
|
|
244
|
-
callback(wrappedError)
|
|
245
|
-
} else {
|
|
246
|
-
callback(err)
|
|
247
|
-
}
|
|
248
|
-
})
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
function formatMessage (message, loc, source) {
|
|
252
|
-
let formatted = message
|
|
253
|
-
if (loc) {
|
|
254
|
-
formatted = formatted +
|
|
255
|
-
' (' + loc.line + ':' + loc.column + ')'
|
|
256
|
-
}
|
|
257
|
-
if (loc && source) {
|
|
258
|
-
formatted = formatted +
|
|
259
|
-
'\n\n' + formatCodeFrame(source, loc.line, loc.column) + '\n'
|
|
260
|
-
}
|
|
261
|
-
return formatted
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function CSSLoaderError (name, message, loc, source, error) {
|
|
265
|
-
Error.call(this)
|
|
266
|
-
Error.captureStackTrace(this, CSSLoaderError)
|
|
267
|
-
this.name = name
|
|
268
|
-
this.error = error
|
|
269
|
-
this.message = formatMessage(message, loc, source)
|
|
270
|
-
this.message = formatMessage(message, loc, source)
|
|
271
|
-
}
|
|
272
|
-
|
|
273
|
-
CSSLoaderError.prototype = Object.create(Error.prototype)
|
|
274
|
-
CSSLoaderError.prototype.constructor = CSSLoaderError
|