@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/lib/wxs/wxs-loader.js
DELETED
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
const NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin')
|
|
2
|
-
const SingleEntryPlugin = require('webpack/lib/SingleEntryPlugin')
|
|
3
|
-
const LimitChunkCountPlugin = require('webpack/lib/optimize/LimitChunkCountPlugin')
|
|
4
|
-
const path = require('path')
|
|
5
|
-
const WxsPlugin = require('./WxsPlugin')
|
|
6
|
-
const ChildCompileDependency = require('../dependency/ChildCompileDependency')
|
|
7
|
-
const getMainCompilation = require('../utils/get-main-compilation')
|
|
8
|
-
const parseRequest = require('../utils/parse-request')
|
|
9
|
-
const toPosix = require('../utils/to-posix')
|
|
10
|
-
const fixRelative = require('../utils/fix-relative')
|
|
11
|
-
const config = require('../config')
|
|
12
|
-
|
|
13
|
-
module.exports = function () {
|
|
14
|
-
const nativeCallback = this.async()
|
|
15
|
-
const mainCompilation = getMainCompilation(this._compilation)
|
|
16
|
-
const mpx = mainCompilation.__mpx__
|
|
17
|
-
const assetsInfo = mpx.assetsInfo
|
|
18
|
-
const mode = mpx.mode
|
|
19
|
-
const wxsMap = mpx.wxsMap
|
|
20
|
-
const getOutputPath = mpx.getOutputPath
|
|
21
|
-
const rootName = mainCompilation._preparedEntrypoints[0].name
|
|
22
|
-
let { resourcePath, queryObj } = parseRequest(this.resource)
|
|
23
|
-
const { resourcePath: issuerResourcePath, queryObj: issuerQueryObj } = parseRequest(queryObj.issuerResource || this._module.issuer.resource)
|
|
24
|
-
const issuerPackageName = issuerQueryObj.packageRoot || mpx.currentPackageRoot || 'main'
|
|
25
|
-
const pagesMap = mpx.pagesMap
|
|
26
|
-
const componentsMap = mpx.componentsMap[issuerPackageName]
|
|
27
|
-
const staticResourcesMap = mpx.staticResourcesMap[issuerPackageName]
|
|
28
|
-
const issuerName = pagesMap[issuerResourcePath] || componentsMap[issuerResourcePath] || staticResourcesMap[issuerResourcePath] || rootName
|
|
29
|
-
const issuerDir = path.dirname(issuerName)
|
|
30
|
-
|
|
31
|
-
const getName = (raw) => {
|
|
32
|
-
const match = /^(.*?)(\.[^.]*)?$/.exec(raw)
|
|
33
|
-
return match[1]
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const wxsModule = queryObj.wxsModule
|
|
37
|
-
if (wxsModule) {
|
|
38
|
-
resourcePath = `${resourcePath}~${wxsModule}`
|
|
39
|
-
}
|
|
40
|
-
const packageRoot = queryObj.packageRoot || ''
|
|
41
|
-
const ext = config[mode].wxs.ext
|
|
42
|
-
let filename = toPosix(path.join(packageRoot, getOutputPath(resourcePath, ext.slice(1), { ext })))
|
|
43
|
-
|
|
44
|
-
filename = mpx.getPackageInfo({
|
|
45
|
-
resource: this.resource,
|
|
46
|
-
outputPath: filename,
|
|
47
|
-
resourceType: 'staticResources',
|
|
48
|
-
warn: (err) => {
|
|
49
|
-
this.emitWarning(err)
|
|
50
|
-
}
|
|
51
|
-
}).outputPath
|
|
52
|
-
|
|
53
|
-
const callback = (err) => {
|
|
54
|
-
if (err) return nativeCallback(err)
|
|
55
|
-
let relativePath = toPosix(path.relative(issuerDir, filename))
|
|
56
|
-
relativePath = fixRelative(relativePath, mode)
|
|
57
|
-
nativeCallback(null, `module.exports = ${JSON.stringify(relativePath)};`)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
if (wxsMap[filename]) {
|
|
61
|
-
wxsMap[filename].modules.push(this._module)
|
|
62
|
-
return callback()
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
wxsMap[filename] = {
|
|
66
|
-
dep: null,
|
|
67
|
-
modules: [this._module]
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
const outputOptions = {
|
|
71
|
-
filename
|
|
72
|
-
}
|
|
73
|
-
// wxs文件必须经过pre-loader
|
|
74
|
-
const request = `!${this.remainingRequest}`
|
|
75
|
-
const plugins = [
|
|
76
|
-
new WxsPlugin({ mode }),
|
|
77
|
-
new NodeTargetPlugin(),
|
|
78
|
-
new SingleEntryPlugin(this.context, request, getName(filename)),
|
|
79
|
-
new LimitChunkCountPlugin({ maxChunks: 1 })
|
|
80
|
-
]
|
|
81
|
-
|
|
82
|
-
const childCompiler = mainCompilation.createChildCompiler(request, outputOptions, plugins)
|
|
83
|
-
|
|
84
|
-
let entryModule
|
|
85
|
-
childCompiler.hooks.thisCompilation.tap('MpxWebpackPlugin ', (compilation) => {
|
|
86
|
-
compilation.hooks.succeedEntry.tap('MpxWebpackPlugin', (entry, name, module) => {
|
|
87
|
-
entryModule = module
|
|
88
|
-
const dep = new ChildCompileDependency(entryModule)
|
|
89
|
-
wxsMap[filename].dep = dep
|
|
90
|
-
})
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
childCompiler.hooks.afterCompile.tapAsync('MpxWebpackPlugin', (compilation, callback) => {
|
|
94
|
-
Object.keys(compilation.assets).forEach((name) => {
|
|
95
|
-
// 因为子编译会合并assetsInfo会互相覆盖,使用全局mpx对象收集完之后再合并到主assetsInfo中
|
|
96
|
-
const assetInfo = assetsInfo.get(name) || { modules: [] }
|
|
97
|
-
assetInfo.modules.push(entryModule)
|
|
98
|
-
assetsInfo.set(name, assetInfo)
|
|
99
|
-
})
|
|
100
|
-
callback()
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
childCompiler.runAsChild((err, entries, compilation) => {
|
|
104
|
-
if (err) return callback(err)
|
|
105
|
-
if (compilation.errors.length > 0) {
|
|
106
|
-
return callback(compilation.errors[0])
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
compilation.fileDependencies.forEach((dep) => {
|
|
110
|
-
this.addDependency(dep)
|
|
111
|
-
}, this)
|
|
112
|
-
compilation.contextDependencies.forEach((dep) => {
|
|
113
|
-
this.addContextDependency(dep)
|
|
114
|
-
}, this)
|
|
115
|
-
callback()
|
|
116
|
-
})
|
|
117
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
3
|
-
Author Tobias Koppers @sokra
|
|
4
|
-
Modified by @hiyuki
|
|
5
|
-
*/
|
|
6
|
-
const normalize = require('../utils/normalize')
|
|
7
|
-
const extractorPath = normalize.lib('extractor')
|
|
8
|
-
const toPosix = require('../utils/to-posix')
|
|
9
|
-
|
|
10
|
-
module.exports = function getImportPrefix (loaderContext, extract) {
|
|
11
|
-
const selectorIndex = loaderContext.loaders.findIndex(({ path }) => {
|
|
12
|
-
// 兼容windows路径
|
|
13
|
-
return toPosix(path).indexOf('@mpxjs/webpack-plugin/lib/selector') !== -1
|
|
14
|
-
})
|
|
15
|
-
let loadersRequest = loaderContext.loaders.slice(
|
|
16
|
-
loaderContext.loaderIndex,
|
|
17
|
-
selectorIndex !== -1 ? selectorIndex : undefined
|
|
18
|
-
).map(function (x) {
|
|
19
|
-
return x.request
|
|
20
|
-
}).join('!')
|
|
21
|
-
if (extract) {
|
|
22
|
-
loadersRequest = extractorPath + '?' +
|
|
23
|
-
JSON.stringify({
|
|
24
|
-
type: 'styles',
|
|
25
|
-
index: -1,
|
|
26
|
-
fromImport: true
|
|
27
|
-
}) + '!' + loadersRequest
|
|
28
|
-
}
|
|
29
|
-
return '-!' + loadersRequest + '!'
|
|
30
|
-
}
|