@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
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
const normalize = require('../utils/normalize')
|
|
3
|
+
const nativeLoaderPath = normalize.lib('native-loader')
|
|
4
|
+
const isUrlRequestRaw = require('../utils/is-url-request')
|
|
5
|
+
const parseRequest = require('../utils/parse-request')
|
|
6
|
+
const addQuery = require('../utils/add-query')
|
|
7
|
+
const loaderUtils = require('loader-utils')
|
|
8
|
+
const resolve = require('../utils/resolve')
|
|
9
|
+
|
|
10
|
+
module.exports = function createJSONHelper ({ loaderContext, emitWarning, customGetDynamicEntry }) {
|
|
11
|
+
const mpx = loaderContext.getMpx()
|
|
12
|
+
const resolveMode = mpx.resolveMode
|
|
13
|
+
const externals = mpx.externals
|
|
14
|
+
const root = mpx.projectRoot
|
|
15
|
+
const publicPath = (loaderContext._compilation && loaderContext._compilation.outputOptions.publicPath) || ''
|
|
16
|
+
const pathHash = mpx.pathHash
|
|
17
|
+
const getOutputPath = mpx.getOutputPath
|
|
18
|
+
const mode = mpx.mode
|
|
19
|
+
|
|
20
|
+
const isUrlRequest = r => isUrlRequestRaw(r, root, externals)
|
|
21
|
+
const urlToRequest = r => loaderUtils.urlToRequest(r)
|
|
22
|
+
|
|
23
|
+
const dynamicEntryMap = new Map()
|
|
24
|
+
|
|
25
|
+
let dynamicEntryCount = 0
|
|
26
|
+
|
|
27
|
+
const getDynamicEntry = (request, type, outputPath = '', packageRoot = '', relativePath = '', context = '') => {
|
|
28
|
+
if (typeof customGetDynamicEntry === 'function') return customGetDynamicEntry(request, type, outputPath, packageRoot, relativePath, context)
|
|
29
|
+
const key = `mpx_dynamic_entry_${dynamicEntryCount++}`
|
|
30
|
+
const value = `__mpx_dynamic_entry__( ${JSON.stringify(request)},${JSON.stringify(type)},${JSON.stringify(outputPath)},${JSON.stringify(packageRoot)},${JSON.stringify(relativePath)},${JSON.stringify(context)})`
|
|
31
|
+
dynamicEntryMap.set(key, value)
|
|
32
|
+
return key
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const processDynamicEntry = (output) => {
|
|
36
|
+
return output.replace(/"mpx_dynamic_entry_\d+"/g, (match) => {
|
|
37
|
+
const key = match.slice(1, -1)
|
|
38
|
+
return dynamicEntryMap.get(key)
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const processComponent = (component, context, { tarRoot = '', outputPath = '', relativePath = '' }, callback) => {
|
|
43
|
+
if (!isUrlRequest(component)) return callback(null, component)
|
|
44
|
+
if (resolveMode === 'native') {
|
|
45
|
+
component = urlToRequest(component)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
resolve(context, component, loaderContext, (err, resource, info) => {
|
|
49
|
+
if (err) return callback(err)
|
|
50
|
+
const { resourcePath, queryObj } = parseRequest(resource)
|
|
51
|
+
|
|
52
|
+
if (queryObj.root) {
|
|
53
|
+
// 删除root query
|
|
54
|
+
resource = addQuery(resource, {}, false, ['root'])
|
|
55
|
+
// 目前只有微信支持分包异步化
|
|
56
|
+
if (mode === 'wx') tarRoot = queryObj.root
|
|
57
|
+
}
|
|
58
|
+
const parsed = path.parse(resourcePath)
|
|
59
|
+
const ext = parsed.ext
|
|
60
|
+
const resourceName = path.join(parsed.dir, parsed.name)
|
|
61
|
+
|
|
62
|
+
if (!outputPath) {
|
|
63
|
+
if (ext === '.js' && resourceName.includes('node_modules') && mode !== 'web') {
|
|
64
|
+
let root = info.descriptionFileRoot
|
|
65
|
+
let name = 'nativeComponent'
|
|
66
|
+
if (info.descriptionFileData) {
|
|
67
|
+
if (info.descriptionFileData.miniprogram) {
|
|
68
|
+
root = path.join(root, info.descriptionFileData.miniprogram)
|
|
69
|
+
}
|
|
70
|
+
if (info.descriptionFileData.name) {
|
|
71
|
+
// 去掉name里面的@符号,因为支付宝不支持文件路径上有@
|
|
72
|
+
name = info.descriptionFileData.name.replace(/@/g, '')
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
let relative = path.relative(root, resourceName)
|
|
76
|
+
outputPath = path.join('components', name + pathHash(root), relative)
|
|
77
|
+
} else {
|
|
78
|
+
outputPath = getOutputPath(resourcePath, 'component')
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (ext === '.js' && mode !== 'web') {
|
|
82
|
+
resource = `!!${nativeLoaderPath}!${resource}`
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const entry = getDynamicEntry(resource, 'component', outputPath, tarRoot, relativePath)
|
|
86
|
+
callback(null, entry)
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const processPage = (page, context, tarRoot = '', callback) => {
|
|
91
|
+
let aliasPath = ''
|
|
92
|
+
if (typeof page !== 'string') {
|
|
93
|
+
aliasPath = page.path
|
|
94
|
+
page = page.src
|
|
95
|
+
}
|
|
96
|
+
if (!isUrlRequest(page)) return callback(null, page)
|
|
97
|
+
if (resolveMode === 'native') {
|
|
98
|
+
page = urlToRequest(page)
|
|
99
|
+
}
|
|
100
|
+
// 增加 page 标识
|
|
101
|
+
page = addQuery(page, { isPage: true })
|
|
102
|
+
resolve(context, page, loaderContext, (err, resource) => {
|
|
103
|
+
if (err) return callback(err)
|
|
104
|
+
const { resourcePath, queryObj: { isFirst } } = parseRequest(resource)
|
|
105
|
+
const ext = path.extname(resourcePath)
|
|
106
|
+
let outputPath
|
|
107
|
+
if (aliasPath) {
|
|
108
|
+
outputPath = aliasPath.replace(/^\//, '')
|
|
109
|
+
} else {
|
|
110
|
+
const relative = path.relative(context, resourcePath)
|
|
111
|
+
if (/^\./.test(relative)) {
|
|
112
|
+
// 如果当前page不存在于context中,对其进行重命名
|
|
113
|
+
outputPath = getOutputPath(resourcePath, 'page')
|
|
114
|
+
emitWarning(`Current page [${resourcePath}] is not in current pages directory [${context}], the page path will be replaced with [${outputPath}], use ?resolve to get the page path and navigate to it!`)
|
|
115
|
+
} else {
|
|
116
|
+
outputPath = /^(.*?)(\.[^.]*)?$/.exec(relative)[1]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (ext === '.js' && mode !== 'web') {
|
|
120
|
+
resource = `!!${nativeLoaderPath}!${resource}`
|
|
121
|
+
}
|
|
122
|
+
const entry = getDynamicEntry(resource, 'page', outputPath, tarRoot, publicPath + tarRoot)
|
|
123
|
+
const key = [resourcePath, outputPath, tarRoot].join('|')
|
|
124
|
+
callback(null, entry, {
|
|
125
|
+
isFirst,
|
|
126
|
+
key
|
|
127
|
+
})
|
|
128
|
+
})
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const processJsExport = (js, context, tarRoot = '', callback) => {
|
|
132
|
+
if (resolveMode === 'native') {
|
|
133
|
+
js = urlToRequest(js)
|
|
134
|
+
}
|
|
135
|
+
resolve(context, js, loaderContext, (err, resource) => {
|
|
136
|
+
if (err) return callback(err)
|
|
137
|
+
const { resourcePath } = parseRequest(resource)
|
|
138
|
+
const relative = path.relative(context, resourcePath)
|
|
139
|
+
if (/^\./.test(relative)) {
|
|
140
|
+
return callback(new Error(`The js export path ${resourcePath} must be in the context ${context}!`))
|
|
141
|
+
}
|
|
142
|
+
const outputPath = /^(.*?)(\.[^.]*)?$/.exec(relative)[1]
|
|
143
|
+
const entry = getDynamicEntry(resource, 'export', outputPath, tarRoot, publicPath + tarRoot)
|
|
144
|
+
callback(null, entry)
|
|
145
|
+
})
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
return {
|
|
149
|
+
processComponent,
|
|
150
|
+
processDynamicEntry,
|
|
151
|
+
processPage,
|
|
152
|
+
processJsExport,
|
|
153
|
+
isUrlRequest,
|
|
154
|
+
urlToRequest
|
|
155
|
+
}
|
|
156
|
+
}
|