@mpxjs/webpack-plugin 2.10.16 → 2.10.17-beta.10
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/config.js +60 -0
- package/lib/dependencies/AppEntryDependency.js +2 -2
- package/lib/dependencies/RecordModuleIdMapDependency.js +49 -0
- package/lib/dependencies/ResolveDependency.js +1 -1
- package/lib/file-loader.js +4 -1
- package/lib/global.d.ts +245 -0
- package/lib/helpers.js +2 -0
- package/lib/index.js +80 -19
- package/lib/json-compiler/helper.js +72 -2
- package/lib/json-compiler/index.js +45 -59
- package/lib/json-compiler/plugin.js +2 -2
- package/lib/loader.js +14 -4
- package/lib/native-loader.js +6 -3
- package/lib/platform/json/wx/index.js +30 -29
- package/lib/platform/style/wx/index.js +51 -36
- package/lib/platform/template/wx/component-config/ad.js +5 -0
- package/lib/platform/template/wx/component-config/button.js +22 -6
- package/lib/platform/template/wx/component-config/camera.js +25 -3
- package/lib/platform/template/wx/component-config/canvas.js +8 -1
- package/lib/platform/template/wx/component-config/component.js +31 -33
- package/lib/platform/template/wx/component-config/cover-image.js +7 -2
- package/lib/platform/template/wx/component-config/cover-view.js +3 -1
- package/lib/platform/template/wx/component-config/fix-component-name.js +2 -2
- package/lib/platform/template/wx/component-config/form.js +27 -2
- package/lib/platform/template/wx/component-config/image.js +5 -0
- package/lib/platform/template/wx/component-config/input.js +11 -1
- package/lib/platform/template/wx/component-config/label.js +10 -2
- package/lib/platform/template/wx/component-config/map.js +11 -0
- package/lib/platform/template/wx/component-config/movable-area.js +4 -1
- package/lib/platform/template/wx/component-config/movable-view.js +17 -2
- package/lib/platform/template/wx/component-config/navigator.js +26 -0
- package/lib/platform/template/wx/component-config/picker-view.js +12 -0
- package/lib/platform/template/wx/component-config/picker.js +3 -1
- package/lib/platform/template/wx/component-config/progress.js +11 -1
- package/lib/platform/template/wx/component-config/rich-text.js +5 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +12 -1
- package/lib/platform/template/wx/component-config/slider.js +8 -0
- package/lib/platform/template/wx/component-config/swiper-item.js +5 -2
- package/lib/platform/template/wx/component-config/swiper.js +10 -0
- package/lib/platform/template/wx/component-config/text.js +5 -0
- package/lib/platform/template/wx/component-config/textarea.js +20 -3
- package/lib/platform/template/wx/component-config/unsupported.js +10 -1
- package/lib/platform/template/wx/component-config/video.js +10 -0
- package/lib/platform/template/wx/index.js +21 -1
- package/lib/react/LoadAsyncChunkModule.js +1 -1
- package/lib/react/index.js +2 -0
- package/lib/react/processJSON.js +59 -72
- package/lib/react/processScript.js +1 -0
- package/lib/react/processStyles.js +24 -11
- package/lib/react/processTemplate.js +8 -6
- package/lib/react/script-helper.js +6 -17
- package/lib/react/style-helper.js +84 -13
- package/lib/resolver/AddModePlugin.js +23 -8
- package/lib/runtime/components/ali/mpx-recycle-view.mpx +518 -0
- package/lib/runtime/components/ali/mpx-sticky-header.mpx +212 -0
- package/lib/runtime/components/ali/mpx-sticky-section.mpx +17 -0
- package/lib/runtime/components/react/animationHooks/index.ts +75 -0
- package/lib/runtime/components/react/animationHooks/useAnimationAPIHooks.ts +198 -0
- package/lib/runtime/components/react/animationHooks/useTransitionHooks.ts +301 -0
- package/lib/runtime/components/react/animationHooks/utils.ts +197 -0
- package/lib/runtime/components/react/context.ts +19 -7
- package/lib/runtime/components/react/dist/animationHooks/index.d.ts +15 -0
- package/lib/runtime/components/react/dist/animationHooks/index.js +67 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.d.ts +3 -0
- package/lib/runtime/components/react/dist/animationHooks/useAnimationAPIHooks.js +182 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.d.ts +3 -0
- package/lib/runtime/components/react/dist/animationHooks/useTransitionHooks.js +279 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.d.ts +109 -0
- package/lib/runtime/components/react/dist/animationHooks/utils.js +151 -0
- package/lib/runtime/components/react/dist/context.d.ts +79 -0
- package/lib/runtime/components/react/dist/context.js +1 -0
- package/lib/runtime/components/react/dist/event.config.d.ts +7 -0
- package/lib/runtime/components/react/dist/getInnerListeners.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-async-suspense.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-button.d.ts +68 -0
- package/lib/runtime/components/react/dist/mpx-camera.d.ts +31 -0
- package/lib/runtime/components/react/dist/mpx-camera.jsx +236 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Bus.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasGradient.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-canvas/CanvasRenderingContext2D.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-canvas/Image.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-canvas/ImageData.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-canvas/constructorsRegistry.d.ts +10 -0
- package/lib/runtime/components/react/dist/mpx-canvas/html.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-canvas/utils.d.ts +52 -0
- package/lib/runtime/components/react/dist/mpx-checkbox-group.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-checkbox.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-form.d.ts +27 -0
- package/lib/runtime/components/react/dist/mpx-icon/index.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-image.d.ts +21 -0
- package/lib/runtime/components/react/dist/mpx-image.jsx +109 -59
- package/lib/runtime/components/react/dist/mpx-inline-text.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-input.d.ts +51 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +52 -17
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +62 -49
- package/lib/runtime/components/react/dist/mpx-label.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-movable-area.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-movable-view.d.ts +65 -0
- package/lib/runtime/components/react/dist/mpx-nav.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-nav.jsx +132 -0
- package/lib/runtime/components/react/dist/mpx-navigator.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-picker/date.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/dateData.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/region.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/regionData.d.ts +2 -0
- package/lib/runtime/components/react/dist/mpx-picker/selector.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/time.d.ts +6 -0
- package/lib/runtime/components/react/dist/mpx-picker/type.d.ts +106 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.d.ts +32 -0
- package/lib/runtime/components/react/dist/mpx-picker-view/index.jsx +4 -3
- package/lib/runtime/components/react/dist/mpx-picker-view/pickerVIewContext.d.ts +8 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/index.jsx +12 -18
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItem.jsx +8 -11
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.d.ts +13 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewColumnItemLite.jsx +20 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewFaces.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewIndicator.d.ts +12 -0
- package/lib/runtime/components/react/dist/mpx-picker-view-column/pickerViewMask.d.ts +11 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.d.ts +16 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-portal/index.jsx +5 -1
- package/lib/runtime/components/react/dist/mpx-portal/portal-host.d.ts +29 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.d.ts +9 -0
- package/lib/runtime/components/react/dist/mpx-portal/portal-manager.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-progress.d.ts +23 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.d.ts +20 -0
- package/lib/runtime/components/react/dist/mpx-radio.d.ts +26 -0
- package/lib/runtime/components/react/dist/mpx-recycle-view.d.ts +45 -0
- package/lib/runtime/components/react/dist/mpx-recycle-view.jsx +307 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/html.d.ts +1 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.d.ts +24 -0
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-root-portal.d.ts +14 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.d.ts +54 -0
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +6 -14
- package/lib/runtime/components/react/dist/mpx-simple-text.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-simple-view.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-slider.d.ts +30 -0
- package/lib/runtime/components/react/dist/mpx-sticky-header.d.ts +17 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.d.ts +15 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.d.ts +18 -0
- package/lib/runtime/components/react/dist/mpx-swiper.d.ts +63 -0
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +77 -44
- package/lib/runtime/components/react/dist/mpx-switch.d.ts +26 -0
- package/lib/runtime/components/react/dist/mpx-text.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-text.jsx +33 -5
- package/lib/runtime/components/react/dist/mpx-textarea.d.ts +7 -0
- package/lib/runtime/components/react/dist/mpx-video.d.ts +101 -0
- package/lib/runtime/components/react/dist/mpx-view.d.ts +35 -0
- package/lib/runtime/components/react/dist/mpx-view.jsx +23 -9
- package/lib/runtime/components/react/dist/mpx-web-view.d.ts +22 -0
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +11 -3
- package/lib/runtime/components/react/dist/parser.d.ts +39 -0
- package/lib/runtime/components/react/dist/useNodesRef.d.ts +11 -0
- package/lib/runtime/components/react/dist/utils.d.ts +124 -0
- package/lib/runtime/components/react/dist/utils.jsx +42 -17
- package/lib/runtime/components/react/mpx-camera.tsx +327 -0
- package/lib/runtime/components/react/mpx-canvas/index.tsx +1 -1
- package/lib/runtime/components/react/mpx-image.tsx +132 -79
- package/lib/runtime/components/react/mpx-input.tsx +63 -24
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +70 -48
- package/lib/runtime/components/react/mpx-nav.tsx +155 -0
- package/lib/runtime/components/react/mpx-picker-view/index.tsx +5 -2
- package/lib/runtime/components/react/mpx-picker-view-column/index.tsx +26 -21
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItem.tsx +8 -12
- package/lib/runtime/components/react/mpx-picker-view-column/pickerViewColumnItemLite.tsx +55 -0
- package/lib/runtime/components/react/mpx-portal/index.tsx +8 -2
- package/lib/runtime/components/react/mpx-portal/portal-manager.tsx +2 -2
- package/lib/runtime/components/react/mpx-recycle-view.tsx +437 -0
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +1 -1
- package/lib/runtime/components/react/mpx-scroll-view.tsx +7 -17
- package/lib/runtime/components/react/mpx-sticky-section.tsx +1 -1
- package/lib/runtime/components/react/mpx-swiper.tsx +92 -42
- package/lib/runtime/components/react/mpx-text.tsx +38 -5
- package/lib/runtime/components/react/mpx-view.tsx +28 -13
- package/lib/runtime/components/react/mpx-web-view.tsx +14 -5
- package/lib/runtime/components/react/tsconfig.json +26 -0
- package/lib/runtime/components/react/types/common.d.ts +19 -0
- package/lib/runtime/components/react/types/global.d.ts +1 -0
- package/lib/runtime/components/react/utils.tsx +43 -21
- package/lib/runtime/components/web/mpx-recycle-view.vue +508 -0
- package/lib/runtime/components/wx/mpx-list-header-default.mpx +21 -0
- package/lib/runtime/components/wx/mpx-recycle-item-default.mpx +21 -0
- package/lib/runtime/components/wx/mpx-recycle-view.mpx +193 -0
- package/lib/runtime/components/wx/mpx-section-header-default.mpx +21 -0
- package/lib/runtime/optionProcessor.js +5 -0
- package/lib/runtime/optionProcessorReact.js +7 -0
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/script-setup-compiler/index.js +2 -2
- package/lib/style-compiler/index.js +3 -2
- package/lib/style-compiler/load-postcss-config.js +1 -1
- package/lib/style-compiler/plugins/trans-special.js +10 -2
- package/lib/style-compiler/strip-conditional-loader/rebaseUrl.js +225 -0
- package/lib/style-compiler/strip-conditional-loader.js +124 -18
- package/lib/template-compiler/compiler.js +272 -72
- package/lib/template-compiler/gen-node-react.js +18 -6
- package/lib/template-compiler/index.js +6 -4
- package/lib/template-compiler/parse-exps.js +1 -1
- package/lib/utils/const.js +19 -1
- package/lib/utils/dom-tag-config.js +6 -6
- package/lib/utils/env.js +6 -1
- package/lib/utils/get-build-tag-component.js +35 -0
- package/lib/utils/merge-visitors.js +55 -0
- package/lib/utils/pre-process-json.js +5 -0
- package/lib/utils/process-extend-components.js +43 -0
- package/lib/utils/string.js +25 -1
- package/lib/web/index.js +2 -0
- package/lib/web/processJSON.js +64 -18
- package/lib/web/processScript.js +1 -1
- package/lib/web/processTemplate.js +6 -4
- package/lib/web/script-helper.js +19 -9
- package/lib/wxs/pre-loader.js +9 -6
- package/lib/wxss/loader.js +1 -9
- package/package.json +11 -7
- package/LICENSE +0 -433
- package/lib/runtime/components/react/dist/useAnimationHooks.js +0 -289
- package/lib/runtime/components/react/useAnimationHooks.ts +0 -320
- package/lib/utils/chain-assign.js +0 -47
package/lib/config.js
CHANGED
|
@@ -553,6 +553,66 @@ module.exports = {
|
|
|
553
553
|
show: 'dd:show'
|
|
554
554
|
}
|
|
555
555
|
},
|
|
556
|
+
ks: {
|
|
557
|
+
typeExtMap: {
|
|
558
|
+
json: '.json',
|
|
559
|
+
script: '.js',
|
|
560
|
+
template: '.ksml',
|
|
561
|
+
styles: '.css'
|
|
562
|
+
},
|
|
563
|
+
tabBar: {
|
|
564
|
+
itemKey: 'list',
|
|
565
|
+
iconKey: 'iconPath',
|
|
566
|
+
activeIconKey: 'selectedIconPath'
|
|
567
|
+
},
|
|
568
|
+
event: {
|
|
569
|
+
parseEvent (attr) {
|
|
570
|
+
const match = /^(bind|catch|capture-bind|capture-catch):?(.*?)(?:\.(.*))?$/.exec(attr)
|
|
571
|
+
if (match) {
|
|
572
|
+
return {
|
|
573
|
+
prefix: match[1],
|
|
574
|
+
eventName: match[2],
|
|
575
|
+
modifier: match[3]
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
},
|
|
579
|
+
getEvent (eventName, prefix = 'bind') {
|
|
580
|
+
if (eventName.includes('-')) {
|
|
581
|
+
return `${prefix}:${eventName}`
|
|
582
|
+
} else {
|
|
583
|
+
return prefix + eventName
|
|
584
|
+
}
|
|
585
|
+
},
|
|
586
|
+
defaultModelProp: 'value',
|
|
587
|
+
defaultModelEvent: 'input',
|
|
588
|
+
defaultModelValuePath: 'value'
|
|
589
|
+
},
|
|
590
|
+
wxs: {
|
|
591
|
+
tag: 'ks',
|
|
592
|
+
module: 'module',
|
|
593
|
+
src: 'src',
|
|
594
|
+
ext: '.ks',
|
|
595
|
+
templatePrefix: 'module.exports = \n'
|
|
596
|
+
},
|
|
597
|
+
directive: {
|
|
598
|
+
if: 'ks:if',
|
|
599
|
+
elseif: 'ks:elif',
|
|
600
|
+
else: 'ks:else',
|
|
601
|
+
for: 'ks:for',
|
|
602
|
+
forIndex: 'ks:for-index',
|
|
603
|
+
forItem: 'ks:for-item',
|
|
604
|
+
key: 'ks:key',
|
|
605
|
+
dynamicClass: 'ks:class',
|
|
606
|
+
dynamicStyle: 'ks:style',
|
|
607
|
+
ref: 'ks:ref',
|
|
608
|
+
show: 'ks:show',
|
|
609
|
+
model: 'ks:model',
|
|
610
|
+
modelProp: 'ks:model-prop',
|
|
611
|
+
modelEvent: 'ks:model-event',
|
|
612
|
+
modelValuePath: 'ks:model-value-path',
|
|
613
|
+
modelFilter: 'ks:model-filter'
|
|
614
|
+
}
|
|
615
|
+
},
|
|
556
616
|
ios: reactConfig,
|
|
557
617
|
android: reactConfig,
|
|
558
618
|
harmony: reactConfig
|
|
@@ -21,8 +21,8 @@ class AppEntryDependency extends NullDependency {
|
|
|
21
21
|
if (mpx.appInfo.name) {
|
|
22
22
|
const issuer = moduleGraph.getIssuer(module)
|
|
23
23
|
const err = new Error(issuer
|
|
24
|
-
? `[json
|
|
25
|
-
: `[json
|
|
24
|
+
? `[Mpx json error]:Mpx单次构建中只能存在一个App,当前组件/页面[${module.resource}]通过[${issuer.resource}]非法引入,引用的资源将被忽略,请确保组件/页面资源通过usingComponents/pages配置引入!`
|
|
25
|
+
: `[Mpx json error]:Mpx单次构建中只能存在一个App,请检查当前entry中的资源[${module.resource}]是否为组件/页面,通过添加?component/page查询字符串显式声明该资源是组件/页面!`)
|
|
26
26
|
return callback(err)
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
+
const makeSerializable = require('webpack/lib/util/makeSerializable')
|
|
3
|
+
|
|
4
|
+
class RecordModuleIdMapDependency extends NullDependency {
|
|
5
|
+
constructor (moduleId, filePath) {
|
|
6
|
+
super()
|
|
7
|
+
this.moduleId = moduleId
|
|
8
|
+
this.filePath = filePath
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
get type () {
|
|
12
|
+
return 'mpx record module id map'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
mpxAction (module, compilation, callback) {
|
|
16
|
+
const mpx = compilation.__mpx__
|
|
17
|
+
const { moduleId, filePath } = this
|
|
18
|
+
// 确保 resourceModuleIdMap 存在
|
|
19
|
+
if (!mpx.resourceModuleIdMap) {
|
|
20
|
+
mpx.resourceModuleIdMap = {}
|
|
21
|
+
}
|
|
22
|
+
// 记录 moduleId 和 filePath 的映射关系
|
|
23
|
+
mpx.resourceModuleIdMap[moduleId] = filePath
|
|
24
|
+
return callback()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
serialize (context) {
|
|
28
|
+
const { write } = context
|
|
29
|
+
write(this.moduleId)
|
|
30
|
+
write(this.filePath)
|
|
31
|
+
super.serialize(context)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
deserialize (context) {
|
|
35
|
+
const { read } = context
|
|
36
|
+
this.moduleId = read()
|
|
37
|
+
this.filePath = read()
|
|
38
|
+
super.deserialize(context)
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
RecordModuleIdMapDependency.Template = class RecordModuleIdMapDependencyTemplate {
|
|
43
|
+
apply () {
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
makeSerializable(RecordModuleIdMapDependency, '@mpxjs/webpack-plugin/lib/dependencies/RecordModuleIdMapDependency')
|
|
48
|
+
|
|
49
|
+
module.exports = RecordModuleIdMapDependency
|
|
@@ -36,7 +36,7 @@ class ResolveDependency extends NullDependency {
|
|
|
36
36
|
const resolveResult = pagesMap[resourcePath] || currentComponentsMap[resourcePath] || mainComponentsMap[resourcePath] || currentStaticResourcesMap[resourcePath] || mainStaticResourcesMap[resourcePath] || ''
|
|
37
37
|
if (!resolveResult) {
|
|
38
38
|
if (!partialCompileRules || matchCondition(resourcePath, partialCompileRules)) {
|
|
39
|
-
compilation.errors.push(new Error(`Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
|
|
39
|
+
compilation.errors.push(new Error(`[Mpx json error]:Path ${resource} is not a page/component/static resource, which is resolved from ${issuerResource}!`))
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
return resolveResult
|
package/lib/file-loader.js
CHANGED
|
@@ -8,7 +8,9 @@ module.exports = function loader (content, prevOptions) {
|
|
|
8
8
|
const options = prevOptions || loaderUtils.getOptions(this) || {}
|
|
9
9
|
const context = options.context || this.rootContext
|
|
10
10
|
const mpx = this.getMpx()
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
const { mode } = mpx
|
|
13
|
+
const isRN = ['ios', 'android', 'harmony'].includes(mode)
|
|
12
14
|
|
|
13
15
|
let url = loaderUtils.interpolateName(this, options.name, {
|
|
14
16
|
context,
|
|
@@ -47,6 +49,7 @@ module.exports = function loader (content, prevOptions) {
|
|
|
47
49
|
? options.publicPath
|
|
48
50
|
: `${options.publicPath}/`}${url}`
|
|
49
51
|
}
|
|
52
|
+
|
|
50
53
|
publicPath = JSON.stringify(publicPath)
|
|
51
54
|
}
|
|
52
55
|
|
package/lib/global.d.ts
ADDED
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
import * as webpack from 'webpack'
|
|
2
|
+
|
|
3
|
+
declare module 'webpack' {
|
|
4
|
+
interface Compilation {
|
|
5
|
+
__mpx__: MpxContext
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
interface Compiler {
|
|
9
|
+
__mpx__?: boolean
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
declare global {
|
|
14
|
+
interface MpxWebpackPluginOptions {
|
|
15
|
+
style: {
|
|
16
|
+
cssCondition?: {
|
|
17
|
+
before?: boolean
|
|
18
|
+
after?: boolean
|
|
19
|
+
beforeExclude?: (string | RegExp)[]
|
|
20
|
+
afterExclude?: (string | RegExp)[]
|
|
21
|
+
legacy?: boolean
|
|
22
|
+
afterLegacy?: boolean
|
|
23
|
+
beforeLegacy?: boolean
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
type MpxLoaderContext<T> = webpack.LoaderContext<T> & {
|
|
29
|
+
getMpx(): MpxContext
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface MpxContext {
|
|
33
|
+
/**
|
|
34
|
+
* 用于使用 webpack-virtual-modules 功能,目前仅在输出 web 时支持使用
|
|
35
|
+
*/
|
|
36
|
+
__vfs: any | null
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* app 信息,便于获取 appName
|
|
40
|
+
*/
|
|
41
|
+
appInfo: {
|
|
42
|
+
resourcePath?: string
|
|
43
|
+
name?: string
|
|
44
|
+
[key: string]: any
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* pageConfig 信息
|
|
49
|
+
*/
|
|
50
|
+
pageConfigsMap: Record<string, any>
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* pages 全局记录,无需区分主包/分包
|
|
54
|
+
*/
|
|
55
|
+
pagesMap: Record<string, string>
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 组件资源记录,按所属包进行记录(如 componentsMap.main)
|
|
59
|
+
*/
|
|
60
|
+
componentsMap: Record<string, Record<string, string>>
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* 静态资源(图片、字体、独立样式)等,按所属包进行记录
|
|
64
|
+
*/
|
|
65
|
+
staticResourcesMap: Record<string, Record<string, string>>
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 用于记录命中 subpackageModulesRules 的 JS 模块分包归属,用于 JS 多分包冗余输出
|
|
69
|
+
*/
|
|
70
|
+
subpackageModulesMap: Record<string, Record<string, string>>
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 记录其他资源,如 pluginMain、pluginExport,无需区分主包/分包
|
|
74
|
+
*/
|
|
75
|
+
otherResourcesMap: Record<string, any>
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 记录独立分包
|
|
79
|
+
*/
|
|
80
|
+
independentSubpackagesMap: Record<string, any>
|
|
81
|
+
|
|
82
|
+
subpackagesEntriesMap: Record<string, any>
|
|
83
|
+
postSubpackageEntriesMap: Record<string, any>
|
|
84
|
+
replacePathMap: Record<string, string>
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* 导出模块集合
|
|
88
|
+
*/
|
|
89
|
+
exportModules: Set<any>
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 记录动态添加入口的分包信息
|
|
93
|
+
*/
|
|
94
|
+
dynamicEntryInfo: Record<string, any>
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 记录 entryModule 与 entryNode 的对应关系,用于体积分析
|
|
98
|
+
*/
|
|
99
|
+
entryNodeModulesMap: Map<any, any>
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* 记录与 asset 相关联的 modules,用于体积分析
|
|
103
|
+
*/
|
|
104
|
+
assetsModulesMap: Map<string, Set<any>>
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* 记录与 asset 相关联的 AST,用于体积分析和 esCheck,避免重复 parse
|
|
108
|
+
*/
|
|
109
|
+
assetsASTsMap: Map<string, any>
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* 记录 RequireExternalDependency 相关资源路径
|
|
113
|
+
*/
|
|
114
|
+
externalRequestsMap: Map<string, any>
|
|
115
|
+
|
|
116
|
+
globalComponents: Record<string, any>
|
|
117
|
+
globalComponentsInfo: Record<string, any>
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* todo: es6 Map 读写性能高于 object,之后会逐步替换
|
|
121
|
+
*/
|
|
122
|
+
wxsAssetsCache: Map<string, any>
|
|
123
|
+
addEntryPromiseMap: Map<string, Promise<any>>
|
|
124
|
+
currentPackageRoot: string
|
|
125
|
+
wxsContentMap: Record<string, string>
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 是否强制使用页面构造函数
|
|
129
|
+
*/
|
|
130
|
+
forceUsePageCtor: boolean
|
|
131
|
+
|
|
132
|
+
resolveMode: string
|
|
133
|
+
mode: string
|
|
134
|
+
srcMode: string
|
|
135
|
+
env: string
|
|
136
|
+
externalClasses: string[]
|
|
137
|
+
projectRoot: string
|
|
138
|
+
autoScopeRules: any
|
|
139
|
+
autoVirtualHostRules: any
|
|
140
|
+
customTextRules: any
|
|
141
|
+
transRpxRules: any
|
|
142
|
+
postcssInlineConfig: any
|
|
143
|
+
decodeHTMLText: boolean
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* native 文件专用配置
|
|
147
|
+
*/
|
|
148
|
+
i18n: any | null
|
|
149
|
+
checkUsingComponentsRules: any
|
|
150
|
+
forceDisableBuiltInLoader: boolean
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 默认的应用标题
|
|
154
|
+
*/
|
|
155
|
+
appTitle: string
|
|
156
|
+
|
|
157
|
+
attributes: any[]
|
|
158
|
+
externals: any[]
|
|
159
|
+
useRelativePath: boolean
|
|
160
|
+
removedChunks: any[]
|
|
161
|
+
forceProxyEventRules: any
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 若配置 disableRequireAsync=true,则全平台构建不支持异步分包
|
|
165
|
+
*/
|
|
166
|
+
supportRequireAsync: boolean
|
|
167
|
+
partialCompileRules: any
|
|
168
|
+
asyncSubpackageRules: any[]
|
|
169
|
+
transSubpackageRules: any
|
|
170
|
+
optimizeRenderRules: any[]
|
|
171
|
+
|
|
172
|
+
addEntryModuleIssuer: (module: string, issuer: string) => void
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 资源路径的哈希函数(用于生成输出唯一名)
|
|
176
|
+
*/
|
|
177
|
+
pathHash: (resourcePath: string) => string
|
|
178
|
+
|
|
179
|
+
// 缓存与工具
|
|
180
|
+
loaderContentCache: Map<string, any>
|
|
181
|
+
extractedFilesCache: Map<string, string>
|
|
182
|
+
|
|
183
|
+
// 函数接口
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* 收集动态入口信息(分包、文件名、是否为页面、是否包含异步等)
|
|
187
|
+
*/
|
|
188
|
+
collectDynamicEntryInfo: (info: { resource: string; packageName: string; filename: string; entryType: string; hasAsync: boolean }) => void
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* 添加入口(包装了 webpack 的 addEntry)
|
|
192
|
+
*/
|
|
193
|
+
addEntry: (request: string, name: string, callback: (err?: Error, result?: any) => void) => any
|
|
194
|
+
|
|
195
|
+
getModuleId: (filePath: string, isApp?: boolean) => string
|
|
196
|
+
getEntryNode: (module: any, type?: string) => any
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* 根据资源路径和类型返回输出路径(支持自定义输出、冲突处理等)
|
|
200
|
+
*/
|
|
201
|
+
getOutputPath: (resourcePath: string, type: string, opts?: { ext?: string; conflictPath?: string }) => string
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 获取提取后的文件名(支持静态、插件、普通资源)
|
|
205
|
+
*/
|
|
206
|
+
getExtractedFile: (resource: string, opts?: { error?: (err: Error) => void }) => string
|
|
207
|
+
|
|
208
|
+
recordResourceMap: (params: {
|
|
209
|
+
resourcePath: string
|
|
210
|
+
resourceType: string
|
|
211
|
+
outputPath?: string
|
|
212
|
+
packageRoot?: string
|
|
213
|
+
recordOnly?: boolean
|
|
214
|
+
warn?: (e: Error) => void
|
|
215
|
+
error?: (e: Error) => void
|
|
216
|
+
}) => { outputPath?: string; alreadyOutputted?: boolean }
|
|
217
|
+
|
|
218
|
+
getPackageInfo: (params: {
|
|
219
|
+
resource: string
|
|
220
|
+
resourceType: string
|
|
221
|
+
outputPath?: string
|
|
222
|
+
issuerResource?: string
|
|
223
|
+
warn?: (e: Error) => void
|
|
224
|
+
error?: (e: Error) => void
|
|
225
|
+
}) => { packageName: string; packageRoot: string; outputPath?: string; alreadyOutputted?: boolean }
|
|
226
|
+
|
|
227
|
+
// 运行时信息与注入相关
|
|
228
|
+
runtimeInfo: Record<string, any>
|
|
229
|
+
dynamicSlotDependencies: Record<string, any>
|
|
230
|
+
dynamicTemplateRuleRunner: any
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 依据 package 注入到 mpx-custom-element-*.json 里面的组件路径
|
|
234
|
+
*/
|
|
235
|
+
getPackageInjectedComponentsMap: (packageName?: string) => Record<string, string>
|
|
236
|
+
|
|
237
|
+
getPackageInjectedTemplateConfig: (packageName?: string) => any
|
|
238
|
+
injectDynamicSlotDependencies: (usingComponents: string, resourcePath: string) => string
|
|
239
|
+
changeHashNameForAstNode: (templateAst: string, componentsMap: any) => string
|
|
240
|
+
collectDynamicSlotDependencies: (packageName?: string) => void
|
|
241
|
+
|
|
242
|
+
// 其它任意扩展字段
|
|
243
|
+
[key: string]: any
|
|
244
|
+
}
|
|
245
|
+
}
|
package/lib/helpers.js
CHANGED
|
@@ -69,6 +69,8 @@ module.exports = function createHelpers (loaderContext) {
|
|
|
69
69
|
if (part.useJSONJS) options.useJSONJS = true
|
|
70
70
|
// eslint-disable-next-line no-fallthrough
|
|
71
71
|
case 'styles':
|
|
72
|
+
options.lang = part.lang
|
|
73
|
+
// eslint-disable-next-line no-fallthrough
|
|
72
74
|
case 'template':
|
|
73
75
|
options.extract = true
|
|
74
76
|
}
|
package/lib/index.js
CHANGED
|
@@ -36,6 +36,7 @@ const FixDescriptionInfoPlugin = require('./resolver/FixDescriptionInfoPlugin')
|
|
|
36
36
|
const AppEntryDependency = require('./dependencies/AppEntryDependency')
|
|
37
37
|
const RecordPageConfigMapDependency = require('./dependencies/RecordPageConfigsMapDependency')
|
|
38
38
|
const RecordResourceMapDependency = require('./dependencies/RecordResourceMapDependency')
|
|
39
|
+
const RecordModuleIdMapDependency = require('./dependencies/RecordModuleIdMapDependency')
|
|
39
40
|
const RecordGlobalComponentsDependency = require('./dependencies/RecordGlobalComponentsDependency')
|
|
40
41
|
const RecordIndependentDependency = require('./dependencies/RecordIndependentDependency')
|
|
41
42
|
const DynamicEntryDependency = require('./dependencies/DynamicEntryDependency')
|
|
@@ -78,13 +79,18 @@ const LoadAsyncChunkModule = require('./react/LoadAsyncChunkModule')
|
|
|
78
79
|
const ExternalModule = require('webpack/lib/ExternalModule')
|
|
79
80
|
const { RetryRuntimeModule, RetryRuntimeGlobal } = require('./dependencies/RetryRuntimeModule')
|
|
80
81
|
const checkVersionCompatibility = require('./utils/check-core-version-match')
|
|
81
|
-
|
|
82
|
+
const { rewriteFSForCss, startFSStripForCss } = require('./style-compiler/strip-conditional-loader')
|
|
83
|
+
rewriteFSForCss()
|
|
82
84
|
checkVersionCompatibility()
|
|
83
85
|
|
|
84
86
|
const isProductionLikeMode = options => {
|
|
85
87
|
return options.mode === 'production' || !options.mode
|
|
86
88
|
}
|
|
87
89
|
|
|
90
|
+
/**
|
|
91
|
+
* @param {import('webpack').NormalModule} module
|
|
92
|
+
* @returns
|
|
93
|
+
*/
|
|
88
94
|
const isStaticModule = module => {
|
|
89
95
|
if (!module.resource) return false
|
|
90
96
|
const { queryObj } = parseRequest(module.resource)
|
|
@@ -321,7 +327,13 @@ class MpxWebpackPlugin {
|
|
|
321
327
|
}
|
|
322
328
|
}
|
|
323
329
|
|
|
330
|
+
/**
|
|
331
|
+
* @param {import('webpack').Compiler} compiler
|
|
332
|
+
*/
|
|
324
333
|
apply (compiler) {
|
|
334
|
+
// 注入 fs 代理
|
|
335
|
+
startFSStripForCss(this.options.defs)
|
|
336
|
+
|
|
325
337
|
if (!compiler.__mpx__) {
|
|
326
338
|
compiler.__mpx__ = true
|
|
327
339
|
} else {
|
|
@@ -673,6 +685,9 @@ class MpxWebpackPlugin {
|
|
|
673
685
|
compilation.dependencyFactories.set(RecordResourceMapDependency, new NullFactory())
|
|
674
686
|
compilation.dependencyTemplates.set(RecordResourceMapDependency, new RecordResourceMapDependency.Template())
|
|
675
687
|
|
|
688
|
+
compilation.dependencyFactories.set(RecordModuleIdMapDependency, new NullFactory())
|
|
689
|
+
compilation.dependencyTemplates.set(RecordModuleIdMapDependency, new RecordModuleIdMapDependency.Template())
|
|
690
|
+
|
|
676
691
|
compilation.dependencyFactories.set(RecordGlobalComponentsDependency, new NullFactory())
|
|
677
692
|
compilation.dependencyTemplates.set(RecordGlobalComponentsDependency, new RecordGlobalComponentsDependency.Template())
|
|
678
693
|
|
|
@@ -721,6 +736,8 @@ class MpxWebpackPlugin {
|
|
|
721
736
|
componentsMap: {
|
|
722
737
|
main: {}
|
|
723
738
|
},
|
|
739
|
+
// 资源与moduleId关系记录
|
|
740
|
+
resourceModuleIdMap: {},
|
|
724
741
|
// 静态资源(图片,字体,独立样式)等,依照所属包进行记录
|
|
725
742
|
staticResourcesMap: {
|
|
726
743
|
main: {}
|
|
@@ -788,6 +805,7 @@ class MpxWebpackPlugin {
|
|
|
788
805
|
// 若配置disableRequireAsync=true, 则全平台构建不支持异步分包
|
|
789
806
|
supportRequireAsync: !this.options.disableRequireAsync && (this.options.mode === 'wx' || this.options.mode === 'ali' || this.options.mode === 'tt' || isWeb(this.options.mode) || (isReact(this.options.mode) && this.options.rnConfig.supportSubpackage)),
|
|
790
807
|
partialCompileRules: this.options.partialCompileRules,
|
|
808
|
+
useExtendComponents: this.options.useExtendComponents,
|
|
791
809
|
collectDynamicEntryInfo: ({ resource, packageName, filename, entryType, hasAsync }) => {
|
|
792
810
|
const curInfo = mpx.dynamicEntryInfo[packageName] = mpx.dynamicEntryInfo[packageName] || {
|
|
793
811
|
hasPage: false,
|
|
@@ -1450,9 +1468,17 @@ class MpxWebpackPlugin {
|
|
|
1450
1468
|
// 删除root query
|
|
1451
1469
|
if (queryObj.root) request = addQuery(request, {}, false, ['root'])
|
|
1452
1470
|
// wx、ali和web平台支持require.async,其余平台使用CommonJsAsyncDependency进行模拟抹平
|
|
1453
|
-
|
|
1471
|
+
let shouldSplitChunk = mpx.supportRequireAsync
|
|
1472
|
+
if (shouldSplitChunk && isReact(mpx.mode)) {
|
|
1473
|
+
const transTarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
|
|
1474
|
+
tarRoot = transTarRoot
|
|
1475
|
+
if (transTarRoot === '') {
|
|
1476
|
+
shouldSplitChunk = false
|
|
1477
|
+
}
|
|
1478
|
+
}
|
|
1479
|
+
|
|
1480
|
+
if (shouldSplitChunk) {
|
|
1454
1481
|
if (isWeb(mpx.mode) || isReact(mpx.mode)) {
|
|
1455
|
-
if (isReact(mpx.mode)) tarRoot = transSubpackage(mpx.transSubpackageRules, tarRoot)
|
|
1456
1482
|
const depBlock = new AsyncDependenciesBlock(
|
|
1457
1483
|
{
|
|
1458
1484
|
name: tarRoot + '/index'
|
|
@@ -1684,11 +1710,12 @@ class MpxWebpackPlugin {
|
|
|
1684
1710
|
|
|
1685
1711
|
if (this.options.generateBuildMap) {
|
|
1686
1712
|
const pagesMap = compilation.__mpx__.pagesMap
|
|
1713
|
+
const resourceModuleIdMap = compilation.__mpx__.resourceModuleIdMap
|
|
1687
1714
|
const componentsPackageMap = compilation.__mpx__.componentsMap
|
|
1688
1715
|
const componentsMap = Object.keys(componentsPackageMap).map(item => componentsPackageMap[item]).reduce((pre, cur) => {
|
|
1689
1716
|
return { ...pre, ...cur }
|
|
1690
1717
|
}, {})
|
|
1691
|
-
const outputMap = JSON.stringify({ ...pagesMap, ...componentsMap })
|
|
1718
|
+
const outputMap = JSON.stringify({ outputPathMap: { ...pagesMap, ...componentsMap }, moduleIdMap: resourceModuleIdMap })
|
|
1692
1719
|
const filename = this.options.generateBuildMap.filename || 'outputMap.json'
|
|
1693
1720
|
compilation.assets[filename] = new RawSource(outputMap)
|
|
1694
1721
|
}
|
|
@@ -1722,7 +1749,14 @@ class MpxWebpackPlugin {
|
|
|
1722
1749
|
|
|
1723
1750
|
if (isReact(mpx.mode)) {
|
|
1724
1751
|
// 添加 @refresh reset 注释用于在 React HMR 时刷新组件
|
|
1725
|
-
|
|
1752
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
1753
|
+
source.add(`/* @refresh reset */
|
|
1754
|
+
if (module.hot) {
|
|
1755
|
+
module.hot.accept(() => {
|
|
1756
|
+
require("react-native").DevSettings.reload();
|
|
1757
|
+
});
|
|
1758
|
+
}\n`)
|
|
1759
|
+
}
|
|
1726
1760
|
// 注入页面的配置,供screen前置设置导航情况
|
|
1727
1761
|
if (isRuntime) {
|
|
1728
1762
|
source.add('// inject pageconfigmap for screen\n' +
|
|
@@ -1900,24 +1934,41 @@ try {
|
|
|
1900
1934
|
normalModuleFactory.hooks.afterResolve.tap('MpxWebpackPlugin', ({ createData }) => {
|
|
1901
1935
|
const { queryObj } = parseRequest(createData.request)
|
|
1902
1936
|
const loaders = createData.loaders
|
|
1937
|
+
|
|
1938
|
+
// 样式 loader 类型检测和条件编译 loader 插入的工具函数
|
|
1939
|
+
const STYLE_LOADER_TYPES = ['stylus-loader', 'sass-loader', 'less-loader', 'css-loader', wxssLoaderPath]
|
|
1940
|
+
const injectStyleStripLoader = (loaders) => {
|
|
1941
|
+
// 检查是否已经存在 stripLoader
|
|
1942
|
+
const hasStripLoader = loaders.some(loader => {
|
|
1943
|
+
const loaderPath = toPosix(loader.loader)
|
|
1944
|
+
return loaderPath.includes('style-compiler/strip-conditional-loader')
|
|
1945
|
+
})
|
|
1946
|
+
if (hasStripLoader) {
|
|
1947
|
+
return
|
|
1948
|
+
}
|
|
1949
|
+
const loaderTypes = new Map(STYLE_LOADER_TYPES.map(type => [`node_modules/${type}`, -1]))
|
|
1950
|
+
loaders.forEach((loader, index) => {
|
|
1951
|
+
const currentLoader = toPosix(loader.loader)
|
|
1952
|
+
for (const [key] of loaderTypes) {
|
|
1953
|
+
if (currentLoader.includes(key)) {
|
|
1954
|
+
loaderTypes.set(key, index)
|
|
1955
|
+
break
|
|
1956
|
+
}
|
|
1957
|
+
}
|
|
1958
|
+
})
|
|
1959
|
+
const targetIndex = STYLE_LOADER_TYPES
|
|
1960
|
+
.map(type => loaderTypes.get(`node_modules/${type}`))
|
|
1961
|
+
.find(index => index !== -1)
|
|
1962
|
+
|
|
1963
|
+
if (targetIndex !== undefined) {
|
|
1964
|
+
loaders.splice(targetIndex + 1, 0, { loader: styleStripConditionalPath })
|
|
1965
|
+
}
|
|
1966
|
+
}
|
|
1903
1967
|
if (queryObj.mpx && queryObj.mpx !== MPX_PROCESSED_FLAG) {
|
|
1904
1968
|
const type = queryObj.type
|
|
1905
1969
|
const extract = queryObj.extract
|
|
1906
|
-
|
|
1907
1970
|
if (type === 'styles') {
|
|
1908
|
-
|
|
1909
|
-
// 单次遍历收集所有索引
|
|
1910
|
-
loaders.forEach((loader, index) => {
|
|
1911
|
-
const currentLoader = toPosix(loader.loader)
|
|
1912
|
-
if (currentLoader.includes('node_modules/stylus-loader') || currentLoader.includes('node_modules/sass-loader') || currentLoader.includes('node_modules/less-loader')) {
|
|
1913
|
-
insertBeforeIndex = index
|
|
1914
|
-
}
|
|
1915
|
-
})
|
|
1916
|
-
|
|
1917
|
-
if (insertBeforeIndex !== -1) {
|
|
1918
|
-
loaders.splice(insertBeforeIndex, 0, { loader: styleStripConditionalPath })
|
|
1919
|
-
}
|
|
1920
|
-
loaders.push({ loader: styleStripConditionalPath })
|
|
1971
|
+
injectStyleStripLoader(loaders)
|
|
1921
1972
|
}
|
|
1922
1973
|
|
|
1923
1974
|
switch (type) {
|
|
@@ -1971,6 +2022,7 @@ try {
|
|
|
1971
2022
|
}
|
|
1972
2023
|
// mpxStyleOptions 为 mpx style 文件的标识,避免 Vue 文件插入 styleCompiler 后导致 vue scoped 样式隔离失效
|
|
1973
2024
|
if (isWeb(mpx.mode) && queryObj.mpxStyleOptions) {
|
|
2025
|
+
injectStyleStripLoader(loaders)
|
|
1974
2026
|
const firstLoader = loaders[0] ? toPosix(loaders[0].loader) : ''
|
|
1975
2027
|
const isPitcherRequest = firstLoader.includes('node_modules/vue-loader/lib/loaders/pitcher')
|
|
1976
2028
|
let cssLoaderIndex = -1
|
|
@@ -2062,3 +2114,12 @@ try {
|
|
|
2062
2114
|
}
|
|
2063
2115
|
|
|
2064
2116
|
module.exports = MpxWebpackPlugin
|
|
2117
|
+
|
|
2118
|
+
/**
|
|
2119
|
+
* 定义 MpxWebpackPlugin 的配置
|
|
2120
|
+
* @param {MpxWebpackPluginOptions} options - 插件选项
|
|
2121
|
+
* @returns {MpxWebpackPluginOptions}
|
|
2122
|
+
*/
|
|
2123
|
+
module.exports.defineConfig = function defineConfig(options) {
|
|
2124
|
+
return options
|
|
2125
|
+
}
|