@mpxjs/webpack-plugin 2.7.1-beta.8 → 2.7.3
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/dependencies/RecordResourceMapDependency.js +1 -0
- package/lib/extractor.js +2 -1
- package/lib/index.js +56 -32
- package/lib/json-compiler/helper.js +1 -1
- package/lib/loader.js +1 -1
- package/lib/runtime/components/web/mpx-swiper.vue +18 -3
- package/lib/runtime/stringify.wxs +3 -1
- package/lib/style-compiler/plugins/conditional-strip.js +68 -65
- package/lib/style-compiler/plugins/rpx.js +43 -37
- package/lib/style-compiler/plugins/scope-id.js +79 -72
- package/lib/style-compiler/plugins/trans-special.js +25 -18
- package/lib/style-compiler/plugins/trim.js +13 -7
- package/lib/style-compiler/plugins/vw.js +22 -16
- package/lib/template-compiler/compiler.js +3 -1
- package/lib/template-compiler/index.js +2 -1
- package/lib/template-compiler/trans-dynamic-class-expr.js +25 -20
- package/lib/web/processTemplate.js +1 -1
- package/lib/wxs/WxsModuleIdsPlugin.js +11 -14
- package/lib/wxss/loader.js +2 -2
- package/lib/wxss/processCss.js +107 -103
- package/package.json +11 -11
package/lib/extractor.js
CHANGED
package/lib/index.js
CHANGED
|
@@ -566,7 +566,7 @@ class MpxWebpackPlugin {
|
|
|
566
566
|
const hash = mpx.pathHash(resourcePath)
|
|
567
567
|
const customOutputPath = this.options.customOutputPath
|
|
568
568
|
if (conflictPath) return conflictPath.replace(/(\.[^\\/]+)?$/, match => hash + match)
|
|
569
|
-
if (typeof customOutputPath === 'function') return customOutputPath(type, name, hash, ext)
|
|
569
|
+
if (typeof customOutputPath === 'function') return customOutputPath(type, name, hash, ext).replace(/^\//, '')
|
|
570
570
|
if (type === 'component' || type === 'page') return path.join(type + 's', name + hash, 'index' + ext)
|
|
571
571
|
return path.join(type, name + hash + ext)
|
|
572
572
|
},
|
|
@@ -597,25 +597,28 @@ class MpxWebpackPlugin {
|
|
|
597
597
|
mpx.extractedFilesCache.set(resource, file)
|
|
598
598
|
return file
|
|
599
599
|
},
|
|
600
|
-
recordResourceMap: ({ resourcePath, resourceType, outputPath, packageRoot = '', warn, error }) => {
|
|
600
|
+
recordResourceMap: ({ resourcePath, resourceType, outputPath, packageRoot = '', recordOnly, warn, error }) => {
|
|
601
601
|
const packageName = packageRoot || 'main'
|
|
602
602
|
const resourceMap = mpx[`${resourceType}sMap`] || mpx.otherResourcesMap
|
|
603
603
|
const currentResourceMap = resourceMap.main ? resourceMap[packageName] = resourceMap[packageName] || {} : resourceMap
|
|
604
|
+
let alreadyOutputted = false
|
|
604
605
|
if (outputPath) {
|
|
605
606
|
if (!currentResourceMap[resourcePath] || currentResourceMap[resourcePath] === true) {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
607
|
+
if (!recordOnly) {
|
|
608
|
+
// 在非recordOnly的模式下,进行输出路径冲突检测,如果存在输出路径冲突,则对输出路径进行重命名
|
|
609
|
+
for (let key in currentResourceMap) {
|
|
610
|
+
// todo 用outputPathMap来检测输出路径冲突
|
|
611
|
+
if (currentResourceMap[key] === outputPath && key !== resourcePath) {
|
|
612
|
+
outputPath = mpx.getOutputPath(resourcePath, resourceType, { conflictPath: outputPath })
|
|
613
|
+
warn && warn(new Error(`Current ${resourceType} [${resourcePath}] is registered with conflicted outputPath [${currentResourceMap[key]}] which is already existed in system, will be renamed with [${outputPath}], use ?resolve to get the real outputPath!`))
|
|
614
|
+
break
|
|
615
|
+
}
|
|
613
616
|
}
|
|
614
617
|
}
|
|
615
618
|
currentResourceMap[resourcePath] = outputPath
|
|
616
619
|
} else {
|
|
617
620
|
if (currentResourceMap[resourcePath] === outputPath) {
|
|
618
|
-
|
|
621
|
+
alreadyOutputted = true
|
|
619
622
|
} else {
|
|
620
623
|
error && error(new Error(`Current ${resourceType} [${resourcePath}] is already registered with outputPath [${currentResourceMap[resourcePath]}], you can not register it with another outputPath [${outputPath}]!`))
|
|
621
624
|
}
|
|
@@ -623,7 +626,11 @@ class MpxWebpackPlugin {
|
|
|
623
626
|
} else if (!currentResourceMap[resourcePath]) {
|
|
624
627
|
currentResourceMap[resourcePath] = true
|
|
625
628
|
}
|
|
626
|
-
|
|
629
|
+
|
|
630
|
+
return {
|
|
631
|
+
outputPath,
|
|
632
|
+
alreadyOutputted
|
|
633
|
+
}
|
|
627
634
|
},
|
|
628
635
|
// 组件和静态资源的输出规则如下:
|
|
629
636
|
// 1. 主包引用的资源输出至主包
|
|
@@ -675,20 +682,18 @@ class MpxWebpackPlugin {
|
|
|
675
682
|
|
|
676
683
|
if (outputPath) outputPath = toPosix(path.join(packageRoot, outputPath))
|
|
677
684
|
|
|
678
|
-
const alreadyOutputted = mpx.recordResourceMap({
|
|
679
|
-
resourcePath,
|
|
680
|
-
resourceType,
|
|
681
|
-
outputPath,
|
|
682
|
-
packageRoot,
|
|
683
|
-
warn,
|
|
684
|
-
error
|
|
685
|
-
})
|
|
686
|
-
|
|
687
685
|
return {
|
|
688
686
|
packageName,
|
|
689
687
|
packageRoot,
|
|
690
|
-
outputPath
|
|
691
|
-
|
|
688
|
+
// 返回outputPath及alreadyOutputted
|
|
689
|
+
...mpx.recordResourceMap({
|
|
690
|
+
resourcePath,
|
|
691
|
+
resourceType,
|
|
692
|
+
outputPath,
|
|
693
|
+
packageRoot,
|
|
694
|
+
warn,
|
|
695
|
+
error
|
|
696
|
+
})
|
|
692
697
|
}
|
|
693
698
|
}
|
|
694
699
|
}
|
|
@@ -763,12 +768,13 @@ class MpxWebpackPlugin {
|
|
|
763
768
|
}
|
|
764
769
|
}
|
|
765
770
|
} else if (independent) {
|
|
766
|
-
// ContextModule和
|
|
771
|
+
// ContextModule/RawModule和ExternalModule等只在独立分包的情况下添加分包标记,其余默认不添加
|
|
767
772
|
const postfix = `|independent=${independent}|${currentPackageRoot}`
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
773
|
+
const rawIdentifier = module.identifier
|
|
774
|
+
if (rawIdentifier) {
|
|
775
|
+
module.identifier = () => {
|
|
776
|
+
return rawIdentifier.call(module) + postfix
|
|
777
|
+
}
|
|
772
778
|
}
|
|
773
779
|
}
|
|
774
780
|
return rawAddModule.call(compilation, module, callback)
|
|
@@ -832,6 +838,23 @@ class MpxWebpackPlugin {
|
|
|
832
838
|
mpx.assetsModulesMap.set(filename, modules)
|
|
833
839
|
})
|
|
834
840
|
|
|
841
|
+
const fillExtractedAssetsMap = (assetsMap, { index, content }, filename) => {
|
|
842
|
+
if (assetsMap.has(index)) {
|
|
843
|
+
if (assetsMap.get(index) !== content) {
|
|
844
|
+
compilation.errors.push(new Error(`The extracted file [${filename}] is filled with same index [${index}] and different content:
|
|
845
|
+
old content: ${assetsMap.get(index)}
|
|
846
|
+
new content: ${content}
|
|
847
|
+
please check!`))
|
|
848
|
+
}
|
|
849
|
+
} else {
|
|
850
|
+
assetsMap.set(index, content)
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
|
|
854
|
+
const sortExtractedAssetsMap = (assetsMap) => {
|
|
855
|
+
return [...assetsMap.entries()].sort((a, b) => a[0] - b[0]).map(item => item[1])
|
|
856
|
+
}
|
|
857
|
+
|
|
835
858
|
compilation.hooks.beforeModuleAssets.tap('MpxWebpackPlugin', () => {
|
|
836
859
|
const extractedAssetsMap = new Map()
|
|
837
860
|
for (const module of compilation.modules) {
|
|
@@ -840,19 +863,19 @@ class MpxWebpackPlugin {
|
|
|
840
863
|
if (extractedInfo) {
|
|
841
864
|
let extractedAssets = extractedAssetsMap.get(filename)
|
|
842
865
|
if (!extractedAssets) {
|
|
843
|
-
extractedAssets = []
|
|
866
|
+
extractedAssets = [new Map(), new Map()]
|
|
844
867
|
extractedAssetsMap.set(filename, extractedAssets)
|
|
845
868
|
}
|
|
846
|
-
|
|
869
|
+
fillExtractedAssetsMap(extractedInfo.pre ? extractedAssets[0] : extractedAssets[1], extractedInfo, filename)
|
|
847
870
|
compilation.hooks.moduleAsset.call(module, filename)
|
|
848
871
|
}
|
|
849
872
|
}
|
|
850
873
|
}
|
|
851
874
|
|
|
852
|
-
for (const [filename,
|
|
853
|
-
const sortedExtractedAssets =
|
|
875
|
+
for (const [filename, [pre, normal]] of extractedAssetsMap) {
|
|
876
|
+
const sortedExtractedAssets = [...sortExtractedAssetsMap(pre), ...sortExtractedAssetsMap(normal)]
|
|
854
877
|
const source = new ConcatSource()
|
|
855
|
-
sortedExtractedAssets.forEach((
|
|
878
|
+
sortedExtractedAssets.forEach((content) => {
|
|
856
879
|
if (content) {
|
|
857
880
|
// 处理replace path
|
|
858
881
|
if (/"mpx_replace_path_.*?"/.test(content)) {
|
|
@@ -1338,6 +1361,7 @@ try {
|
|
|
1338
1361
|
const fs = compiler.intermediateFileSystem
|
|
1339
1362
|
const cacheLocation = compiler.options.cache.cacheLocation
|
|
1340
1363
|
return new Promise((resolve) => {
|
|
1364
|
+
if (!cacheLocation) return resolve()
|
|
1341
1365
|
if (typeof fs.rm === 'function') {
|
|
1342
1366
|
fs.rm(cacheLocation, {
|
|
1343
1367
|
recursive: true,
|
|
@@ -97,7 +97,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
|
|
|
97
97
|
const ext = path.extname(resourcePath)
|
|
98
98
|
let outputPath
|
|
99
99
|
if (aliasPath) {
|
|
100
|
-
outputPath = aliasPath
|
|
100
|
+
outputPath = aliasPath.replace(/^\//, '')
|
|
101
101
|
} else {
|
|
102
102
|
const relative = path.relative(context, resourcePath)
|
|
103
103
|
if (/^\./.test(relative)) {
|
package/lib/loader.js
CHANGED
|
@@ -51,7 +51,7 @@ module.exports = function (content) {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// 支持资源query传入isPage或isComponent支持页面/组件单独编译
|
|
54
|
-
if (queryObj.isComponent || queryObj.isPage) {
|
|
54
|
+
if (ctorType === 'app' && (queryObj.isComponent || queryObj.isPage)) {
|
|
55
55
|
const entryName = getEntryName(this) || (queryObj.isComponent ? 'noEntryComponent' : 'noEntryPage')
|
|
56
56
|
ctorType = queryObj.isComponent ? 'component' : 'page'
|
|
57
57
|
this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, ctorType, entryName, packageRoot))
|
|
@@ -41,7 +41,9 @@
|
|
|
41
41
|
},
|
|
42
42
|
data () {
|
|
43
43
|
return {
|
|
44
|
-
currentIndex: this.current
|
|
44
|
+
currentIndex: this.current,
|
|
45
|
+
currentChildLength: 0,
|
|
46
|
+
lastChildLength: 0
|
|
45
47
|
}
|
|
46
48
|
},
|
|
47
49
|
computed: {
|
|
@@ -81,6 +83,9 @@
|
|
|
81
83
|
}
|
|
82
84
|
}
|
|
83
85
|
},
|
|
86
|
+
updated () {
|
|
87
|
+
this.currentChildLength = this.$children && this.$children.length
|
|
88
|
+
},
|
|
84
89
|
watch: {
|
|
85
90
|
current (val) {
|
|
86
91
|
if (this.bs) {
|
|
@@ -89,6 +94,15 @@
|
|
|
89
94
|
}
|
|
90
95
|
this.changeSource = ''
|
|
91
96
|
this.goto(val)
|
|
97
|
+
},
|
|
98
|
+
currentChildLength(val) {
|
|
99
|
+
if (val < this.lastChildLength && val < this.currentIndex) {
|
|
100
|
+
this.goto(0, 0)
|
|
101
|
+
}
|
|
102
|
+
if (this.lastChildLength || (!this.lastChildLength && !this.autoplay)) {
|
|
103
|
+
this.bs && this.bs.refresh()
|
|
104
|
+
}
|
|
105
|
+
this.lastChildLength = val
|
|
92
106
|
}
|
|
93
107
|
},
|
|
94
108
|
activated () {
|
|
@@ -167,10 +181,11 @@
|
|
|
167
181
|
refresh () {
|
|
168
182
|
this.bs && this.bs.refresh()
|
|
169
183
|
},
|
|
170
|
-
goto (index) {
|
|
184
|
+
goto (index, time) {
|
|
171
185
|
const x = this.vertical ? 0 : index
|
|
172
186
|
const y = this.vertical ? index : 0
|
|
173
|
-
|
|
187
|
+
const speed = time === 0 ? 0 : this.duration
|
|
188
|
+
this.bs && this.bs.goToPage(x, y, speed)
|
|
174
189
|
}
|
|
175
190
|
},
|
|
176
191
|
render (createElement) {
|
|
@@ -120,6 +120,8 @@ function stringifyArray (value) {
|
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
var mpxDashReg = genRegExp('(.+)MpxDash$')
|
|
123
|
+
// 转义字符在wxs正则中存在平台兼容性问题,用[$]规避使用转义字符
|
|
124
|
+
var mpxDashReplaceReg = genRegExp('[$]', 'g')
|
|
123
125
|
|
|
124
126
|
function stringifyObject (value) {
|
|
125
127
|
var res = ''
|
|
@@ -129,7 +131,7 @@ function stringifyObject (value) {
|
|
|
129
131
|
if (value[key]) {
|
|
130
132
|
if (res) res += ' '
|
|
131
133
|
if (mpxDashReg.test(key)) {
|
|
132
|
-
key =
|
|
134
|
+
key = mpxDashReg.exec(key)[1].replace(mpxDashReplaceReg, '-')
|
|
133
135
|
}
|
|
134
136
|
res += key
|
|
135
137
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
const postcss = require('postcss')
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* 按平台条件编译CSS,用法如下:
|
|
5
3
|
* @type {postcss.Plugin<any>}
|
|
@@ -44,7 +42,7 @@ const postcss = require('postcss')
|
|
|
44
42
|
// @mpx-endif
|
|
45
43
|
// */
|
|
46
44
|
// `
|
|
47
|
-
module.exports =
|
|
45
|
+
module.exports = (options = {}) => {
|
|
48
46
|
const { defs } = options
|
|
49
47
|
|
|
50
48
|
const defKeys = Object.keys(defs)
|
|
@@ -91,71 +89,76 @@ module.exports = postcss.plugin('conditional-strip', (options = {}) => {
|
|
|
91
89
|
return parseCondition(/@mpx-elif[^(]*?\(([\s\S]*)\)/, content)
|
|
92
90
|
}
|
|
93
91
|
|
|
94
|
-
return
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
return {
|
|
93
|
+
postcssPlugin: 'conditional-strip',
|
|
94
|
+
Once (root) {
|
|
95
|
+
const condsStacks = []
|
|
96
|
+
const currentConds = []
|
|
97
|
+
let curDepth = -1
|
|
98
98
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
})
|
|
115
|
-
currentConds[curDepth] = cond
|
|
116
|
-
} else if (isElseIf(text)) {
|
|
117
|
-
isKeyword = true
|
|
118
|
-
const cond = parseElseIf(text)
|
|
119
|
-
const parentCond = currentConds[curDepth - 1]
|
|
120
|
-
if (parentCond && parentCond.shouldRemove) {
|
|
121
|
-
cond.shouldRemove = true
|
|
122
|
-
}
|
|
123
|
-
cond.children.push(node)
|
|
124
|
-
condsStacks[curDepth].elif = cond
|
|
125
|
-
currentConds[curDepth] = cond
|
|
126
|
-
} else if (isElse(text)) {
|
|
127
|
-
isKeyword = true
|
|
128
|
-
const curConds = condsStacks[curDepth]
|
|
129
|
-
const cond = {
|
|
130
|
-
shouldRemove: !(curConds.if.shouldRemove && (!curConds.elif || curConds.elif.shouldRemove)),
|
|
131
|
-
children: [node]
|
|
132
|
-
}
|
|
133
|
-
const parentCond = currentConds[curDepth - 1]
|
|
134
|
-
if (parentCond && parentCond.shouldRemove) {
|
|
135
|
-
cond.shouldRemove = true
|
|
136
|
-
}
|
|
137
|
-
condsStacks[curDepth].else = cond
|
|
138
|
-
currentConds[curDepth] = cond
|
|
139
|
-
} else if (isEndIf(text)) {
|
|
140
|
-
isKeyword = true
|
|
141
|
-
const curConds = condsStacks.pop()
|
|
142
|
-
Object.keys(curConds).forEach(k => {
|
|
143
|
-
curConds[k].children.forEach(node => {
|
|
144
|
-
node.remove()
|
|
99
|
+
root.walk(node => {
|
|
100
|
+
let isKeyword = false
|
|
101
|
+
if (node.type === 'comment') {
|
|
102
|
+
const { text } = node
|
|
103
|
+
if (isIfStart(text)) {
|
|
104
|
+
isKeyword = true
|
|
105
|
+
const cond = parseIf(text)
|
|
106
|
+
curDepth++
|
|
107
|
+
const parentCond = currentConds[curDepth - 1]
|
|
108
|
+
if (parentCond && parentCond.shouldRemove) {
|
|
109
|
+
cond.shouldRemove = true
|
|
110
|
+
}
|
|
111
|
+
cond.children.push(node)
|
|
112
|
+
condsStacks.push({
|
|
113
|
+
if: cond
|
|
145
114
|
})
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
115
|
+
currentConds[curDepth] = cond
|
|
116
|
+
} else if (isElseIf(text)) {
|
|
117
|
+
isKeyword = true
|
|
118
|
+
const cond = parseElseIf(text)
|
|
119
|
+
const parentCond = currentConds[curDepth - 1]
|
|
120
|
+
if (parentCond && parentCond.shouldRemove) {
|
|
121
|
+
cond.shouldRemove = true
|
|
122
|
+
}
|
|
123
|
+
cond.children.push(node)
|
|
124
|
+
condsStacks[curDepth].elif = cond
|
|
125
|
+
currentConds[curDepth] = cond
|
|
126
|
+
} else if (isElse(text)) {
|
|
127
|
+
isKeyword = true
|
|
128
|
+
const curConds = condsStacks[curDepth]
|
|
129
|
+
const cond = {
|
|
130
|
+
shouldRemove: !(curConds.if.shouldRemove && (!curConds.elif || curConds.elif.shouldRemove)),
|
|
131
|
+
children: [node]
|
|
132
|
+
}
|
|
133
|
+
const parentCond = currentConds[curDepth - 1]
|
|
134
|
+
if (parentCond && parentCond.shouldRemove) {
|
|
135
|
+
cond.shouldRemove = true
|
|
136
|
+
}
|
|
137
|
+
condsStacks[curDepth].else = cond
|
|
138
|
+
currentConds[curDepth] = cond
|
|
139
|
+
} else if (isEndIf(text)) {
|
|
140
|
+
isKeyword = true
|
|
141
|
+
const curConds = condsStacks.pop()
|
|
142
|
+
Object.keys(curConds).forEach(k => {
|
|
143
|
+
curConds[k].children.forEach(node => {
|
|
144
|
+
node.remove()
|
|
145
|
+
})
|
|
146
|
+
})
|
|
147
|
+
currentConds.pop()
|
|
148
|
+
curDepth--
|
|
149
|
+
node.remove()
|
|
150
|
+
}
|
|
150
151
|
}
|
|
151
|
-
}
|
|
152
152
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
153
|
+
if (!isKeyword) {
|
|
154
|
+
const curCond = currentConds[curDepth]
|
|
155
|
+
if (curCond && curCond.shouldRemove) {
|
|
156
|
+
curCond.children.push(node)
|
|
157
|
+
}
|
|
157
158
|
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
159
|
+
})
|
|
160
|
+
}
|
|
160
161
|
}
|
|
161
|
-
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
module.exports.postcss = true
|
|
@@ -1,45 +1,51 @@
|
|
|
1
|
-
const postcss = require('postcss')
|
|
2
1
|
const pxRegExp = /\b(\d+(\.\d+)?)px\b/
|
|
3
2
|
const pxRegExpG = /\b(\d+(\.\d+)?)px\b/g
|
|
3
|
+
// rpx
|
|
4
|
+
module.exports = (options = {}) => {
|
|
5
|
+
return {
|
|
6
|
+
postcssPlugin: 'rpx',
|
|
7
|
+
Once (root) {
|
|
8
|
+
const mode = options.mode || 'only'
|
|
9
|
+
const defaultIgnoreComment = mode === 'all' ? 'use px' : 'use rpx'
|
|
10
|
+
const baseWidth = 750
|
|
11
|
+
const designWidth = options.designWidth || 750
|
|
12
|
+
const ratio = +(baseWidth / designWidth).toFixed(2)
|
|
13
|
+
function isIgnoreComment (node) {
|
|
14
|
+
let result = node && node.type === 'comment' && node.text.trim() === (options.comment || defaultIgnoreComment)
|
|
15
|
+
if (result) {
|
|
16
|
+
node.remove()
|
|
17
|
+
}
|
|
18
|
+
return result
|
|
19
|
+
}
|
|
4
20
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
if (result) {
|
|
14
|
-
node.remove()
|
|
15
|
-
}
|
|
16
|
-
return result
|
|
17
|
-
}
|
|
21
|
+
function transRpx (declaration) {
|
|
22
|
+
if (pxRegExp.test(declaration.value)) {
|
|
23
|
+
declaration.value = declaration.value.replace(pxRegExpG, function (match, $1) {
|
|
24
|
+
if ($1 === '0') return $1
|
|
25
|
+
return `${$1 * ratio}rpx`
|
|
26
|
+
})
|
|
27
|
+
}
|
|
28
|
+
}
|
|
18
29
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
root.walkRules(rule => {
|
|
31
|
+
let ignore = false
|
|
32
|
+
if (isIgnoreComment(rule.prev()) || isIgnoreComment(rule.last)) {
|
|
33
|
+
ignore = true
|
|
34
|
+
}
|
|
35
|
+
rule.walkDecls(declaration => {
|
|
36
|
+
if (ignore || isIgnoreComment(declaration.prev())) {
|
|
37
|
+
if (mode === 'only') {
|
|
38
|
+
transRpx(declaration)
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
if (mode === 'all') {
|
|
42
|
+
transRpx(declaration)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
})
|
|
24
46
|
})
|
|
25
47
|
}
|
|
26
48
|
}
|
|
49
|
+
}
|
|
27
50
|
|
|
28
|
-
|
|
29
|
-
let ignore = false
|
|
30
|
-
if (isIgnoreComment(rule.prev()) || isIgnoreComment(rule.last)) {
|
|
31
|
-
ignore = true
|
|
32
|
-
}
|
|
33
|
-
rule.walkDecls(declaration => {
|
|
34
|
-
if (ignore || isIgnoreComment(declaration.prev())) {
|
|
35
|
-
if (mode === 'only') {
|
|
36
|
-
transRpx(declaration)
|
|
37
|
-
}
|
|
38
|
-
} else {
|
|
39
|
-
if (mode === 'all') {
|
|
40
|
-
transRpx(declaration)
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
})
|
|
44
|
-
})
|
|
45
|
-
})
|
|
51
|
+
module.exports.postcss = true
|
|
@@ -1,81 +1,88 @@
|
|
|
1
|
-
const postcss = require('postcss')
|
|
2
1
|
const selectorParser = require('postcss-selector-parser')
|
|
2
|
+
// scope-id
|
|
3
3
|
|
|
4
|
-
module.exports =
|
|
5
|
-
|
|
4
|
+
module.exports = ({ id }) => {
|
|
5
|
+
return {
|
|
6
|
+
postcssPlugin: 'scope-id',
|
|
7
|
+
Once: (root) => {
|
|
8
|
+
const keyframes = Object.create(null)
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
return
|
|
19
|
-
}
|
|
20
|
-
node.selector = selectorParser(selectors => {
|
|
21
|
-
selectors.each(selector => {
|
|
22
|
-
let node = null
|
|
23
|
-
selector.each(n => {
|
|
24
|
-
// ">>>" combinator
|
|
25
|
-
if (n.type === 'combinator' && n.value === '>>>') {
|
|
26
|
-
n.value = ' '
|
|
27
|
-
n.spaces.before = n.spaces.after = ''
|
|
28
|
-
return false
|
|
29
|
-
}
|
|
30
|
-
// /deep/ alias for >>>, since >>> doesn't work in SASS
|
|
31
|
-
if (n.type === 'tag' && n.value === '/deep/') {
|
|
32
|
-
const prev = n.prev()
|
|
33
|
-
if (prev && prev.type === 'combinator' && prev.value === ' ') {
|
|
34
|
-
prev.remove()
|
|
10
|
+
root.each(function rewriteSelector (node) {
|
|
11
|
+
if (!node.selector) {
|
|
12
|
+
// handle media queries
|
|
13
|
+
if (node.type === 'atrule') {
|
|
14
|
+
if (node.name === 'media' || node.name === 'supports') {
|
|
15
|
+
node.each(rewriteSelector)
|
|
16
|
+
} else if (/-?keyframes$/.test(node.name)) {
|
|
17
|
+
// register keyframes
|
|
18
|
+
keyframes[node.params] = node.params = node.params + '-' + id
|
|
35
19
|
}
|
|
36
|
-
n.remove()
|
|
37
|
-
return false
|
|
38
20
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
21
|
+
return
|
|
22
|
+
}
|
|
23
|
+
node.selector = selectorParser(selectors => {
|
|
24
|
+
selectors.each(selector => {
|
|
25
|
+
let node = null
|
|
26
|
+
selector.each(n => {
|
|
27
|
+
// ">>>" combinator
|
|
28
|
+
if (n.type === 'combinator' && n.value === '>>>') {
|
|
29
|
+
n.value = ' '
|
|
30
|
+
n.spaces.before = n.spaces.after = ''
|
|
31
|
+
return false
|
|
32
|
+
}
|
|
33
|
+
// /deep/ alias for >>>, since >>> doesn't work in SASS
|
|
34
|
+
if (n.type === 'tag' && n.value === '/deep/') {
|
|
35
|
+
const prev = n.prev()
|
|
36
|
+
if (prev && prev.type === 'combinator' && prev.value === ' ') {
|
|
37
|
+
prev.remove()
|
|
38
|
+
}
|
|
39
|
+
n.remove()
|
|
40
|
+
return false
|
|
41
|
+
}
|
|
42
|
+
if (n.type !== 'pseudo' && n.type !== 'combinator') {
|
|
43
|
+
node = n
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
// 对于page selector不添加scope id
|
|
47
|
+
if (node && node.type === 'tag' && node.value === 'page') return
|
|
48
|
+
selector.insertAfter(node, selectorParser.className({
|
|
49
|
+
value: id
|
|
50
|
+
}))
|
|
51
|
+
})
|
|
52
|
+
}).processSync(node.selector)
|
|
48
53
|
})
|
|
49
|
-
}).process(node.selector).result
|
|
50
|
-
})
|
|
51
54
|
|
|
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
|
-
|
|
55
|
+
// If keyframes are found in this <style>, find and rewrite animation names
|
|
56
|
+
// in declarations.
|
|
57
|
+
// Caveat: this only works for keyframes and animation rules in the same
|
|
58
|
+
// <style> element.
|
|
59
|
+
if (Object.keys(keyframes).length) {
|
|
60
|
+
root.walkDecls(decl => {
|
|
61
|
+
// individual animation-name declaration
|
|
62
|
+
if (/-?animation-name$/.test(decl.prop)) {
|
|
63
|
+
decl.value = decl.value.split(',')
|
|
64
|
+
.map(v => keyframes[v.trim()] || v.trim())
|
|
65
|
+
.join(',')
|
|
66
|
+
}
|
|
67
|
+
// shorthand
|
|
68
|
+
if (/-?animation$/.test(decl.prop)) {
|
|
69
|
+
decl.value = decl.value.split(',')
|
|
70
|
+
.map(v => {
|
|
71
|
+
const vals = v.trim().split(/\s+/)
|
|
72
|
+
const i = vals.findIndex(val => keyframes[val])
|
|
73
|
+
if (i !== -1) {
|
|
74
|
+
vals.splice(i, 1, keyframes[vals[i]])
|
|
75
|
+
return vals.join(' ')
|
|
76
|
+
} else {
|
|
77
|
+
return v
|
|
78
|
+
}
|
|
79
|
+
})
|
|
80
|
+
.join(',')
|
|
81
|
+
}
|
|
82
|
+
})
|
|
78
83
|
}
|
|
79
|
-
}
|
|
84
|
+
}
|
|
80
85
|
}
|
|
81
|
-
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
module.exports.postcss = true
|
|
@@ -1,21 +1,28 @@
|
|
|
1
|
-
const postcss = require('postcss')
|
|
2
1
|
const selectorParser = require('postcss-selector-parser')
|
|
2
|
+
// trans-special
|
|
3
3
|
|
|
4
|
-
module.exports =
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
selector
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
4
|
+
module.exports = ({ id }) => {
|
|
5
|
+
return {
|
|
6
|
+
postcssPlugin: 'trans-special',
|
|
7
|
+
Once: (root) => {
|
|
8
|
+
root.each(function rewriteSelector (node) {
|
|
9
|
+
if (!node.selector) return
|
|
10
|
+
node.selector = selectorParser(selectors => {
|
|
11
|
+
selectors.each(selector => {
|
|
12
|
+
selector.each(n => {
|
|
13
|
+
if (/^:host$/.test(n.value)) {
|
|
14
|
+
const compoundSelectors = n.nodes
|
|
15
|
+
n.replaceWith(selectorParser.className({
|
|
16
|
+
value: 'host-' + id
|
|
17
|
+
}))
|
|
18
|
+
selector.insertAfter(n, compoundSelectors)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
})
|
|
22
|
+
}).processSync(node.selector)
|
|
18
23
|
})
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
module.exports.postcss = true
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
const postcss = require('postcss')
|
|
2
1
|
|
|
3
|
-
module.exports =
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
module.exports = (opts) => {
|
|
3
|
+
return {
|
|
4
|
+
postcssPlugin: 'trim',
|
|
5
|
+
Once: (root) => {
|
|
6
|
+
root.walk(({ type, raws }) => {
|
|
7
|
+
if (type === 'rule' || type === 'atrule') {
|
|
8
|
+
raws.before = raws.after = '\n'
|
|
9
|
+
}
|
|
10
|
+
})
|
|
7
11
|
}
|
|
8
|
-
}
|
|
9
|
-
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports.postcss = true
|
|
@@ -1,23 +1,29 @@
|
|
|
1
|
-
const postcss = require('postcss')
|
|
2
1
|
const rpxRegExp = /\b(\d+(\.\d+)?)rpx\b/
|
|
3
2
|
const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
|
|
4
3
|
|
|
5
|
-
module.exports =
|
|
6
|
-
|
|
4
|
+
module.exports = (options = {}) => {
|
|
5
|
+
return {
|
|
6
|
+
postcssPlugin: 'vw',
|
|
7
|
+
Once: (root) => {
|
|
8
|
+
const rpx2vwRatio = +(100 / 750).toFixed(8)
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
const transRpxFn = options.transRpxFn && typeof options.transRpxFn === 'function' ? options.transRpxFn : function (match, $1) {
|
|
11
|
+
if ($1 === '0') return $1
|
|
12
|
+
return `${$1 * rpx2vwRatio}vw`
|
|
13
|
+
}
|
|
14
|
+
function transVw (declaration) {
|
|
15
|
+
if (rpxRegExp.test(declaration.value)) {
|
|
16
|
+
declaration.value = declaration.value.replace(rpxRegExpG, transRpxFn)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
root.walkRules(rule => {
|
|
21
|
+
rule.walkDecls(declaration => {
|
|
22
|
+
transVw(declaration)
|
|
23
|
+
})
|
|
24
|
+
})
|
|
15
25
|
}
|
|
16
26
|
}
|
|
27
|
+
}
|
|
17
28
|
|
|
18
|
-
|
|
19
|
-
rule.walkDecls(declaration => {
|
|
20
|
-
transVw(declaration)
|
|
21
|
-
})
|
|
22
|
-
})
|
|
23
|
-
})
|
|
29
|
+
module.exports.postcss = true
|
|
@@ -1619,7 +1619,9 @@ function processClass (el, meta) {
|
|
|
1619
1619
|
staticClass = staticClass.replace(/\s+/g, ' ')
|
|
1620
1620
|
if (dynamicClass) {
|
|
1621
1621
|
let staticClassExp = parseMustache(staticClass).result
|
|
1622
|
-
let dynamicClassExp = transDynamicClassExpr(parseMustache(dynamicClass).result
|
|
1622
|
+
let dynamicClassExp = transDynamicClassExpr(parseMustache(dynamicClass).result, {
|
|
1623
|
+
error: error$1
|
|
1624
|
+
})
|
|
1623
1625
|
addAttrs(el, [{
|
|
1624
1626
|
name: targetType,
|
|
1625
1627
|
// swan中externalClass是通过编译时静态实现,因此需要保留原有的staticClass形式避免externalClass失效
|
|
@@ -53,7 +53,8 @@ module.exports = function (raw) {
|
|
|
53
53
|
externalClasses,
|
|
54
54
|
hasScoped,
|
|
55
55
|
moduleId,
|
|
56
|
-
|
|
56
|
+
// 这里需传递resourcePath和wxsContentMap保持一致
|
|
57
|
+
filePath: resourcePath,
|
|
57
58
|
i18n,
|
|
58
59
|
checkUsingComponents: mpx.checkUsingComponents,
|
|
59
60
|
globalComponents: Object.keys(mpx.usingComponents),
|
|
@@ -1,27 +1,32 @@
|
|
|
1
1
|
const babylon = require('@babel/parser')
|
|
2
2
|
const t = require('@babel/types')
|
|
3
3
|
const generate = require('@babel/generator').default
|
|
4
|
-
const dash2hump = require('../utils/hump-dash').dash2hump
|
|
5
4
|
|
|
6
|
-
module.exports = function transDynamicClassExpr (expr) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (t.isObjectExpression(expr)) {
|
|
13
|
-
expr.properties.forEach((property) => {
|
|
14
|
-
if (t.isObjectProperty(property) && !property.computed) {
|
|
15
|
-
const propertyName = property.key.name || property.key.value
|
|
16
|
-
if (/-/.test(propertyName)) {
|
|
17
|
-
property.key = t.identifier(dash2hump(propertyName) + 'MpxDash')
|
|
18
|
-
} else {
|
|
19
|
-
property.key = t.identifier(propertyName)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
5
|
+
module.exports = function transDynamicClassExpr (expr, { error } = {}) {
|
|
6
|
+
try {
|
|
7
|
+
const ast = babylon.parseExpression(expr, {
|
|
8
|
+
plugins: [
|
|
9
|
+
'objectRestSpread'
|
|
10
|
+
]
|
|
22
11
|
})
|
|
12
|
+
if (t.isObjectExpression(ast)) {
|
|
13
|
+
ast.properties.forEach((property) => {
|
|
14
|
+
if (t.isObjectProperty(property) && !property.computed) {
|
|
15
|
+
const propertyName = property.key.name || property.key.value
|
|
16
|
+
if (/-/.test(propertyName)) {
|
|
17
|
+
if (/\$/.test(propertyName)) {
|
|
18
|
+
error && error(`Dynamic classname [${propertyName}] is not supported, which includes [-] char and [$] char at the same time.`)
|
|
19
|
+
} else {
|
|
20
|
+
property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
return generate(ast, {
|
|
27
|
+
compact: true
|
|
28
|
+
}).code
|
|
29
|
+
} catch (e) {
|
|
30
|
+
return expr
|
|
23
31
|
}
|
|
24
|
-
return generate(expr, {
|
|
25
|
-
compact: true
|
|
26
|
-
}).code
|
|
27
32
|
}
|
|
@@ -96,7 +96,7 @@ module.exports = function (template, {
|
|
|
96
96
|
// todo 后续输出web也采用mpx的scoped处理
|
|
97
97
|
hasScoped: false,
|
|
98
98
|
moduleId,
|
|
99
|
-
filePath:
|
|
99
|
+
filePath: resourcePath,
|
|
100
100
|
i18n: null,
|
|
101
101
|
checkUsingComponents,
|
|
102
102
|
// web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
const {
|
|
2
2
|
compareModulesByPreOrderIndexOrIdentifier
|
|
3
3
|
} = require('webpack/lib/util/comparators')
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
assignAscendingModuleIds,
|
|
6
|
+
getUsedModuleIdsAndModules
|
|
7
|
+
} = require('webpack/lib/ids/IdHelpers')
|
|
5
8
|
|
|
6
9
|
/** @typedef {import("../Compiler")} Compiler */
|
|
7
10
|
/** @typedef {import("../Module")} Module */
|
|
@@ -12,19 +15,13 @@ class WxsModuleIdsPlugin {
|
|
|
12
15
|
name: 'WxsModuleIdsPlugin',
|
|
13
16
|
// 放在最前面执行,确保生成的代码模块为数组形式,符合wxs规范
|
|
14
17
|
stage: -1000
|
|
15
|
-
},
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
chunkGraph.getModuleId(m) === null
|
|
23
|
-
)
|
|
24
|
-
.sort(
|
|
25
|
-
compareModulesByPreOrderIndexOrIdentifier(compilation.moduleGraph)
|
|
26
|
-
)
|
|
27
|
-
assignAscendingModuleIds(modulesInNaturalOrder, compilation)
|
|
18
|
+
}, () => {
|
|
19
|
+
const [usedIds, modulesInNaturalOrder] =
|
|
20
|
+
getUsedModuleIdsAndModules(compilation)
|
|
21
|
+
modulesInNaturalOrder.sort(
|
|
22
|
+
compareModulesByPreOrderIndexOrIdentifier(compilation.moduleGraph)
|
|
23
|
+
)
|
|
24
|
+
assignAscendingModuleIds(usedIds, modulesInNaturalOrder, compilation)
|
|
28
25
|
})
|
|
29
26
|
}
|
|
30
27
|
}
|
package/lib/wxss/loader.js
CHANGED
|
@@ -65,7 +65,7 @@ module.exports = function (content, map) {
|
|
|
65
65
|
alreadyImported[imp.url] = true
|
|
66
66
|
}
|
|
67
67
|
return true
|
|
68
|
-
}).map((imp) => {
|
|
68
|
+
}).map((imp, i) => {
|
|
69
69
|
if (!isUrlRequest(imp.url, root, externals)) {
|
|
70
70
|
return 'exports.push([module.id, ' +
|
|
71
71
|
JSON.stringify('@import url(' + imp.url + ');') + ', ' +
|
|
@@ -75,7 +75,7 @@ module.exports = function (content, map) {
|
|
|
75
75
|
isStatic: true,
|
|
76
76
|
issuerFile: mpx.getExtractedFile(this.resource),
|
|
77
77
|
fromImport: true
|
|
78
|
-
})
|
|
78
|
+
}, i)
|
|
79
79
|
return 'exports.push([module.id, ' +
|
|
80
80
|
JSON.stringify('@import "') +
|
|
81
81
|
'+ require(' + requestString + ') +' +
|
package/lib/wxss/processCss.js
CHANGED
|
@@ -17,129 +17,133 @@ const modulesScope = require('postcss-modules-scope')
|
|
|
17
17
|
const modulesValues = require('postcss-modules-values')
|
|
18
18
|
const valueParser = require('postcss-value-parser')
|
|
19
19
|
const isUrlRequest = require('../utils/is-url-request')
|
|
20
|
+
// css-loader-parser
|
|
20
21
|
|
|
21
|
-
const parserPlugin =
|
|
22
|
-
return
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
+
}
|
|
27
48
|
|
|
28
|
-
function replaceImportsInString (str) {
|
|
29
49
|
if (options.import) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
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) {
|
|
33
59
|
return
|
|
34
60
|
}
|
|
35
|
-
|
|
36
|
-
const
|
|
37
|
-
|
|
38
|
-
|
|
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)
|
|
39
66
|
}
|
|
67
|
+
|
|
68
|
+
importItems.push({
|
|
69
|
+
url: url,
|
|
70
|
+
mediaQuery: mediaQuery
|
|
71
|
+
})
|
|
72
|
+
rule.remove()
|
|
40
73
|
})
|
|
41
|
-
return tokens.toString()
|
|
42
74
|
}
|
|
43
|
-
return str
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (options.import) {
|
|
47
|
-
css.walkAtRules(/^import$/i, function (rule) {
|
|
48
|
-
const values = Tokenizer.parseValues(rule.params)
|
|
49
|
-
let url = values.nodes[0].nodes[0]
|
|
50
|
-
if (url && url.type === 'url') {
|
|
51
|
-
url = url.url
|
|
52
|
-
} else if (url && url.type === 'string') {
|
|
53
|
-
url = url.value
|
|
54
|
-
} else throw rule.error('Unexpected format ' + rule.params)
|
|
55
|
-
if (!url.replace(/\s/g, '').length) {
|
|
56
|
-
return
|
|
57
|
-
}
|
|
58
|
-
values.nodes[0].nodes.shift()
|
|
59
|
-
const mediaQuery = Tokenizer.stringifyValues(values)
|
|
60
75
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
})
|
|
68
86
|
})
|
|
69
|
-
rule.remove()
|
|
70
87
|
})
|
|
71
|
-
}
|
|
72
88
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
Object.keys(icss.icssImports).forEach(function (key) {
|
|
76
|
-
const url = loaderUtils.parseString(key)
|
|
77
|
-
Object.keys(icss.icssImports[key]).forEach(function (prop) {
|
|
78
|
-
imports['$' + prop] = importItems.length
|
|
79
|
-
importItems.push({
|
|
80
|
-
url: url,
|
|
81
|
-
export: icss.icssImports[key][prop]
|
|
82
|
-
})
|
|
89
|
+
Object.keys(exports).forEach(function (exportName) {
|
|
90
|
+
exports[exportName] = replaceImportsInString(exports[exportName])
|
|
83
91
|
})
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
Object.keys(exports).forEach(function (exportName) {
|
|
87
|
-
exports[exportName] = replaceImportsInString(exports[exportName])
|
|
88
|
-
})
|
|
89
92
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
function isAlias (url) {
|
|
94
|
+
// Handle alias starting by / and root disabled
|
|
95
|
+
return url !== options.resolve(url)
|
|
96
|
+
}
|
|
94
97
|
|
|
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
|
-
|
|
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
|
+
case 'url':
|
|
113
|
+
if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && (isAlias(item.url) || isUrlRequest(item.url, options.root))) {
|
|
114
|
+
// Strip quotes, they will be re-added if the module needs them
|
|
115
|
+
item.stringType = ''
|
|
116
|
+
delete item.innerSpacingBefore
|
|
117
|
+
delete item.innerSpacingAfter
|
|
118
|
+
const url = item.url
|
|
119
|
+
item.url = '___CSS_LOADER_URL___' + urlItems.length + '___'
|
|
120
|
+
urlItems.push({
|
|
121
|
+
url: url
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
break
|
|
125
|
+
}
|
|
122
126
|
}
|
|
123
|
-
}
|
|
124
127
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
128
|
+
css.walkDecls(function (decl) {
|
|
129
|
+
const values = Tokenizer.parseValues(decl.value)
|
|
130
|
+
values.nodes.forEach(function (value) {
|
|
131
|
+
value.nodes.forEach(processNode)
|
|
132
|
+
})
|
|
133
|
+
decl.value = Tokenizer.stringifyValues(values)
|
|
134
|
+
})
|
|
135
|
+
css.walkAtRules(function (atrule) {
|
|
136
|
+
if (typeof atrule.params === 'string') {
|
|
137
|
+
atrule.params = replaceImportsInString(atrule.params)
|
|
138
|
+
}
|
|
129
139
|
})
|
|
130
|
-
decl.value = Tokenizer.stringifyValues(values)
|
|
131
|
-
})
|
|
132
|
-
css.walkAtRules(function (atrule) {
|
|
133
|
-
if (typeof atrule.params === 'string') {
|
|
134
|
-
atrule.params = replaceImportsInString(atrule.params)
|
|
135
|
-
}
|
|
136
|
-
})
|
|
137
140
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
+
options.importItems = importItems
|
|
142
|
+
options.urlItems = urlItems
|
|
143
|
+
options.exports = exports
|
|
144
|
+
}
|
|
141
145
|
}
|
|
142
|
-
}
|
|
146
|
+
}
|
|
143
147
|
|
|
144
148
|
module.exports = function processCss (inputSource, inputMap, options, callback) {
|
|
145
149
|
const query = options.query
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.7.
|
|
3
|
+
"version": "2.7.3",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"consolidate": "^0.15.1",
|
|
33
33
|
"css": "^2.2.1",
|
|
34
34
|
"css-selector-tokenizer": "^0.7.0",
|
|
35
|
-
"cssnano": "^
|
|
35
|
+
"cssnano": "^5.0.16",
|
|
36
36
|
"de-indent": "^1.0.2",
|
|
37
37
|
"fastparse": "^1.1.1",
|
|
38
38
|
"hash-sum": "^1.0.2",
|
|
@@ -46,14 +46,14 @@
|
|
|
46
46
|
"lru-cache": "^4.1.2",
|
|
47
47
|
"mime": "^2.2.2",
|
|
48
48
|
"object-assign": "^4.1.1",
|
|
49
|
-
"postcss": "^
|
|
50
|
-
"postcss-load-config": "^1.
|
|
51
|
-
"postcss-modules-extract-imports": "^
|
|
52
|
-
"postcss-modules-local-by-default": "^
|
|
53
|
-
"postcss-modules-scope": "^
|
|
54
|
-
"postcss-modules-values": "^
|
|
55
|
-
"postcss-selector-parser": "^
|
|
56
|
-
"postcss-value-parser": "^
|
|
49
|
+
"postcss": "^8.4.5",
|
|
50
|
+
"postcss-load-config": "^3.1.1",
|
|
51
|
+
"postcss-modules-extract-imports": "^3.0.0",
|
|
52
|
+
"postcss-modules-local-by-default": "^4.0.0",
|
|
53
|
+
"postcss-modules-scope": "^3.0.0",
|
|
54
|
+
"postcss-modules-values": "^4.0.0",
|
|
55
|
+
"postcss-selector-parser": "^6.0.8",
|
|
56
|
+
"postcss-value-parser": "^4.0.2",
|
|
57
57
|
"source-list-map": "^2.0.0"
|
|
58
58
|
},
|
|
59
59
|
"peerDependencies": {
|
|
@@ -80,5 +80,5 @@
|
|
|
80
80
|
"engines": {
|
|
81
81
|
"node": ">=14.14.0"
|
|
82
82
|
},
|
|
83
|
-
"gitHead": "
|
|
83
|
+
"gitHead": "0cb7ce760316aa22f7c96ba8561a96f3eab2b8d6"
|
|
84
84
|
}
|