@mpxjs/webpack-plugin 2.7.0-alpha.0 → 2.7.0-alpha.2
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/README.md +1 -1
- package/lib/config.js +14 -0
- package/lib/dependencies/AddEntryDependency.js +24 -0
- package/lib/dependencies/AppEntryDependency.js +2 -0
- package/lib/dependencies/CommonJsAsyncDependency.js +51 -0
- package/lib/dependencies/CommonJsVariableDependency.js +13 -6
- package/lib/dependencies/DynamicEntryDependency.js +85 -41
- package/lib/dependencies/FlagPluginDependency.js +1 -0
- package/lib/dependencies/RecordIndependentDependency.js +44 -0
- package/lib/dependencies/RecordResourceMapDependency.js +62 -0
- package/lib/dependencies/RemoveEntryDependency.js +40 -0
- package/lib/dependencies/ResolveDependency.js +11 -6
- package/lib/extractor.js +17 -7
- package/lib/file-loader.js +2 -2
- package/lib/helpers.js +6 -12
- package/lib/independent-loader.js +52 -0
- package/lib/index.js +595 -304
- package/lib/json-compiler/helper.js +36 -32
- package/lib/json-compiler/index.js +119 -66
- package/lib/json-compiler/plugin.js +23 -7
- package/lib/loader.js +135 -90
- package/lib/native-loader.js +37 -69
- package/lib/parser.js +1 -2
- package/lib/partial-compile/index.js +35 -0
- package/lib/platform/json/wx/index.js +8 -3
- package/lib/platform/template/normalize-component-rules.js +2 -3
- package/lib/platform/template/wx/component-config/button.js +17 -5
- package/lib/platform/template/wx/component-config/image.js +4 -0
- package/lib/platform/template/wx/component-config/input.js +4 -0
- package/lib/platform/template/wx/component-config/navigator.js +1 -1
- package/lib/platform/template/wx/component-config/rich-text.js +4 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
- package/lib/platform/template/wx/component-config/switch.js +4 -0
- package/lib/platform/template/wx/component-config/text.js +4 -0
- package/lib/platform/template/wx/component-config/textarea.js +5 -0
- package/lib/platform/template/wx/component-config/view.js +4 -0
- package/lib/platform/template/wx/index.js +149 -3
- package/lib/record-loader.js +2 -2
- package/lib/resolve-loader.js +4 -1
- package/lib/resolver/AddEnvPlugin.js +4 -3
- package/lib/resolver/AddModePlugin.js +4 -3
- package/lib/resolver/FixDescriptionInfoPlugin.js +28 -0
- package/lib/resolver/PackageEntryPlugin.js +23 -36
- package/lib/runtime/base.styl +5 -0
- package/lib/runtime/components/tenon/getInnerListeners.js +317 -0
- package/lib/runtime/components/tenon/tenon-button.vue +305 -0
- package/lib/runtime/components/tenon/tenon-image.vue +61 -0
- package/lib/runtime/components/tenon/tenon-input.vue +99 -0
- package/lib/runtime/components/tenon/tenon-rich-text.vue +21 -0
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +124 -0
- package/lib/runtime/components/tenon/tenon-switch.vue +91 -0
- package/lib/runtime/components/tenon/tenon-text-area.vue +64 -0
- package/lib/runtime/components/tenon/tenon-text.vue +64 -0
- package/lib/runtime/components/tenon/tenon-view.vue +93 -0
- package/lib/runtime/components/tenon/util.js +44 -0
- package/lib/runtime/components/web/getInnerListeners.js +51 -45
- package/lib/runtime/components/web/mpx-image.vue +20 -5
- package/lib/runtime/components/web/mpx-keep-alive.vue +4 -1
- package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
- package/lib/runtime/components/web/mpx-swiper.vue +37 -8
- package/lib/runtime/components/web/mpx-tab-bar-container.vue +2 -2
- package/lib/runtime/components/web/mpx-textarea.vue +1 -1
- package/lib/runtime/i18n.wxs +28 -8
- package/lib/runtime/optionProcessor.js +50 -20
- package/lib/runtime/optionProcessor.tenon.js +386 -0
- package/lib/runtime/stringify.wxs +6 -4
- package/lib/selector.js +23 -5
- package/lib/style-compiler/index.js +12 -13
- package/lib/style-compiler/load-postcss-config.js +3 -1
- package/lib/style-compiler/plugins/conditional-strip.js +68 -65
- package/lib/style-compiler/plugins/hm.js +20 -0
- 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 +19 -12
- package/lib/template-compiler/bind-this.js +4 -4
- package/lib/template-compiler/compiler.js +172 -62
- package/lib/template-compiler/index.js +8 -9
- package/lib/template-compiler/trans-dynamic-class-expr.js +32 -22
- package/lib/tenon/index.js +105 -0
- package/lib/tenon/processJSON.js +356 -0
- package/lib/tenon/processScript.js +261 -0
- package/lib/tenon/processStyles.js +21 -0
- package/lib/tenon/processTemplate.js +133 -0
- package/lib/utils/const.js +6 -1
- package/lib/utils/eval-json-js.js +31 -0
- package/lib/utils/get-entry-name.js +3 -3
- package/lib/utils/get-json-content.js +42 -0
- package/lib/utils/get-relative-path.js +25 -0
- package/lib/utils/match-condition.js +4 -1
- package/lib/utils/normalize.js +4 -2
- package/lib/utils/resolve.js +13 -0
- package/lib/web/processJSON.js +113 -144
- package/lib/web/processScript.js +45 -38
- package/lib/web/processTemplate.js +56 -41
- package/lib/wxml/loader.js +1 -6
- package/lib/wxs/WxsModuleIdsPlugin.js +11 -14
- package/lib/wxs/i18n-loader.js +5 -4
- package/lib/wxs/loader.js +87 -56
- package/lib/wxs/pre-loader.js +30 -10
- package/lib/wxss/loader.js +3 -3
- package/lib/wxss/processCss.js +135 -131
- package/package.json +23 -17
- package/lib/built-in-loader.js +0 -49
- package/lib/dependencies/RecordStaticResourceDependency.js +0 -47
- package/lib/utils/get-main-compilation.js +0 -6
- package/lib/utils/read-json-for-src.js +0 -34
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
const templateCompiler = require('../template-compiler/compiler')
|
|
2
2
|
const genComponentTag = require('../utils/gen-component-tag')
|
|
3
3
|
const addQuery = require('../utils/add-query')
|
|
4
|
-
const path = require('path')
|
|
5
4
|
const parseRequest = require('../utils/parse-request')
|
|
6
|
-
const
|
|
5
|
+
// const { matchCondition } = require('../utils/match-condition')
|
|
7
6
|
|
|
8
7
|
function calculateRootEleChild (arr) {
|
|
9
8
|
if (!arr) {
|
|
@@ -21,19 +20,30 @@ function calculateRootEleChild (arr) {
|
|
|
21
20
|
}, 0)
|
|
22
21
|
}
|
|
23
22
|
|
|
24
|
-
module.exports = function (template,
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
23
|
+
module.exports = function (template, {
|
|
24
|
+
loaderContext,
|
|
25
|
+
// hasScoped,
|
|
26
|
+
hasComment,
|
|
27
|
+
isNative,
|
|
28
|
+
srcMode,
|
|
29
|
+
moduleId,
|
|
30
|
+
ctorType,
|
|
31
|
+
usingComponents,
|
|
32
|
+
componentGenerics
|
|
33
|
+
}, callback) {
|
|
34
|
+
const mpx = loaderContext.getMpx()
|
|
35
|
+
const {
|
|
36
|
+
mode,
|
|
37
|
+
defs,
|
|
38
|
+
wxsContentMap,
|
|
39
|
+
decodeHTMLText,
|
|
40
|
+
externalClasses,
|
|
41
|
+
checkUsingComponents
|
|
42
|
+
// autoVirtualHostRules
|
|
43
|
+
} = mpx
|
|
44
|
+
const { resourcePath } = parseRequest(loaderContext.resource)
|
|
32
45
|
const builtInComponentsMap = {}
|
|
33
|
-
|
|
34
|
-
const mainCompilation = getMainCompilation(compilation)
|
|
35
|
-
const mpx = mainCompilation.__mpx__
|
|
36
|
-
const wxsContentMap = mpx.wxsContentMap
|
|
46
|
+
|
|
37
47
|
let wxsModuleMap, genericsInfo
|
|
38
48
|
let output = '/* template */\n'
|
|
39
49
|
|
|
@@ -43,7 +53,7 @@ module.exports = function (template, options, callback) {
|
|
|
43
53
|
content: '<div class="app"><mpx-keep-alive><router-view class="page"></router-view></mpx-keep-alive></div>'
|
|
44
54
|
}
|
|
45
55
|
builtInComponentsMap['mpx-keep-alive'] = {
|
|
46
|
-
resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', {
|
|
56
|
+
resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', { isComponent: true })
|
|
47
57
|
}
|
|
48
58
|
}
|
|
49
59
|
|
|
@@ -62,7 +72,7 @@ module.exports = function (template, options, callback) {
|
|
|
62
72
|
}
|
|
63
73
|
if (template.content) {
|
|
64
74
|
const templateSrcMode = template.mode || srcMode
|
|
65
|
-
const
|
|
75
|
+
const { root, meta } = templateCompiler.parse(template.content, {
|
|
66
76
|
warn: (msg) => {
|
|
67
77
|
loaderContext.emitWarning(
|
|
68
78
|
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
@@ -73,54 +83,59 @@ module.exports = function (template, options, callback) {
|
|
|
73
83
|
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
74
84
|
)
|
|
75
85
|
},
|
|
76
|
-
usingComponents
|
|
77
|
-
hasComment
|
|
78
|
-
isNative
|
|
79
|
-
basename: path.basename(resourcePath),
|
|
86
|
+
usingComponents,
|
|
87
|
+
hasComment,
|
|
88
|
+
isNative,
|
|
80
89
|
isComponent: ctorType === 'component',
|
|
81
90
|
mode,
|
|
82
91
|
srcMode: templateSrcMode,
|
|
83
92
|
defs,
|
|
84
|
-
decodeHTMLText
|
|
85
|
-
externalClasses
|
|
93
|
+
decodeHTMLText,
|
|
94
|
+
externalClasses,
|
|
86
95
|
// todo 后续输出web也采用mpx的scoped处理
|
|
87
|
-
// hasScoped:options.hasScoped,
|
|
88
96
|
hasScoped: false,
|
|
89
97
|
moduleId,
|
|
90
|
-
filePath:
|
|
98
|
+
filePath: resourcePath,
|
|
91
99
|
i18n: null,
|
|
92
|
-
checkUsingComponents
|
|
100
|
+
checkUsingComponents,
|
|
93
101
|
// web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
|
|
94
102
|
globalComponents: [],
|
|
95
103
|
// web模式下实现抽象组件
|
|
96
|
-
componentGenerics
|
|
104
|
+
componentGenerics
|
|
105
|
+
// todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
|
|
106
|
+
// hasVirtualHost: matchCondition(resourcePath, autoVirtualHostRules)
|
|
97
107
|
})
|
|
98
|
-
if (
|
|
99
|
-
wxsModuleMap =
|
|
108
|
+
if (meta.wxsModuleMap) {
|
|
109
|
+
wxsModuleMap = meta.wxsModuleMap
|
|
100
110
|
}
|
|
101
|
-
if (
|
|
102
|
-
for (let module in
|
|
103
|
-
wxsContentMap[`${resourcePath}~${module}`] =
|
|
111
|
+
if (meta.wxsContentMap) {
|
|
112
|
+
for (let module in meta.wxsContentMap) {
|
|
113
|
+
wxsContentMap[`${resourcePath}~${module}`] = meta.wxsContentMap[module]
|
|
104
114
|
}
|
|
105
115
|
}
|
|
106
|
-
if (
|
|
107
|
-
Object.keys(
|
|
116
|
+
if (meta.builtInComponentsMap) {
|
|
117
|
+
Object.keys(meta.builtInComponentsMap).forEach((name) => {
|
|
108
118
|
builtInComponentsMap[name] = {
|
|
109
|
-
resource: addQuery(
|
|
119
|
+
resource: addQuery(meta.builtInComponentsMap[name], { isComponent: true })
|
|
110
120
|
}
|
|
111
121
|
})
|
|
112
122
|
}
|
|
113
|
-
if (
|
|
114
|
-
genericsInfo =
|
|
123
|
+
if (meta.genericsInfo) {
|
|
124
|
+
genericsInfo = meta.genericsInfo
|
|
115
125
|
}
|
|
116
|
-
// 输出H5有多个root element时, 使用
|
|
117
|
-
|
|
118
|
-
|
|
126
|
+
// 输出H5有多个root element时, 使用mpx-root-view标签包裹
|
|
127
|
+
// todo 后续输出web也基于autoVirtualHostRules决定是否添加root wrapper
|
|
128
|
+
if (root.tag === 'temp-node') {
|
|
129
|
+
const childLen = calculateRootEleChild(root.children)
|
|
119
130
|
if (childLen >= 2) {
|
|
120
|
-
|
|
131
|
+
root.tag = 'div'
|
|
132
|
+
templateCompiler.addAttrs(root, [{
|
|
133
|
+
name: 'class',
|
|
134
|
+
value: 'mpx-root-view'
|
|
135
|
+
}])
|
|
121
136
|
}
|
|
122
137
|
}
|
|
123
|
-
return templateCompiler.serialize(
|
|
138
|
+
return templateCompiler.serialize(root)
|
|
124
139
|
}
|
|
125
140
|
})
|
|
126
141
|
output += '\n\n'
|
package/lib/wxml/loader.js
CHANGED
|
@@ -17,13 +17,10 @@ module.exports = function (content) {
|
|
|
17
17
|
const externals = mpx.externals
|
|
18
18
|
|
|
19
19
|
const { queryObj } = parseRequest(this.resource)
|
|
20
|
-
const moduleId = queryObj.moduleId
|
|
21
20
|
const hasScoped = false
|
|
22
21
|
const hasComment = false
|
|
23
22
|
const isNative = true
|
|
24
23
|
|
|
25
|
-
const usingComponents = []
|
|
26
|
-
|
|
27
24
|
const mode = mpx.mode
|
|
28
25
|
const localSrcMode = queryObj.mode
|
|
29
26
|
const customAttributes = options.attributes || mpx.attributes || []
|
|
@@ -90,8 +87,6 @@ module.exports = function (content) {
|
|
|
90
87
|
hasScoped,
|
|
91
88
|
hasComment,
|
|
92
89
|
isNative,
|
|
93
|
-
moduleId,
|
|
94
|
-
usingComponents,
|
|
95
90
|
isStatic: true
|
|
96
91
|
}
|
|
97
92
|
requestString = getRequestString('template', { src, mode: localSrcMode }, extraOptions)
|
|
@@ -99,7 +94,7 @@ module.exports = function (content) {
|
|
|
99
94
|
case config[mode].wxs.tag:
|
|
100
95
|
// 显式传递issuerResource避免模块缓存以及提供给wxs-loader计算相对路径
|
|
101
96
|
extraOptions = {
|
|
102
|
-
|
|
97
|
+
issuerResource: this.resource,
|
|
103
98
|
isStatic: true
|
|
104
99
|
}
|
|
105
100
|
requestString = getRequestString('wxs', { src, mode: localSrcMode }, extraOptions)
|
|
@@ -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/wxs/i18n-loader.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
// 该loader用于将用户定义的messages注入到i18n.wxs中
|
|
2
|
-
const getMainCompilation = require('../utils/get-main-compilation')
|
|
3
2
|
const loaderUtils = require('loader-utils')
|
|
4
3
|
|
|
5
4
|
module.exports = function (content) {
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
let prefix = 'var __mpx_messages__, __mpx_datetime_formats__, __mpx_number_formats__\n'
|
|
5
|
+
const i18n = this.getMpx().i18n
|
|
6
|
+
let prefix = 'var __mpx_messages__, __mpx_datetime_formats__, __mpx_number_formats__, __mpx_locale__\n'
|
|
9
7
|
if (i18n) {
|
|
10
8
|
if (i18n.messages) {
|
|
11
9
|
prefix += `__mpx_messages__ = ${JSON.stringify(i18n.messages)}\n`
|
|
@@ -22,6 +20,9 @@ module.exports = function (content) {
|
|
|
22
20
|
} else if (i18n.numberFormatsPath) {
|
|
23
21
|
prefix += `__mpx_number_formats__ = require(${loaderUtils.stringifyRequest(this, i18n.numberFormatsPath)})\n`
|
|
24
22
|
}
|
|
23
|
+
if (i18n.locale) {
|
|
24
|
+
prefix += `__mpx_locale__ = ${JSON.stringify(i18n.locale)}\n`
|
|
25
|
+
}
|
|
25
26
|
}
|
|
26
27
|
content = prefix + content
|
|
27
28
|
return content
|
package/lib/wxs/loader.js
CHANGED
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
const NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin')
|
|
2
2
|
const EntryPlugin = require('webpack/lib/EntryPlugin')
|
|
3
|
+
const LazySet = require('webpack/lib/util/LazySet')
|
|
3
4
|
const LimitChunkCountPlugin = require('webpack/lib/optimize/LimitChunkCountPlugin')
|
|
5
|
+
const FlagEntryExportAsUsedPlugin = require('webpack/lib/FlagEntryExportAsUsedPlugin')
|
|
4
6
|
const path = require('path')
|
|
5
7
|
const WxsPlugin = require('./WxsPlugin')
|
|
6
|
-
const
|
|
8
|
+
const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
|
|
7
9
|
const parseRequest = require('../utils/parse-request')
|
|
8
10
|
const toPosix = require('../utils/to-posix')
|
|
9
11
|
const fixRelative = require('../utils/fix-relative')
|
|
12
|
+
const addQuery = require('../utils/add-query')
|
|
10
13
|
const config = require('../config')
|
|
11
14
|
|
|
12
|
-
module.exports =
|
|
15
|
+
module.exports = content => content
|
|
16
|
+
|
|
17
|
+
module.exports.pitch = function (remainingRequest) {
|
|
13
18
|
const nativeCallback = this.async()
|
|
14
19
|
const moduleGraph = this._compilation.moduleGraph
|
|
15
20
|
const mpx = this.getMpx()
|
|
16
21
|
const mode = mpx.mode
|
|
17
|
-
const
|
|
18
|
-
const appInfo = mpx.appInfo
|
|
22
|
+
const getOutputPath = mpx.getOutputPath
|
|
19
23
|
let { resourcePath, queryObj } = parseRequest(this.resource)
|
|
20
24
|
const issuer = moduleGraph.getIssuer(this._module)
|
|
21
25
|
const { resourcePath: issuerResourcePath, queryObj: issuerQueryObj } = parseRequest(queryObj.issuerResource || issuer.resource)
|
|
22
|
-
const issuerPackageName = issuerQueryObj.packageRoot ||
|
|
26
|
+
const issuerPackageName = issuerQueryObj.packageRoot || 'main'
|
|
23
27
|
const pagesMap = mpx.pagesMap
|
|
24
28
|
const componentsMap = mpx.componentsMap[issuerPackageName]
|
|
25
29
|
const staticResourcesMap = mpx.staticResourcesMap[issuerPackageName]
|
|
26
|
-
const issuerName =
|
|
30
|
+
const issuerName = pagesMap[issuerResourcePath] || componentsMap[issuerResourcePath] || staticResourcesMap[issuerResourcePath]
|
|
27
31
|
const issuerDir = path.dirname(issuerName)
|
|
28
32
|
|
|
29
33
|
const getName = (raw) => {
|
|
@@ -36,9 +40,9 @@ module.exports = function () {
|
|
|
36
40
|
resourcePath = `${resourcePath}~${wxsModule}`
|
|
37
41
|
}
|
|
38
42
|
const packageRoot = queryObj.packageRoot || ''
|
|
39
|
-
const
|
|
40
|
-
const filename = toPosix(path.join(packageRoot,
|
|
41
|
-
this._module.addPresentationalDependency(new
|
|
43
|
+
const ext = config[mode].wxs.ext
|
|
44
|
+
const filename = toPosix(path.join(packageRoot, getOutputPath(resourcePath, ext.slice(1), { ext })))
|
|
45
|
+
this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'staticResource', filename, packageRoot))
|
|
42
46
|
|
|
43
47
|
const callback = (err) => {
|
|
44
48
|
if (err) return nativeCallback(err)
|
|
@@ -47,65 +51,92 @@ module.exports = function () {
|
|
|
47
51
|
nativeCallback(null, `module.exports = ${JSON.stringify(relativePath)};`)
|
|
48
52
|
}
|
|
49
53
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return callback()
|
|
53
|
-
}
|
|
54
|
+
// 清空issuerResource query避免文件内容输出报错并进行子编译缓存优化
|
|
55
|
+
const request = '!!' + addQuery(remainingRequest, {}, false, ['issuerResource'])
|
|
54
56
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
// request中已经包含全量构成filename的信息,故可以直接使用request作为key来进行缓存
|
|
58
|
+
if (!mpx.wxsAssetsCache.has(request)) {
|
|
59
|
+
mpx.wxsAssetsCache.set(request, new Promise((resolve, reject) => {
|
|
60
|
+
const outputOptions = {
|
|
61
|
+
filename,
|
|
62
|
+
// 避免输出的wxs中包含es语法
|
|
63
|
+
environment: {
|
|
64
|
+
// The environment supports arrow functions ('() => { ... }').
|
|
65
|
+
arrowFunction: false,
|
|
66
|
+
// The environment supports BigInt as literal (123n).
|
|
67
|
+
bigIntLiteral: false,
|
|
68
|
+
// The environment supports const and let for variable declarations.
|
|
69
|
+
const: false,
|
|
70
|
+
// The environment supports destructuring ('{ a, b } = obj').
|
|
71
|
+
destructuring: false,
|
|
72
|
+
// The environment supports an async import() function to import EcmaScript modules.
|
|
73
|
+
dynamicImport: false,
|
|
74
|
+
// The environment supports 'for of' iteration ('for (const x of array) { ... }').
|
|
75
|
+
forOf: false,
|
|
76
|
+
// The environment supports ECMAScript Module syntax to import ECMAScript modules (import ... from '...').
|
|
77
|
+
module: false
|
|
78
|
+
}
|
|
79
|
+
}
|
|
59
80
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
new NodeTargetPlugin(),
|
|
68
|
-
new EntryPlugin(this.context, request, { name: getName(filename) }),
|
|
69
|
-
new LimitChunkCountPlugin({ maxChunks: 1 })
|
|
70
|
-
]
|
|
81
|
+
const plugins = [
|
|
82
|
+
new WxsPlugin({ mode }),
|
|
83
|
+
new NodeTargetPlugin(),
|
|
84
|
+
new EntryPlugin(this.context, request, { name: getName(filename) }),
|
|
85
|
+
new LimitChunkCountPlugin({ maxChunks: 1 }),
|
|
86
|
+
new FlagEntryExportAsUsedPlugin(true, 'entry')
|
|
87
|
+
]
|
|
71
88
|
|
|
72
|
-
|
|
89
|
+
const childCompiler = this._compilation.createChildCompiler(resourcePath, outputOptions, plugins)
|
|
73
90
|
|
|
74
|
-
|
|
75
|
-
// childCompiler.hooks.thisCompilation.tap('MpxWebpackPlugin ', (compilation) => {
|
|
76
|
-
// compilation.hooks.succeedEntry.tap('MpxWebpackPlugin', (entry, name, module) => {
|
|
77
|
-
// entryModule = module
|
|
78
|
-
// // const dep = new ChildCompileDependency(entryModule)
|
|
79
|
-
// // wxsMap[filename].dep = dep
|
|
80
|
-
// })
|
|
81
|
-
// })
|
|
91
|
+
let assets = []
|
|
82
92
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
compilation.clearAssets()
|
|
89
|
-
})
|
|
93
|
+
childCompiler.hooks.afterCompile.tap('MpxWebpackPlugin', (compilation) => {
|
|
94
|
+
// 持久化缓存,使用module.buildInfo.assets来输出文件
|
|
95
|
+
assets = compilation.getAssets()
|
|
96
|
+
compilation.clearAssets()
|
|
97
|
+
})
|
|
90
98
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
99
|
+
childCompiler.runAsChild((err, entries, compilation) => {
|
|
100
|
+
if (err) return reject(err)
|
|
101
|
+
const fileDependencies = new LazySet()
|
|
102
|
+
const contextDependencies = new LazySet()
|
|
103
|
+
const missingDependencies = new LazySet()
|
|
104
|
+
const buildDependencies = new LazySet()
|
|
105
|
+
compilation.modules.forEach((module) => {
|
|
106
|
+
module.addCacheDependencies(
|
|
107
|
+
fileDependencies,
|
|
108
|
+
contextDependencies,
|
|
109
|
+
missingDependencies,
|
|
110
|
+
buildDependencies
|
|
111
|
+
)
|
|
112
|
+
})
|
|
113
|
+
resolve({
|
|
114
|
+
assets,
|
|
115
|
+
fileDependencies,
|
|
116
|
+
contextDependencies,
|
|
117
|
+
missingDependencies,
|
|
118
|
+
buildDependencies
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
}))
|
|
122
|
+
}
|
|
96
123
|
|
|
97
|
-
|
|
124
|
+
mpx.wxsAssetsCache.get(request).then(({ assets, fileDependencies, contextDependencies, missingDependencies, buildDependencies }) => {
|
|
125
|
+
assets.forEach(({ name, source, info }) => {
|
|
126
|
+
this.emitFile(name, source.source(), undefined, info)
|
|
127
|
+
})
|
|
128
|
+
fileDependencies.forEach((dep) => {
|
|
98
129
|
this.addDependency(dep)
|
|
99
|
-
}
|
|
100
|
-
|
|
130
|
+
})
|
|
131
|
+
contextDependencies.forEach((dep) => {
|
|
101
132
|
this.addContextDependency(dep)
|
|
102
|
-
}
|
|
103
|
-
|
|
133
|
+
})
|
|
134
|
+
missingDependencies.forEach((dep) => {
|
|
104
135
|
this.addMissingDependency(dep)
|
|
105
136
|
})
|
|
106
|
-
|
|
137
|
+
buildDependencies.forEach((dep) => {
|
|
107
138
|
this.addBuildDependency(dep)
|
|
108
139
|
})
|
|
109
140
|
callback()
|
|
110
|
-
})
|
|
141
|
+
}).catch(callback)
|
|
111
142
|
}
|
package/lib/wxs/pre-loader.js
CHANGED
|
@@ -1,22 +1,21 @@
|
|
|
1
|
-
const babylon = require('
|
|
2
|
-
const traverse = require('babel
|
|
3
|
-
const t = require('babel
|
|
4
|
-
const generate = require('babel
|
|
5
|
-
const getMainCompilation = require('../utils/get-main-compilation')
|
|
1
|
+
const babylon = require('@babel/parser')
|
|
2
|
+
const traverse = require('@babel/traverse').default
|
|
3
|
+
const t = require('@babel/types')
|
|
4
|
+
const generate = require('@babel/generator').default
|
|
6
5
|
const parseRequest = require('../utils/parse-request')
|
|
7
6
|
const isEmptyObject = require('../utils/is-empty-object')
|
|
8
7
|
const parseQuery = require('loader-utils').parseQuery
|
|
9
8
|
|
|
10
9
|
module.exports = function (content) {
|
|
11
10
|
this.cacheable()
|
|
12
|
-
const
|
|
11
|
+
const mpx = this.getMpx()
|
|
13
12
|
const module = this._module
|
|
14
|
-
const mode =
|
|
13
|
+
const mode = mpx.mode
|
|
15
14
|
const wxsModule = parseQuery(this.resourceQuery || '?').wxsModule
|
|
16
15
|
|
|
17
16
|
// 处理内联wxs
|
|
18
17
|
if (wxsModule) {
|
|
19
|
-
const wxsContentMap =
|
|
18
|
+
const wxsContentMap = mpx.wxsContentMap
|
|
20
19
|
const resourcePath = parseRequest(this.resource).resourcePath
|
|
21
20
|
content = wxsContentMap[`${resourcePath}~${wxsModule}`] || content
|
|
22
21
|
}
|
|
@@ -40,11 +39,25 @@ module.exports = function (content) {
|
|
|
40
39
|
let results = targetPath.unshiftContainer('body', insertNodes) || []
|
|
41
40
|
targetPath.inserted = true
|
|
42
41
|
results.forEach((item) => {
|
|
43
|
-
item.
|
|
42
|
+
item.shouldStopTraverse = true
|
|
44
43
|
})
|
|
45
44
|
}
|
|
46
45
|
}
|
|
47
46
|
},
|
|
47
|
+
CallExpression (path) {
|
|
48
|
+
const callee = path.node.callee
|
|
49
|
+
if (t.isIdentifier(callee) && callee.name === 'getRegExp') {
|
|
50
|
+
const argPath = path.get('arguments')[0]
|
|
51
|
+
if (argPath.isStringLiteral()) {
|
|
52
|
+
argPath.replaceWith(t.stringLiteral(argPath.node.extra.raw.slice(1, -1)))
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
ForStatement (path) {
|
|
57
|
+
if (path.shouldStopTraverse) {
|
|
58
|
+
path.stop()
|
|
59
|
+
}
|
|
60
|
+
},
|
|
48
61
|
// 处理vant-aliapp中export var bem = bem;这种不被acorn支持的2b语法
|
|
49
62
|
ExportNamedDeclaration (path) {
|
|
50
63
|
if (
|
|
@@ -88,12 +101,19 @@ module.exports = function (content) {
|
|
|
88
101
|
},
|
|
89
102
|
CallExpression (path) {
|
|
90
103
|
const callee = path.node.callee
|
|
104
|
+
const args = path.node.arguments
|
|
91
105
|
const transMap = {
|
|
92
106
|
getDate: 'Date',
|
|
93
107
|
getRegExp: 'RegExp'
|
|
94
108
|
}
|
|
95
109
|
if (t.isIdentifier(callee) && transMap[callee.name]) {
|
|
96
|
-
|
|
110
|
+
if (callee.name === 'getRegExp') {
|
|
111
|
+
const arg = args[0]
|
|
112
|
+
if (t.isStringLiteral(arg)) {
|
|
113
|
+
args[0] = t.stringLiteral(arg.extra.raw.slice(1, -1))
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
path.replaceWith(t.newExpression(t.identifier(transMap[callee.name]), args))
|
|
97
117
|
}
|
|
98
118
|
}
|
|
99
119
|
})
|
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 + ');') + ', ' +
|
|
@@ -73,9 +73,9 @@ module.exports = function (content, map) {
|
|
|
73
73
|
} else {
|
|
74
74
|
const requestString = getRequestString('styles', { src: imp.url }, {
|
|
75
75
|
isStatic: true,
|
|
76
|
-
|
|
76
|
+
issuerResource: 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 + ') +' +
|