@mpxjs/webpack-plugin 2.6.115 → 2.7.0-alpha
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/LICENSE +433 -0
- package/README.md +1 -1
- package/lib/config.js +14 -0
- package/lib/dependencies/AddEntryDependency.js +24 -0
- package/lib/dependencies/AppEntryDependency.js +58 -0
- package/lib/dependencies/CommonJsAsyncDependency.js +51 -0
- package/lib/dependencies/CommonJsVariableDependency.js +81 -0
- package/lib/dependencies/DynamicEntryDependency.js +171 -0
- package/lib/dependencies/FlagPluginDependency.js +24 -0
- package/lib/dependencies/InjectDependency.js +43 -0
- package/lib/dependencies/RecordGlobalComponentsDependency.js +50 -0
- package/lib/dependencies/RecordIndependentDependency.js +44 -0
- package/lib/dependencies/RecordResourceMapDependency.js +62 -0
- package/lib/dependencies/RemoveEntryDependency.js +40 -0
- package/lib/{dependency → dependencies}/ReplaceDependency.js +19 -2
- package/lib/dependencies/ResolveDependency.js +88 -0
- package/lib/extractor.js +82 -178
- package/lib/file-loader.js +7 -19
- package/lib/helpers.js +39 -334
- package/lib/independent-loader.js +52 -0
- package/lib/index.js +889 -525
- package/lib/json-compiler/helper.js +156 -0
- package/lib/json-compiler/index.js +245 -451
- package/lib/json-compiler/plugin.js +150 -0
- package/lib/json-compiler/{theme-loader.js → theme.js} +5 -3
- package/lib/loader.js +178 -241
- package/lib/native-loader.js +71 -133
- package/lib/parser.js +1 -2
- package/lib/partial-compile/index.js +35 -0
- package/lib/platform/json/wx/index.js +1 -1
- package/lib/platform/template/normalize-component-rules.js +2 -3
- package/lib/platform/template/wx/component-config/button.js +14 -2
- 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/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 +11 -0
- package/lib/resolve-loader.js +6 -0
- 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 +1 -3
- package/lib/runtime/components/web/mpx-image.vue +20 -5
- package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
- package/lib/runtime/components/web/mpx-swiper.vue +18 -3
- package/lib/runtime/i18n.wxs +31 -11
- package/lib/runtime/optionProcessor.js +48 -3
- package/lib/runtime/optionProcessor.tenon.js +386 -0
- package/lib/selector.js +29 -10
- package/lib/style-compiler/index.js +16 -24
- 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 +22 -16
- package/lib/template-compiler/compiler.js +106 -199
- package/lib/template-compiler/index.js +52 -139
- package/lib/template-compiler/trans-dynamic-class-expr.js +18 -13
- 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/url-loader.js +11 -29
- package/lib/utils/add-query.js +1 -1
- package/lib/utils/const.js +10 -0
- package/lib/utils/emit-file.js +10 -0
- package/lib/utils/eval-json-js.js +31 -0
- package/lib/utils/get-entry-name.js +13 -0
- package/lib/utils/get-json-content.js +42 -0
- package/lib/utils/get-relative-path.js +25 -0
- package/lib/utils/is-url-request.js +10 -1
- package/lib/utils/match-condition.js +4 -1
- package/lib/utils/normalize.js +4 -15
- package/lib/utils/parse-request.js +3 -3
- package/lib/utils/resolve.js +13 -0
- package/lib/utils/set.js +47 -0
- package/lib/utils/stringify-loaders-resource.js +25 -0
- package/lib/utils/stringify-query.js +4 -0
- package/lib/web/processJSON.js +113 -144
- package/lib/web/processScript.js +47 -34
- package/lib/web/processTemplate.js +57 -40
- package/lib/wxml/{wxml-loader.js → loader.js} +21 -62
- package/lib/wxs/WxsModuleIdsPlugin.js +29 -0
- package/lib/wxs/WxsParserPlugin.js +2 -2
- package/lib/wxs/WxsPlugin.js +4 -8
- package/lib/wxs/WxsTemplatePlugin.js +46 -92
- package/lib/wxs/{wxs-i18n-loader.js → i18n-loader.js} +5 -4
- package/lib/wxs/loader.js +142 -0
- package/lib/wxs/{wxs-pre-loader.js → pre-loader.js} +20 -5
- package/lib/wxss/loader.js +31 -43
- package/lib/wxss/localsLoader.js +1 -5
- package/lib/wxss/processCss.js +107 -103
- package/package.json +21 -18
- package/lib/built-in-loader.js +0 -49
- package/lib/content-loader.js +0 -13
- package/lib/dependency/ChildCompileDependency.js +0 -24
- package/lib/dependency/InjectDependency.js +0 -26
- package/lib/dependency/RemovedModuleDependency.js +0 -23
- package/lib/dependency/ResolveDependency.js +0 -49
- package/lib/path-loader.js +0 -3
- package/lib/plugin-loader.js +0 -287
- package/lib/staticConfig.js +0 -4
- package/lib/utils/get-main-compilation.js +0 -6
- package/lib/utils/read-json-for-src.js +0 -34
- package/lib/utils/try-require.js +0 -16
- package/lib/wxs/wxs-loader.js +0 -117
- package/lib/wxss/getImportPrefix.js +0 -30
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0-alpha",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -27,12 +27,15 @@
|
|
|
27
27
|
"@better-scroll/slide": "^2.2.1",
|
|
28
28
|
"@better-scroll/wheel": "^2.2.1",
|
|
29
29
|
"@better-scroll/zoom": "^2.2.1",
|
|
30
|
+
"@hummer/tenon-dev-server-webpack-plugin": "0.0.2",
|
|
31
|
+
"@hummer/tenon-loader": "^1.1.0",
|
|
32
|
+
"@hummer/tenon-style-loader": "^0.2.0",
|
|
30
33
|
"acorn-walk": "^7.2.0",
|
|
31
34
|
"async": "^2.6.0",
|
|
32
35
|
"consolidate": "^0.15.1",
|
|
33
36
|
"css": "^2.2.1",
|
|
34
37
|
"css-selector-tokenizer": "^0.7.0",
|
|
35
|
-
"cssnano": "^
|
|
38
|
+
"cssnano": "^5.0.16",
|
|
36
39
|
"de-indent": "^1.0.2",
|
|
37
40
|
"fastparse": "^1.1.1",
|
|
38
41
|
"hash-sum": "^1.0.2",
|
|
@@ -40,28 +43,24 @@
|
|
|
40
43
|
"html-minifier": "^3.5.8",
|
|
41
44
|
"icss-utils": "^2.1.0",
|
|
42
45
|
"json5": "^2.1.3",
|
|
43
|
-
"loader-utils": "
|
|
46
|
+
"loader-utils": "^2.0.2",
|
|
44
47
|
"lodash": "^4.17.15",
|
|
45
48
|
"lodash.camelcase": "^4.3.0",
|
|
46
49
|
"lru-cache": "^4.1.2",
|
|
47
50
|
"mime": "^2.2.2",
|
|
48
51
|
"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": "^
|
|
57
|
-
"
|
|
58
|
-
"source-list-map": "^2.0.0",
|
|
59
|
-
"webpack-sources": "^1.1.0"
|
|
52
|
+
"postcss": "^8.4.5",
|
|
53
|
+
"postcss-load-config": "^3.1.1",
|
|
54
|
+
"postcss-modules-extract-imports": "^3.0.0",
|
|
55
|
+
"postcss-modules-local-by-default": "^4.0.0",
|
|
56
|
+
"postcss-modules-scope": "^3.0.0",
|
|
57
|
+
"postcss-modules-values": "^4.0.0",
|
|
58
|
+
"postcss-selector-parser": "^6.0.8",
|
|
59
|
+
"postcss-value-parser": "^4.0.2",
|
|
60
|
+
"source-list-map": "^2.0.0"
|
|
60
61
|
},
|
|
61
62
|
"peerDependencies": {
|
|
62
|
-
"
|
|
63
|
-
"webpack": "^4.0.0",
|
|
64
|
-
"webpack-cli": "^3.0.0"
|
|
63
|
+
"webpack": "^5.48.0"
|
|
65
64
|
},
|
|
66
65
|
"publishConfig": {
|
|
67
66
|
"registry": "https://registry.npmjs.org"
|
|
@@ -80,5 +79,9 @@
|
|
|
80
79
|
"devDependencies": {
|
|
81
80
|
"@types/babel-traverse": "^6.25.4",
|
|
82
81
|
"@types/babel-types": "^7.0.4"
|
|
83
|
-
}
|
|
82
|
+
},
|
|
83
|
+
"engines": {
|
|
84
|
+
"node": ">=14.14.0"
|
|
85
|
+
},
|
|
86
|
+
"gitHead": "00ed5b8ad381d9b718828b5e169b1ce5cc45c3a6"
|
|
84
87
|
}
|
package/lib/built-in-loader.js
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const parseComponent = require('./parser')
|
|
2
|
-
const loaderUtils = require('loader-utils')
|
|
3
|
-
const parseRequest = require('./utils/parse-request')
|
|
4
|
-
const normalize = require('./utils/normalize')
|
|
5
|
-
const selectorPath = normalize.lib('selector')
|
|
6
|
-
const genComponentTag = require('./utils/gen-component-tag')
|
|
7
|
-
const getMainCompilation = require('./utils/get-main-compilation')
|
|
8
|
-
|
|
9
|
-
module.exports = function (content) {
|
|
10
|
-
this.cacheable()
|
|
11
|
-
const mainCompilation = getMainCompilation(this._compilation)
|
|
12
|
-
const mpx = mainCompilation.__mpx__
|
|
13
|
-
if (!mpx) {
|
|
14
|
-
return content
|
|
15
|
-
}
|
|
16
|
-
const mode = mpx.mode
|
|
17
|
-
const env = mpx.env
|
|
18
|
-
const defs = mpx.defs
|
|
19
|
-
const resourcePath = parseRequest(this.resource).resourcePath
|
|
20
|
-
const parts = parseComponent(content, {
|
|
21
|
-
filePath: resourcePath,
|
|
22
|
-
needMap: this.sourceMap,
|
|
23
|
-
mode,
|
|
24
|
-
defs,
|
|
25
|
-
env
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
let output = ''
|
|
29
|
-
|
|
30
|
-
// 内建组件编写规范比较统一,不需要处理太多情况
|
|
31
|
-
if (parts.template) {
|
|
32
|
-
output += genComponentTag(parts.template)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (parts.script) {
|
|
36
|
-
output += '\n' + genComponentTag(parts.script, (script) => {
|
|
37
|
-
let content = ''
|
|
38
|
-
if (parts.styles && parts.styles.length) {
|
|
39
|
-
parts.styles.forEach((style, i) => {
|
|
40
|
-
const requestString = loaderUtils.stringifyRequest(this, `builtInComponent.styl!=!${selectorPath}?type=styles&index=${i}!${loaderUtils.getRemainingRequest(this)}`)
|
|
41
|
-
content += `\n import ${requestString}`
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
content += script.content
|
|
45
|
-
return content
|
|
46
|
-
})
|
|
47
|
-
}
|
|
48
|
-
return output
|
|
49
|
-
}
|
package/lib/content-loader.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
module.exports = function (content) {
|
|
2
|
-
if (!this.__mpx__) {
|
|
3
|
-
return content
|
|
4
|
-
}
|
|
5
|
-
// todo 由于additionalAssets阶段还会进行一次依赖同步,此处获取的依赖不一定是最终的依赖,可能会有bad case
|
|
6
|
-
this.__mpx__.fileDependencies.forEach(file => {
|
|
7
|
-
this.addDependency(file)
|
|
8
|
-
})
|
|
9
|
-
this.__mpx__.contextDependencies.forEach(context => {
|
|
10
|
-
this.addContextDependency(context)
|
|
11
|
-
})
|
|
12
|
-
return this.__mpx__.content
|
|
13
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
-
|
|
3
|
-
class ChildCompileDependency extends NullDependency {
|
|
4
|
-
constructor (module) {
|
|
5
|
-
super()
|
|
6
|
-
this.childCompileEntryModule = module
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
get type () {
|
|
10
|
-
return 'mpx child compile'
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
updateHash (hash) {
|
|
14
|
-
super.updateHash(hash)
|
|
15
|
-
hash.update(this.childCompileEntryModule.identifier())
|
|
16
|
-
}
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
ChildCompileDependency.Template = class ChildCompileDependencyTemplate {
|
|
20
|
-
apply () {
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
module.exports = ChildCompileDependency
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
-
|
|
3
|
-
class InjectDependency extends NullDependency {
|
|
4
|
-
constructor (options) {
|
|
5
|
-
super()
|
|
6
|
-
this.content = options.content
|
|
7
|
-
this.index = options.index || 0
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
get type () {
|
|
11
|
-
return 'mpx inject'
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
updateHash (hash) {
|
|
15
|
-
super.updateHash(hash)
|
|
16
|
-
hash.update(this.content)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
InjectDependency.Template = class InjectDependencyTemplate {
|
|
21
|
-
apply (dep, source) {
|
|
22
|
-
source.insert(dep.index, '/* mpx inject */ ' + dep.content)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
module.exports = InjectDependency
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const ModuleDependency = require('webpack/lib/dependencies//ModuleDependency')
|
|
2
|
-
|
|
3
|
-
class RemovedModuleDependency extends ModuleDependency {
|
|
4
|
-
constructor (request, removedModule, range) {
|
|
5
|
-
super(request)
|
|
6
|
-
this.removedModule = removedModule
|
|
7
|
-
this.range = range
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
get type () {
|
|
11
|
-
return 'removed module'
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
RemovedModuleDependency.Template = class RemovedModuleDependencyTemplate {
|
|
16
|
-
apply (dep, source) {
|
|
17
|
-
if (dep.range) {
|
|
18
|
-
source.replace(dep.range[0], dep.range[1] - 1, '')
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
module.exports = RemovedModuleDependency
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
const NullDependency = require('webpack/lib/dependencies/NullDependency')
|
|
2
|
-
const parseRequest = require('../utils/parse-request')
|
|
3
|
-
|
|
4
|
-
class ResolveDependency extends NullDependency {
|
|
5
|
-
constructor (resource, packageName, pagesMap, componentsMap, staticResourcesMap, publicPath, range, issuerResource, compilation) {
|
|
6
|
-
super()
|
|
7
|
-
this.resource = resource
|
|
8
|
-
this.packageName = packageName
|
|
9
|
-
this.pagesMap = pagesMap
|
|
10
|
-
this.componentsMap = componentsMap
|
|
11
|
-
this.staticResourcesMap = staticResourcesMap
|
|
12
|
-
this.publicPath = publicPath
|
|
13
|
-
this.range = range
|
|
14
|
-
this.issuerResource = issuerResource
|
|
15
|
-
this.compilation = compilation
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get type () {
|
|
19
|
-
return 'mpx resolve'
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
updateHash (hash) {
|
|
23
|
-
super.updateHash(hash)
|
|
24
|
-
hash.update(this.resource)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
ResolveDependency.Template = class ResolveDependencyTemplate {
|
|
29
|
-
apply (dep, source) {
|
|
30
|
-
const content = this.getContent(dep)
|
|
31
|
-
source.replace(dep.range[0], dep.range[1] - 1, content)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getContent (dep) {
|
|
35
|
-
const resourcePath = parseRequest(dep.resource).resourcePath
|
|
36
|
-
const pagesMap = dep.pagesMap
|
|
37
|
-
const componentsMap = dep.componentsMap[dep.packageName]
|
|
38
|
-
const mainComponentsMap = dep.componentsMap.main
|
|
39
|
-
const staticResourcesMap = dep.staticResourcesMap[dep.packageName]
|
|
40
|
-
const mainStaticResourcesMap = dep.staticResourcesMap.main
|
|
41
|
-
const resolved = pagesMap[resourcePath] || componentsMap[resourcePath] || mainComponentsMap[resourcePath] || staticResourcesMap[resourcePath] || mainStaticResourcesMap[resourcePath] || ''
|
|
42
|
-
if (!resolved) {
|
|
43
|
-
dep.compilation.errors.push(new Error(`Path ${dep.resource} is not a page/component/static resource, which is resolved from ${dep.issuerResource}!`))
|
|
44
|
-
}
|
|
45
|
-
return JSON.stringify(dep.publicPath + resolved)
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
module.exports = ResolveDependency
|
package/lib/path-loader.js
DELETED
package/lib/plugin-loader.js
DELETED
|
@@ -1,287 +0,0 @@
|
|
|
1
|
-
const path = require('path')
|
|
2
|
-
const async = require('async')
|
|
3
|
-
const JSON5 = require('json5')
|
|
4
|
-
const SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin')
|
|
5
|
-
const parseRequest = require('./utils/parse-request')
|
|
6
|
-
const toPosix = require('./utils/to-posix')
|
|
7
|
-
const getMainCompilation = require('./utils/get-main-compilation')
|
|
8
|
-
const isUrlRequestRaw = require('./utils/is-url-request')
|
|
9
|
-
const loaderUtils = require('loader-utils')
|
|
10
|
-
const normalize = require('./utils/normalize')
|
|
11
|
-
const addQuery = require('./utils/add-query')
|
|
12
|
-
const nativeLoaderPath = normalize.lib('native-loader')
|
|
13
|
-
|
|
14
|
-
// webpack4中.json文件会走json parser,抽取内容的占位内容必须为合法json,否则会在parse阶段报错
|
|
15
|
-
const defaultResultSource = '{}'
|
|
16
|
-
|
|
17
|
-
// ali不导出的插件页面的固定prefix
|
|
18
|
-
const NO_EXPORT = '__mpx_plugin_no_export_page__'
|
|
19
|
-
|
|
20
|
-
module.exports = function (source) {
|
|
21
|
-
// 该loader中会在每次编译中动态添加entry,不能缓存,否则watch不好使
|
|
22
|
-
this.cacheable(false)
|
|
23
|
-
|
|
24
|
-
const nativeCallback = this.async()
|
|
25
|
-
const mainCompilation = getMainCompilation(this._compilation)
|
|
26
|
-
const mpx = mainCompilation.__mpx__
|
|
27
|
-
|
|
28
|
-
mpx.isPluginMode = true
|
|
29
|
-
|
|
30
|
-
const isUrlRequest = r => isUrlRequestRaw(r, projectRoot)
|
|
31
|
-
const urlToRequest = r => loaderUtils.urlToRequest(r, projectRoot)
|
|
32
|
-
const resolve = (context, request, callback) => {
|
|
33
|
-
const { queryObj } = parseRequest(request)
|
|
34
|
-
context = queryObj.context || context
|
|
35
|
-
return this.resolve(context, request, callback)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const emitWarning = (msg) => {
|
|
39
|
-
this.emitWarning(
|
|
40
|
-
new Error('[plugin loader][' + this.resource + ']: ' + msg)
|
|
41
|
-
)
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const emitError = (msg) => {
|
|
45
|
-
this.emitError(
|
|
46
|
-
new Error('[plugin loader][' + this.resource + ']: ' + msg)
|
|
47
|
-
)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
if (!mpx) {
|
|
51
|
-
return nativeCallback(null, source)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const context = this.context
|
|
55
|
-
const packageName = 'main'
|
|
56
|
-
const pagesMap = mpx.pagesMap
|
|
57
|
-
const getOutputPath = mpx.getOutputPath
|
|
58
|
-
const componentsMap = mpx.componentsMap[packageName]
|
|
59
|
-
const getEntryNode = mpx.getEntryNode
|
|
60
|
-
const resolveMode = mpx.resolveMode
|
|
61
|
-
const projectRoot = mpx.projectRoot
|
|
62
|
-
const extract = mpx.extract
|
|
63
|
-
const pathHash = mpx.pathHash
|
|
64
|
-
const resourceName = this._compilation._preparedEntrypoints[0].name
|
|
65
|
-
|
|
66
|
-
const entryModule = this._module
|
|
67
|
-
// 通过rawRequest关联entryNode和entryModule
|
|
68
|
-
const entryRequest = entryModule.rawRequest
|
|
69
|
-
const entryType = 'Plugin'
|
|
70
|
-
const currentEntry = getEntryNode(entryRequest, entryType, entryModule)
|
|
71
|
-
// 最终输出中不需要为plugin.json产生chunk,而是使用extract直接输出json文件,删除plugin.json对应的entrypoint
|
|
72
|
-
this._compilation._preparedEntrypoints.pop()
|
|
73
|
-
// 为了在体积统计中能够统计到该entry,将其缓存在mpx.removedChunks中
|
|
74
|
-
mpx.removedChunks.push({
|
|
75
|
-
entryModule
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
let entryDeps = new Set()
|
|
79
|
-
|
|
80
|
-
let cacheCallback
|
|
81
|
-
|
|
82
|
-
const checkEntryDeps = (callback) => {
|
|
83
|
-
callback = callback || cacheCallback
|
|
84
|
-
if (callback && entryDeps.size === 0) {
|
|
85
|
-
callback()
|
|
86
|
-
} else {
|
|
87
|
-
cacheCallback = callback
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const addEntrySafely = (resource, name, callback) => {
|
|
92
|
-
const dep = SingleEntryPlugin.createDependency(resource, name)
|
|
93
|
-
entryDeps.add(dep)
|
|
94
|
-
this._compilation.addEntry(this._compiler.context, dep, name, (err, module) => {
|
|
95
|
-
entryDeps.delete(dep)
|
|
96
|
-
checkEntryDeps()
|
|
97
|
-
callback(err, module)
|
|
98
|
-
})
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// 初次处理json
|
|
102
|
-
const callback = (err) => {
|
|
103
|
-
checkEntryDeps(() => {
|
|
104
|
-
if (err) return nativeCallback(err)
|
|
105
|
-
if (mpx.mode === 'ali' && pluginEntry.pages) {
|
|
106
|
-
let publicPages = Object.keys(pluginEntry.pages).reduce((cur, key) => {
|
|
107
|
-
if (!key.startsWith(NO_EXPORT)) {
|
|
108
|
-
cur[key] = pluginEntry.pages[key]
|
|
109
|
-
}
|
|
110
|
-
return cur
|
|
111
|
-
}, {})
|
|
112
|
-
pluginEntry.publicPages = publicPages
|
|
113
|
-
pluginEntry.pages = Object.values(pluginEntry.pages)
|
|
114
|
-
}
|
|
115
|
-
const sideEffects = []
|
|
116
|
-
const file = resourceName + '.json'
|
|
117
|
-
sideEffects.push((additionalAssets) => {
|
|
118
|
-
additionalAssets[file].modules = additionalAssets[file].modules || []
|
|
119
|
-
additionalAssets[file].modules.push(entryModule)
|
|
120
|
-
})
|
|
121
|
-
extract(JSON.stringify(pluginEntry), file, 0, sideEffects)
|
|
122
|
-
nativeCallback(null, defaultResultSource)
|
|
123
|
-
})
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
let pluginEntry
|
|
127
|
-
try {
|
|
128
|
-
pluginEntry = JSON5.parse(source)
|
|
129
|
-
} catch (err) {
|
|
130
|
-
return callback(err)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
let processMain, processComponents, processPages
|
|
134
|
-
|
|
135
|
-
processMain = processComponents = processPages = (callback) => {
|
|
136
|
-
callback()
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (pluginEntry.main) {
|
|
140
|
-
processMain = function (main, callback) {
|
|
141
|
-
if (!isUrlRequest(main)) return callback()
|
|
142
|
-
if (resolveMode === 'native') {
|
|
143
|
-
main = urlToRequest(main)
|
|
144
|
-
}
|
|
145
|
-
resolve(context, main, (err, resource) => {
|
|
146
|
-
if (err) return callback(err)
|
|
147
|
-
const { resourcePath } = parseRequest(resource)
|
|
148
|
-
// 获取pageName
|
|
149
|
-
const relative = path.relative(context, resourcePath)
|
|
150
|
-
const mainPath = toPosix(/^(.*?)(\.[^.]*)?$/.exec(relative)[1])
|
|
151
|
-
if (/^\./.test(mainPath)) {
|
|
152
|
-
emitError(`The plugin's main path [${main}] must be in the context [${context}]!`)
|
|
153
|
-
return callback()
|
|
154
|
-
}
|
|
155
|
-
pluginEntry.main = mainPath + '.js'
|
|
156
|
-
addEntrySafely(resource, mainPath, (err, module) => {
|
|
157
|
-
if (err) return callback(err)
|
|
158
|
-
mpx.pluginMainModule = module
|
|
159
|
-
currentEntry.addChild(getEntryNode(resource, 'PluginMain', module))
|
|
160
|
-
callback(err, module)
|
|
161
|
-
})
|
|
162
|
-
})
|
|
163
|
-
}.bind(this, pluginEntry.main)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (pluginEntry.publicComponents) {
|
|
167
|
-
processComponents = function (components, callback) {
|
|
168
|
-
async.forEachOf(components, (component, name, callback) => {
|
|
169
|
-
if (!isUrlRequest(component)) return callback()
|
|
170
|
-
if (resolveMode === 'native') {
|
|
171
|
-
component = urlToRequest(component)
|
|
172
|
-
}
|
|
173
|
-
resolve(context, component, (err, resource, info) => {
|
|
174
|
-
if (err) return callback(err)
|
|
175
|
-
const resourcePath = parseRequest(resource).resourcePath
|
|
176
|
-
const parsed = path.parse(resourcePath)
|
|
177
|
-
const ext = parsed.ext
|
|
178
|
-
let outputPath
|
|
179
|
-
if (ext === '.js') {
|
|
180
|
-
let root = info.descriptionFileRoot
|
|
181
|
-
let name = 'nativeComponent'
|
|
182
|
-
if (info.descriptionFileData) {
|
|
183
|
-
if (info.descriptionFileData.miniprogram) {
|
|
184
|
-
root = path.join(root, info.descriptionFileData.miniprogram)
|
|
185
|
-
}
|
|
186
|
-
if (info.descriptionFileData.name) {
|
|
187
|
-
// 去掉name里面的@符号,因为支付宝不支持文件路径上有@
|
|
188
|
-
name = info.descriptionFileData.name.split('@').join('')
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
const resourceName = path.join(parsed.dir, parsed.name)
|
|
192
|
-
let relativePath = path.relative(root, resourceName)
|
|
193
|
-
outputPath = path.join('components', name + pathHash(root), relativePath)
|
|
194
|
-
} else {
|
|
195
|
-
outputPath = getOutputPath(resourcePath, 'component')
|
|
196
|
-
}
|
|
197
|
-
const componentPath = toPosix(outputPath)
|
|
198
|
-
pluginEntry.publicComponents[name] = componentPath
|
|
199
|
-
// 与json-compiler处理组件的行为表现一致
|
|
200
|
-
resource = addQuery(resource, {
|
|
201
|
-
packageName: 'main'
|
|
202
|
-
})
|
|
203
|
-
if (ext === '.js') {
|
|
204
|
-
resource = '!!' + nativeLoaderPath + '!' + resource
|
|
205
|
-
}
|
|
206
|
-
currentEntry.addChild(getEntryNode(resource, 'Component'))
|
|
207
|
-
// 如果之前已经创建了入口,直接return
|
|
208
|
-
if (componentsMap[resourcePath] === componentPath) return callback()
|
|
209
|
-
componentsMap[resourcePath] = componentPath
|
|
210
|
-
addEntrySafely(resource, componentPath, callback)
|
|
211
|
-
})
|
|
212
|
-
}, callback)
|
|
213
|
-
}.bind(this, pluginEntry.publicComponents)
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
if (pluginEntry.pages) {
|
|
217
|
-
// 处理 pages
|
|
218
|
-
if (mpx.srcMode === 'ali') { // 处理ali
|
|
219
|
-
let pagesMap = pluginEntry.publicPages
|
|
220
|
-
pluginEntry.pages = pluginEntry.pages.reduce((cur, val, index) => {
|
|
221
|
-
if (!Object.values(pagesMap).includes(val)) { // no export page
|
|
222
|
-
cur[`${NO_EXPORT}${index}`] = val
|
|
223
|
-
}
|
|
224
|
-
return cur
|
|
225
|
-
}, pagesMap)
|
|
226
|
-
}
|
|
227
|
-
processPages = function (pages, callback) {
|
|
228
|
-
async.forEachOf(pages, (page, name, callback) => {
|
|
229
|
-
let aliasPath = ''
|
|
230
|
-
if (typeof page !== 'string') {
|
|
231
|
-
aliasPath = page.path
|
|
232
|
-
page = page.src
|
|
233
|
-
}
|
|
234
|
-
if (!isUrlRequest(page)) return callback()
|
|
235
|
-
if (resolveMode === 'native') {
|
|
236
|
-
page = urlToRequest(page)
|
|
237
|
-
}
|
|
238
|
-
resolve(context, page, (err, resource) => {
|
|
239
|
-
if (err) return callback(err)
|
|
240
|
-
const { resourcePath } = parseRequest(resource)
|
|
241
|
-
const ext = path.extname(resourcePath)
|
|
242
|
-
// 获取pageName
|
|
243
|
-
let pageName
|
|
244
|
-
if (aliasPath) {
|
|
245
|
-
pageName = toPosix(aliasPath)
|
|
246
|
-
// 判断 key 存在重复情况直接报错
|
|
247
|
-
for (let key in pagesMap) {
|
|
248
|
-
if (pagesMap[key] === pageName && key !== resourcePath) {
|
|
249
|
-
emitError(`Current page [${resourcePath}] registers a conflict page path [${pageName}] with existed page [${key}], which is not allowed, please rename it!`)
|
|
250
|
-
return callback()
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
} else {
|
|
254
|
-
const relative = path.relative(context, resourcePath)
|
|
255
|
-
pageName = toPosix(/^(.*?)(\.[^.]*)?$/.exec(relative)[1])
|
|
256
|
-
if (/^\./.test(pageName)) {
|
|
257
|
-
// 如果当前page不存在于context中,插件模式下报错
|
|
258
|
-
emitError(`Current page [${resourcePath}] is not in current pages directory [${context}], which is not allowed in plugin mode!`)
|
|
259
|
-
return callback()
|
|
260
|
-
}
|
|
261
|
-
// 如果当前page与已有page存在命名冲突,插件模式下报错
|
|
262
|
-
for (let key in pagesMap) {
|
|
263
|
-
if (pagesMap[key] === pageName && key !== resourcePath) {
|
|
264
|
-
emitError(`Current page [${resourcePath}] is registered with a conflict page path [${pageName}], which is already existed in system, which is not allowed in plugin mode!`)
|
|
265
|
-
return callback()
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
if (ext === '.js') {
|
|
270
|
-
resource = '!!' + nativeLoaderPath + '!' + resource
|
|
271
|
-
}
|
|
272
|
-
// 如果之前已经创建了入口,直接return
|
|
273
|
-
if (pagesMap[resourcePath]) {
|
|
274
|
-
emitWarning(`Current page [${resourcePath}] which is imported from [${this.resourcePath}] has been registered in pagesMap already, it will be ignored, please check it and remove the redundant page declaration!`)
|
|
275
|
-
return callback()
|
|
276
|
-
}
|
|
277
|
-
currentEntry.addChild(getEntryNode(resource, 'Page'))
|
|
278
|
-
pagesMap[resourcePath] = pageName
|
|
279
|
-
pluginEntry.pages[name] = pageName
|
|
280
|
-
addEntrySafely(resource, pageName, callback)
|
|
281
|
-
})
|
|
282
|
-
}, callback)
|
|
283
|
-
}.bind(this, pluginEntry.pages)
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
async.parallel([processMain, processComponents, processPages], callback)
|
|
287
|
-
}
|
package/lib/staticConfig.js
DELETED
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
const parseRequest = require('./parse-request')
|
|
2
|
-
const mpxJSON = require('./mpx-json')
|
|
3
|
-
const getMainCompilation = require('./get-main-compilation')
|
|
4
|
-
|
|
5
|
-
module.exports = function readJsonForSrc (src, loaderContext, callback) {
|
|
6
|
-
const fs = loaderContext._compiler.inputFileSystem
|
|
7
|
-
const mpx = getMainCompilation(loaderContext._compilation).__mpx__
|
|
8
|
-
const defs = mpx.defs
|
|
9
|
-
const resolve = (context, request, callback) => {
|
|
10
|
-
const { queryObj } = parseRequest(request)
|
|
11
|
-
context = queryObj.context || context
|
|
12
|
-
return loaderContext.resolve(context, request, callback)
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
resolve(loaderContext.context, src, (err, result) => {
|
|
16
|
-
if (err) return callback(err)
|
|
17
|
-
const { rawResourcePath: resourcePath } = parseRequest(result)
|
|
18
|
-
loaderContext.addDependency(resourcePath)
|
|
19
|
-
fs.readFile(resourcePath, (err, content) => {
|
|
20
|
-
if (err) {
|
|
21
|
-
return callback(err)
|
|
22
|
-
}
|
|
23
|
-
content = content.toString('utf-8')
|
|
24
|
-
if (resourcePath.endsWith('.json.js')) {
|
|
25
|
-
try {
|
|
26
|
-
content = mpxJSON.compileMPXJSONText({ source: content, defs, filePath: resourcePath })
|
|
27
|
-
} catch (e) {
|
|
28
|
-
return callback(e)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
callback(null, content)
|
|
32
|
-
})
|
|
33
|
-
})
|
|
34
|
-
}
|
package/lib/utils/try-require.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
const cwd = process.cwd()
|
|
2
|
-
const resolve = require('resolve')
|
|
3
|
-
|
|
4
|
-
module.exports = function tryRequire (dep) {
|
|
5
|
-
let fromCwd
|
|
6
|
-
try {
|
|
7
|
-
fromCwd = resolve.sync(dep, { basedir: cwd })
|
|
8
|
-
} catch (e) {}
|
|
9
|
-
if (fromCwd) {
|
|
10
|
-
return require(fromCwd)
|
|
11
|
-
} else {
|
|
12
|
-
try {
|
|
13
|
-
return require(dep)
|
|
14
|
-
} catch (e) {}
|
|
15
|
-
}
|
|
16
|
-
}
|