@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
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
const templateCompiler = require('../template-compiler/compiler')
|
|
2
|
+
const genComponentTag = require('../utils/gen-component-tag')
|
|
3
|
+
const addQuery = require('../utils/add-query')
|
|
4
|
+
const path = require('path')
|
|
5
|
+
const parseRequest = require('../utils/parse-request')
|
|
6
|
+
// const getMainCompilation = require('../utils/get-main-compilation')
|
|
7
|
+
|
|
8
|
+
// function calculateRootEleChild (arr) {
|
|
9
|
+
// if (!arr) {
|
|
10
|
+
// return 0
|
|
11
|
+
// }
|
|
12
|
+
// return arr.reduce((total, item) => {
|
|
13
|
+
// if (item.type === 1) {
|
|
14
|
+
// if (item.tag === 'template') {
|
|
15
|
+
// total += calculateRootEleChild(item.children)
|
|
16
|
+
// } else {
|
|
17
|
+
// total += 1
|
|
18
|
+
// }
|
|
19
|
+
// }
|
|
20
|
+
// return total
|
|
21
|
+
// }, 0)
|
|
22
|
+
// }
|
|
23
|
+
|
|
24
|
+
module.exports = function (template, options, callback) {
|
|
25
|
+
const mode = options.mode
|
|
26
|
+
const srcMode = options.srcMode
|
|
27
|
+
const defs = options.defs
|
|
28
|
+
const moduleId = options.moduleId
|
|
29
|
+
const loaderContext = options.loaderContext
|
|
30
|
+
const ctorType = options.ctorType
|
|
31
|
+
const resourcePath = parseRequest(loaderContext.resource).resourcePath
|
|
32
|
+
const builtInComponentsMap = {}
|
|
33
|
+
// const compilation = loaderContext._compilation
|
|
34
|
+
// const mainCompilation = getMainCompilation(compilation)
|
|
35
|
+
// const mpx = mainCompilation.__mpx__
|
|
36
|
+
// const wxsContentMap = mpx.wxsContentMap
|
|
37
|
+
let wxsModuleMap, genericsInfo
|
|
38
|
+
let output = '/* template */\n'
|
|
39
|
+
|
|
40
|
+
if (ctorType === 'app') {
|
|
41
|
+
template = {
|
|
42
|
+
tag: 'template',
|
|
43
|
+
content: '<div class="app">this is app</div>'
|
|
44
|
+
}
|
|
45
|
+
// builtInComponentsMap['mpx-keep-alive'] = {
|
|
46
|
+
// resource: addQuery('@mpxjs/webpack-plugin/lib/runtime/components/web/mpx-keep-alive.vue', { component: true })
|
|
47
|
+
// }
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (template) {
|
|
51
|
+
// 由于远端src template资源引用的相对路径可能发生变化,暂时不支持。
|
|
52
|
+
if (template.src) {
|
|
53
|
+
return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template content must be inline in .mpx files!'))
|
|
54
|
+
}
|
|
55
|
+
if (template.lang) {
|
|
56
|
+
return callback(new Error('[mpx loader][' + loaderContext.resource + ']: ' + 'template lang is not supported in trans web mode temporarily, we will support it in the future!'))
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
output += genComponentTag(template, (template) => {
|
|
60
|
+
if (ctorType === 'app') {
|
|
61
|
+
return template.content
|
|
62
|
+
}
|
|
63
|
+
if (template.content) {
|
|
64
|
+
const templateSrcMode = template.mode || srcMode
|
|
65
|
+
const parsed = templateCompiler.parse(template.content, {
|
|
66
|
+
warn: (msg) => {
|
|
67
|
+
loaderContext.emitWarning(
|
|
68
|
+
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
69
|
+
)
|
|
70
|
+
},
|
|
71
|
+
error: (msg) => {
|
|
72
|
+
loaderContext.emitError(
|
|
73
|
+
new Error('[template compiler][' + loaderContext.resource + ']: ' + msg)
|
|
74
|
+
)
|
|
75
|
+
},
|
|
76
|
+
usingComponents: options.usingComponents,
|
|
77
|
+
hasComment: options.hasComment,
|
|
78
|
+
isNative: options.isNative,
|
|
79
|
+
basename: path.basename(resourcePath),
|
|
80
|
+
isComponent: ctorType === 'component',
|
|
81
|
+
mode,
|
|
82
|
+
srcMode: templateSrcMode,
|
|
83
|
+
defs,
|
|
84
|
+
decodeHTMLText: options.decodeHTMLText,
|
|
85
|
+
// externalClasses: options.externalClasses,
|
|
86
|
+
hasScoped: false,
|
|
87
|
+
moduleId,
|
|
88
|
+
filePath: loaderContext.resourcePath,
|
|
89
|
+
i18n: null,
|
|
90
|
+
checkUsingComponents: options.checkUsingComponents,
|
|
91
|
+
// web模式下全局组件不会被合入usingComponents中,故globalComponents可以传空
|
|
92
|
+
globalComponents: [],
|
|
93
|
+
// web模式下实现抽象组件
|
|
94
|
+
componentGenerics: options.componentGenerics
|
|
95
|
+
})
|
|
96
|
+
// if (parsed.meta.wxsModuleMap) {
|
|
97
|
+
// wxsModuleMap = parsed.meta.wxsModuleMap
|
|
98
|
+
// }
|
|
99
|
+
// if (parsed.meta.wxsContentMap) {
|
|
100
|
+
// for (let module in parsed.meta.wxsContentMap) {
|
|
101
|
+
// wxsContentMap[`${resourcePath}~${module}`] = parsed.meta.wxsContentMap[module]
|
|
102
|
+
// }
|
|
103
|
+
// }
|
|
104
|
+
if (parsed.meta.builtInComponentsMap) {
|
|
105
|
+
Object.keys(parsed.meta.builtInComponentsMap).forEach((name) => {
|
|
106
|
+
builtInComponentsMap[name] = {
|
|
107
|
+
resource: addQuery(parsed.meta.builtInComponentsMap[name], { component: true })
|
|
108
|
+
}
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
// if (parsed.meta.genericsInfo) {
|
|
112
|
+
// genericsInfo = parsed.meta.genericsInfo
|
|
113
|
+
// }
|
|
114
|
+
// 输出H5有多个root element时, 使用div标签包裹
|
|
115
|
+
// if (parsed.root.tag === 'temp-node') {
|
|
116
|
+
// const childLen = calculateRootEleChild(parsed.root.children)
|
|
117
|
+
// if (childLen >= 2) {
|
|
118
|
+
// parsed.root.tag = 'div'
|
|
119
|
+
// }
|
|
120
|
+
// }
|
|
121
|
+
return templateCompiler.serialize(parsed.root)
|
|
122
|
+
}
|
|
123
|
+
})
|
|
124
|
+
output += '\n\n'
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
callback(null, {
|
|
128
|
+
output,
|
|
129
|
+
builtInComponentsMap,
|
|
130
|
+
genericsInfo,
|
|
131
|
+
wxsModuleMap
|
|
132
|
+
})
|
|
133
|
+
}
|
package/lib/utils/const.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
module.exports = {
|
|
2
2
|
MPX_PROCESSED_FLAG: 'mpx_processed',
|
|
3
3
|
MPX_DISABLE_EXTRACTOR_CACHE: 'mpx_disable_extractor_cache',
|
|
4
|
-
DEFAULT_RESULT_SOURCE: ''
|
|
4
|
+
DEFAULT_RESULT_SOURCE: '',
|
|
5
|
+
RESOLVE_IGNORED_ERR: new Error('Resolve ignored!'),
|
|
6
|
+
JSON_JS_EXT: '.json.js',
|
|
7
|
+
MPX_ROOT_VIEW: 'mpx-root-view', // 根节点类名
|
|
8
|
+
MPX_APP_MODULE_ID: 'mpx-app-scope', // app文件moduleId
|
|
9
|
+
MPX_CURRENT_CHUNK: 'mpx_current_chunk'
|
|
5
10
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const path = require('path')
|
|
2
|
+
|
|
3
|
+
module.exports = function evalJSONJS (source, filename, loaderContext) {
|
|
4
|
+
if (!loaderContext._compiler) return {}
|
|
5
|
+
const fs = loaderContext._compiler.inputFileSystem
|
|
6
|
+
const defs = loaderContext.getMpx().defs
|
|
7
|
+
const defKeys = Object.keys(defs)
|
|
8
|
+
const defValues = defKeys.map((key) => {
|
|
9
|
+
return defs[key]
|
|
10
|
+
})
|
|
11
|
+
const dirname = path.dirname(filename)
|
|
12
|
+
// eslint-disable-next-line no-new-func
|
|
13
|
+
const func = new Function('module', 'exports', 'require', '__filename', '__dirname', ...defKeys, source)
|
|
14
|
+
const module = {
|
|
15
|
+
exports: {}
|
|
16
|
+
}
|
|
17
|
+
// 此处采用readFileSync+evalJSONJS而不直接使用require获取依赖内容有两个原因:
|
|
18
|
+
// 1. 支持依赖中正常访问defs变量
|
|
19
|
+
// 2. 避免对应的依赖文件被作为buildDependencies
|
|
20
|
+
func(module, module.exports, function (request) {
|
|
21
|
+
if (request.startsWith('.')) {
|
|
22
|
+
request = path.join(dirname, request)
|
|
23
|
+
}
|
|
24
|
+
const filename = require.resolve(request)
|
|
25
|
+
loaderContext.addDependency(filename)
|
|
26
|
+
const source = fs.readFileSync(filename).toString('utf-8')
|
|
27
|
+
return evalJSONJS(source, filename, loaderContext)
|
|
28
|
+
}, filename, dirname, ...defValues)
|
|
29
|
+
|
|
30
|
+
return module.exports
|
|
31
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
module.exports = function (loaderContext) {
|
|
2
|
-
|
|
3
|
-
const moduleGraph =
|
|
2
|
+
if (!loaderContext._compilation) return ''
|
|
3
|
+
const moduleGraph = loaderContext._compilation.moduleGraph
|
|
4
4
|
let entryName = ''
|
|
5
|
-
for (const [name, { dependencies }] of
|
|
5
|
+
for (const [name, { dependencies }] of loaderContext._compilation.entries) {
|
|
6
6
|
const entryModule = moduleGraph.getModule(dependencies[0])
|
|
7
7
|
if (entryModule.resource === loaderContext.resource) {
|
|
8
8
|
entryName = name
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const parseRequest = require('./parse-request')
|
|
2
|
+
const evalJSONJS = require('./eval-json-js')
|
|
3
|
+
const resolve = require('./resolve')
|
|
4
|
+
const async = require('async')
|
|
5
|
+
const { JSON_JS_EXT } = require('./const')
|
|
6
|
+
|
|
7
|
+
module.exports = function getJSONContent (json, loaderContext, callback) {
|
|
8
|
+
if (!loaderContext._compiler) return callback(null, '{}')
|
|
9
|
+
const fs = loaderContext._compiler.inputFileSystem
|
|
10
|
+
async.waterfall([
|
|
11
|
+
(callback) => {
|
|
12
|
+
if (json.src) {
|
|
13
|
+
resolve(loaderContext.context, json.src, loaderContext, (err, result) => {
|
|
14
|
+
if (err) return callback(err)
|
|
15
|
+
const { rawResourcePath: resourcePath } = parseRequest(result)
|
|
16
|
+
fs.readFile(resourcePath, (err, content) => {
|
|
17
|
+
if (err) return callback(err)
|
|
18
|
+
callback(null, {
|
|
19
|
+
content: content.toString('utf-8'),
|
|
20
|
+
useJSONJS: json.useJSONJS || resourcePath.endsWith(JSON_JS_EXT),
|
|
21
|
+
filename: resourcePath
|
|
22
|
+
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
})
|
|
26
|
+
} else {
|
|
27
|
+
callback(null, {
|
|
28
|
+
content: json.content,
|
|
29
|
+
useJSONJS: json.useJSONJS,
|
|
30
|
+
filename: loaderContext.resourcePath
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
({ content, useJSONJS, filename }, callback) => {
|
|
35
|
+
if (!content) return callback(null, '{}')
|
|
36
|
+
if (useJSONJS) {
|
|
37
|
+
content = JSON.stringify(evalJSONJS(content, filename, loaderContext))
|
|
38
|
+
}
|
|
39
|
+
callback(null, content)
|
|
40
|
+
}
|
|
41
|
+
], callback)
|
|
42
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
function getRelativePath (source, target) {
|
|
2
|
+
// make sure source and target are absolute path
|
|
3
|
+
/^\//.test(source) || (source = '/' + source);
|
|
4
|
+
/^\//.test(target) || (target = '/' + target)
|
|
5
|
+
|
|
6
|
+
source = source && source.replace(/\/[^/]*$/, '') // get dirname
|
|
7
|
+
// check if source or target is root path
|
|
8
|
+
let sourceArr = source.split('/').filter((item, index) => index !== 0 && !!item)
|
|
9
|
+
let targetArr = target.split('/').filter((item, index) => index !== 0 && !!item)
|
|
10
|
+
let i = 0
|
|
11
|
+
while (sourceArr[i] === targetArr[i] && i < sourceArr.length && i < targetArr.length) {
|
|
12
|
+
i++
|
|
13
|
+
}
|
|
14
|
+
let relativePath = ''
|
|
15
|
+
for (let j = 0; j < sourceArr.length - i; j++) {
|
|
16
|
+
relativePath += '../'
|
|
17
|
+
}
|
|
18
|
+
relativePath += targetArr.slice(i).join('/')
|
|
19
|
+
if (relativePath[0] !== '.') relativePath = './' + relativePath
|
|
20
|
+
return relativePath
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = {
|
|
24
|
+
getRelativePath
|
|
25
|
+
}
|
package/lib/utils/normalize.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
const path = require('path')
|
|
1
|
+
// const path = require('path')
|
|
2
2
|
|
|
3
|
-
exports.lib = file => path.resolve(__dirname, '../', file)
|
|
3
|
+
// exports.lib = file => path.resolve(__dirname, '../', file)
|
|
4
|
+
// support npm link debug
|
|
5
|
+
exports.lib = file => '@mpxjs/webpack-plugin/lib/' + file
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const parseRequest = require('./parse-request')
|
|
2
|
+
const { RESOLVE_IGNORED_ERR } = require('./const')
|
|
3
|
+
|
|
4
|
+
// todo 提供不记录dependency的resolve方法,非必要的情况下不记录dependency,提升缓存利用率
|
|
5
|
+
module.exports = (context, request, loaderContext, callback) => {
|
|
6
|
+
const { queryObj } = parseRequest(request)
|
|
7
|
+
context = queryObj.context || context
|
|
8
|
+
return loaderContext.resolve(context, request, (err, resource, info) => {
|
|
9
|
+
if (err) return callback(err)
|
|
10
|
+
if (resource === false) return callback(RESOLVE_IGNORED_ERR)
|
|
11
|
+
callback(null, resource, info)
|
|
12
|
+
})
|
|
13
|
+
}
|