@mpxjs/webpack-plugin 2.6.114-alpha.8 → 2.6.115
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/built-in-loader.js +49 -0
- package/lib/config.js +0 -14
- package/lib/content-loader.js +13 -0
- package/lib/dependency/ChildCompileDependency.js +24 -0
- package/lib/dependency/InjectDependency.js +26 -0
- package/lib/dependency/RemovedModuleDependency.js +23 -0
- package/lib/{dependencies → dependency}/ReplaceDependency.js +2 -19
- package/lib/dependency/ResolveDependency.js +49 -0
- package/lib/extractor.js +178 -82
- package/lib/file-loader.js +19 -7
- package/lib/helpers.js +334 -39
- package/lib/index.js +525 -889
- package/lib/json-compiler/index.js +451 -245
- package/lib/json-compiler/{theme.js → theme-loader.js} +3 -5
- package/lib/loader.js +241 -178
- package/lib/native-loader.js +133 -71
- package/lib/parser.js +2 -1
- package/lib/path-loader.js +3 -0
- package/lib/platform/json/wx/index.js +1 -1
- package/lib/platform/template/normalize-component-rules.js +3 -2
- package/lib/platform/template/wx/component-config/button.js +2 -14
- package/lib/platform/template/wx/component-config/image.js +0 -4
- package/lib/platform/template/wx/component-config/input.js +0 -4
- package/lib/platform/template/wx/component-config/rich-text.js +0 -4
- package/lib/platform/template/wx/component-config/scroll-view.js +0 -4
- package/lib/platform/template/wx/component-config/switch.js +0 -4
- package/lib/platform/template/wx/component-config/text.js +0 -4
- package/lib/platform/template/wx/component-config/textarea.js +0 -5
- package/lib/platform/template/wx/component-config/view.js +0 -4
- package/lib/platform/template/wx/index.js +3 -149
- package/lib/plugin-loader.js +287 -0
- package/lib/resolver/AddEnvPlugin.js +3 -4
- package/lib/resolver/AddModePlugin.js +3 -4
- package/lib/resolver/PackageEntryPlugin.js +36 -23
- package/lib/runtime/base.styl +0 -5
- package/lib/runtime/components/web/getInnerListeners.js +3 -1
- package/lib/runtime/components/web/mpx-image.vue +5 -20
- package/lib/runtime/components/web/mpx-movable-view.vue +2 -6
- package/lib/runtime/components/web/mpx-swiper.vue +3 -18
- package/lib/runtime/i18n.wxs +11 -31
- package/lib/runtime/optionProcessor.js +3 -48
- package/lib/selector.js +10 -29
- package/lib/staticConfig.js +4 -0
- package/lib/style-compiler/index.js +24 -16
- package/lib/style-compiler/load-postcss-config.js +1 -3
- package/lib/style-compiler/plugins/conditional-strip.js +65 -68
- package/lib/style-compiler/plugins/rpx.js +37 -43
- package/lib/style-compiler/plugins/scope-id.js +72 -79
- package/lib/style-compiler/plugins/trans-special.js +18 -25
- package/lib/style-compiler/plugins/trim.js +7 -13
- package/lib/style-compiler/plugins/vw.js +16 -22
- package/lib/template-compiler/compiler.js +199 -106
- package/lib/template-compiler/index.js +139 -52
- package/lib/template-compiler/trans-dynamic-class-expr.js +13 -18
- package/lib/url-loader.js +29 -11
- package/lib/utils/add-query.js +1 -1
- package/lib/utils/get-main-compilation.js +6 -0
- package/lib/utils/is-url-request.js +1 -10
- package/lib/utils/match-condition.js +1 -4
- package/lib/utils/normalize.js +15 -4
- package/lib/utils/parse-request.js +3 -3
- package/lib/utils/read-json-for-src.js +34 -0
- package/lib/utils/stringify-query.js +0 -4
- package/lib/utils/try-require.js +16 -0
- package/lib/web/processJSON.js +144 -113
- package/lib/web/processScript.js +34 -47
- package/lib/web/processTemplate.js +40 -57
- package/lib/wxml/{loader.js → wxml-loader.js} +62 -21
- package/lib/wxs/WxsParserPlugin.js +2 -2
- package/lib/wxs/WxsPlugin.js +8 -4
- package/lib/wxs/WxsTemplatePlugin.js +92 -46
- package/lib/wxs/{i18n-loader.js → wxs-i18n-loader.js} +4 -5
- package/lib/wxs/wxs-loader.js +117 -0
- package/lib/wxs/{pre-loader.js → wxs-pre-loader.js} +5 -20
- package/lib/wxss/getImportPrefix.js +30 -0
- package/lib/wxss/loader.js +43 -31
- package/lib/wxss/localsLoader.js +5 -1
- package/lib/wxss/processCss.js +103 -107
- package/package.json +18 -21
- package/LICENSE +0 -433
- package/lib/dependencies/AddEntryDependency.js +0 -24
- package/lib/dependencies/AppEntryDependency.js +0 -58
- package/lib/dependencies/CommonJsAsyncDependency.js +0 -51
- package/lib/dependencies/CommonJsVariableDependency.js +0 -81
- package/lib/dependencies/DynamicEntryDependency.js +0 -171
- package/lib/dependencies/FlagPluginDependency.js +0 -24
- package/lib/dependencies/InjectDependency.js +0 -43
- package/lib/dependencies/RecordGlobalComponentsDependency.js +0 -50
- package/lib/dependencies/RecordIndependentDependency.js +0 -44
- package/lib/dependencies/RecordResourceMapDependency.js +0 -62
- package/lib/dependencies/RemoveEntryDependency.js +0 -40
- package/lib/dependencies/ResolveDependency.js +0 -88
- package/lib/independent-loader.js +0 -52
- package/lib/json-compiler/helper.js +0 -156
- package/lib/json-compiler/plugin.js +0 -150
- package/lib/partial-compile/index.js +0 -35
- package/lib/record-loader.js +0 -11
- package/lib/resolve-loader.js +0 -6
- package/lib/resolver/FixDescriptionInfoPlugin.js +0 -28
- package/lib/runtime/components/tenon/getInnerListeners.js +0 -317
- package/lib/runtime/components/tenon/tenon-button.vue +0 -305
- package/lib/runtime/components/tenon/tenon-image.vue +0 -61
- package/lib/runtime/components/tenon/tenon-input.vue +0 -99
- package/lib/runtime/components/tenon/tenon-rich-text.vue +0 -21
- package/lib/runtime/components/tenon/tenon-scroll-view.vue +0 -124
- package/lib/runtime/components/tenon/tenon-switch.vue +0 -91
- package/lib/runtime/components/tenon/tenon-text-area.vue +0 -64
- package/lib/runtime/components/tenon/tenon-text.vue +0 -64
- package/lib/runtime/components/tenon/tenon-view.vue +0 -93
- package/lib/runtime/components/tenon/util.js +0 -44
- package/lib/runtime/optionProcessor.tenon.js +0 -386
- package/lib/style-compiler/plugins/hm.js +0 -20
- package/lib/tenon/index.js +0 -105
- package/lib/tenon/processJSON.js +0 -360
- package/lib/tenon/processScript.js +0 -260
- package/lib/tenon/processStyles.js +0 -21
- package/lib/tenon/processTemplate.js +0 -133
- package/lib/utils/const.js +0 -10
- package/lib/utils/emit-file.js +0 -10
- package/lib/utils/eval-json-js.js +0 -31
- package/lib/utils/get-entry-name.js +0 -13
- package/lib/utils/get-json-content.js +0 -42
- package/lib/utils/get-relative-path.js +0 -24
- package/lib/utils/resolve.js +0 -13
- package/lib/utils/set.js +0 -47
- package/lib/utils/stringify-loaders-resource.js +0 -25
- package/lib/wxs/WxsModuleIdsPlugin.js +0 -29
- package/lib/wxs/loader.js +0 -142
|
@@ -1,14 +1,19 @@
|
|
|
1
1
|
const compiler = require('./compiler')
|
|
2
|
+
const loaderUtils = require('loader-utils')
|
|
2
3
|
const bindThis = require('./bind-this').transform
|
|
4
|
+
const InjectDependency = require('../dependency/InjectDependency')
|
|
3
5
|
const parseRequest = require('../utils/parse-request')
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
+
const getMainCompilation = require('../utils/get-main-compilation')
|
|
7
|
+
const matchCondition = require('../utils/match-condition')
|
|
8
|
+
const path = require('path')
|
|
6
9
|
|
|
7
10
|
module.exports = function (raw) {
|
|
8
11
|
this.cacheable()
|
|
12
|
+
const options = loaderUtils.getOptions(this) || {}
|
|
9
13
|
const { resourcePath, queryObj } = parseRequest(this.resource)
|
|
10
|
-
const
|
|
11
|
-
const
|
|
14
|
+
const compilation = this._compilation
|
|
15
|
+
const mainCompilation = getMainCompilation(compilation)
|
|
16
|
+
const mpx = mainCompilation.__mpx__
|
|
12
17
|
const mode = mpx.mode
|
|
13
18
|
const env = mpx.env
|
|
14
19
|
const defs = mpx.defs
|
|
@@ -20,11 +25,6 @@ module.exports = function (raw) {
|
|
|
20
25
|
const packageName = queryObj.packageRoot || mpx.currentPackageRoot || 'main'
|
|
21
26
|
const componentsMap = mpx.componentsMap[packageName]
|
|
22
27
|
const wxsContentMap = mpx.wxsContentMap
|
|
23
|
-
const usingComponents = queryObj.usingComponents || []
|
|
24
|
-
const hasComment = queryObj.hasComment
|
|
25
|
-
const isNative = queryObj.isNative
|
|
26
|
-
const hasScoped = queryObj.hasScoped
|
|
27
|
-
const moduleId = queryObj.moduleId || 'm' + mpx.pathHash(resourcePath)
|
|
28
28
|
|
|
29
29
|
const warn = (msg) => {
|
|
30
30
|
this.emitWarning(
|
|
@@ -38,12 +38,13 @@ module.exports = function (raw) {
|
|
|
38
38
|
)
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
const
|
|
41
|
+
const parsed = compiler.parse(raw, {
|
|
42
42
|
warn,
|
|
43
43
|
error,
|
|
44
|
-
usingComponents,
|
|
45
|
-
hasComment,
|
|
46
|
-
isNative,
|
|
44
|
+
usingComponents: options.usingComponents,
|
|
45
|
+
hasComment: options.hasComment,
|
|
46
|
+
isNative: options.isNative,
|
|
47
|
+
basename: path.basename(resourcePath),
|
|
47
48
|
isComponent: !!componentsMap[resourcePath],
|
|
48
49
|
mode,
|
|
49
50
|
env,
|
|
@@ -51,56 +52,49 @@ module.exports = function (raw) {
|
|
|
51
52
|
defs,
|
|
52
53
|
decodeHTMLText,
|
|
53
54
|
externalClasses,
|
|
54
|
-
hasScoped,
|
|
55
|
-
moduleId,
|
|
56
|
-
|
|
57
|
-
filePath: resourcePath,
|
|
55
|
+
hasScoped: options.hasScoped,
|
|
56
|
+
moduleId: options.moduleId,
|
|
57
|
+
filePath: this.resourcePath,
|
|
58
58
|
i18n,
|
|
59
59
|
checkUsingComponents: mpx.checkUsingComponents,
|
|
60
60
|
globalComponents: Object.keys(mpx.usingComponents),
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
// deprecated option
|
|
62
|
+
globalMpxAttrsFilter: mpx.globalMpxAttrsFilter,
|
|
63
|
+
forceProxyEvent: matchCondition(this.resourcePath, mpx.forceProxyEventRules),
|
|
64
|
+
hasVirtualHost: matchCondition(resourcePath, mpx.autoVirtualHostRules)
|
|
64
65
|
})
|
|
65
66
|
|
|
67
|
+
let ast = parsed.root
|
|
68
|
+
let meta = parsed.meta
|
|
69
|
+
|
|
66
70
|
if (meta.wxsContentMap) {
|
|
67
71
|
for (let module in meta.wxsContentMap) {
|
|
68
72
|
wxsContentMap[`${resourcePath}~${module}`] = meta.wxsContentMap[module]
|
|
69
73
|
}
|
|
70
74
|
}
|
|
71
75
|
|
|
72
|
-
let resultSource = ''
|
|
73
|
-
|
|
74
|
-
for (let module in meta.wxsModuleMap) {
|
|
75
|
-
const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module], root)
|
|
76
|
-
resultSource += `var ${module} = require(${loaderUtils.stringifyRequest(this, src)});\n`
|
|
77
|
-
}
|
|
78
|
-
|
|
79
76
|
let result = compiler.serialize(ast)
|
|
80
77
|
|
|
81
|
-
if (isNative) {
|
|
78
|
+
if (options.isNative || mpx.forceDisableInject) {
|
|
82
79
|
return result
|
|
83
80
|
}
|
|
84
81
|
|
|
85
|
-
const rawCode = `
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
this._r();
|
|
91
|
-
}
|
|
82
|
+
const rawCode = `global.currentInject = {
|
|
83
|
+
moduleId: ${JSON.stringify(options.moduleId)},
|
|
84
|
+
render: function () {
|
|
85
|
+
${compiler.genNode(ast)}this._r();
|
|
86
|
+
}
|
|
92
87
|
};\n`
|
|
93
88
|
|
|
94
|
-
let
|
|
89
|
+
let renderResult
|
|
95
90
|
|
|
96
91
|
try {
|
|
97
|
-
|
|
92
|
+
renderResult = bindThis(rawCode, {
|
|
98
93
|
needCollect: true,
|
|
99
94
|
ignoreMap: meta.wxsModuleMap
|
|
100
95
|
})
|
|
101
96
|
} catch (e) {
|
|
102
|
-
error(`
|
|
103
|
-
Invalid render function generated by the template, please check!\n
|
|
97
|
+
error(`Invalid render function generated by the template, please check!\n
|
|
104
98
|
Template result:
|
|
105
99
|
${result}\n
|
|
106
100
|
Error code:
|
|
@@ -110,30 +104,123 @@ ${e.stack}`)
|
|
|
110
104
|
return result
|
|
111
105
|
}
|
|
112
106
|
|
|
113
|
-
|
|
107
|
+
// todo 此处在loader中往其他模块addDep更加危险,考虑修改为通过抽取后的空模块的module.exports来传递信息
|
|
108
|
+
let globalInjectCode = renderResult.code + '\n'
|
|
114
109
|
|
|
115
|
-
if ((mode === 'tt' || mode === 'swan') &&
|
|
116
|
-
|
|
110
|
+
if ((mode === 'tt' || mode === 'swan') && renderResult.propKeys) {
|
|
111
|
+
globalInjectCode += `global.currentInject.propKeys = ${JSON.stringify(renderResult.propKeys)};\n`
|
|
117
112
|
}
|
|
118
113
|
|
|
119
114
|
if (meta.computed) {
|
|
120
|
-
|
|
121
|
-
global.currentInject.injectComputed = {
|
|
115
|
+
globalInjectCode += bindThis(`global.currentInject.injectComputed = {
|
|
122
116
|
${meta.computed.join(',')}
|
|
123
|
-
};`).code + '\n'
|
|
117
|
+
};`).code + '\n'
|
|
124
118
|
}
|
|
125
119
|
|
|
126
120
|
if (meta.refs) {
|
|
127
|
-
|
|
128
|
-
global.currentInject.getRefsData = function () {
|
|
121
|
+
globalInjectCode += `global.currentInject.getRefsData = function () {
|
|
129
122
|
return ${JSON.stringify(meta.refs)};
|
|
130
|
-
};\n`
|
|
123
|
+
};\n`
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
if (meta.options) {
|
|
127
|
+
globalInjectCode += bindThis(`global.currentInject.injectOptions = ${JSON.stringify(meta.options)};`).code + '\n'
|
|
131
128
|
}
|
|
132
129
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
130
|
+
const issuer = this._module.issuer
|
|
131
|
+
const parser = issuer.parser
|
|
132
|
+
|
|
133
|
+
// 同步issuer的dependencies,确保watch中issuer rebuild时template也进行rebuild,使该loader中往issuer中注入的依赖持续有效
|
|
134
|
+
issuer.buildInfo.fileDependencies.forEach((dep) => {
|
|
135
|
+
this.addDependency(dep)
|
|
136
|
+
})
|
|
137
|
+
issuer.buildInfo.contextDependencies.forEach((dep) => {
|
|
138
|
+
this.addContextDependency(dep)
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
// 删除issuer中上次注入的dependencies,避免issuer本身不需要更新时上次的注入代码残留
|
|
142
|
+
issuer.dependencies = issuer.dependencies.filter((dep) => {
|
|
143
|
+
return !dep.templateInject
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
const dep = new InjectDependency({
|
|
147
|
+
content: globalInjectCode,
|
|
148
|
+
index: -2
|
|
136
149
|
})
|
|
137
150
|
|
|
138
|
-
|
|
151
|
+
dep.templateInject = true
|
|
152
|
+
issuer.addDependency(dep)
|
|
153
|
+
|
|
154
|
+
let isSync = true
|
|
155
|
+
|
|
156
|
+
const iterationOfArrayCallback = (arr, fn) => {
|
|
157
|
+
for (let index = 0; index < arr.length; index++) {
|
|
158
|
+
fn(arr[index])
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
const dependencies = new Map()
|
|
163
|
+
|
|
164
|
+
const addDependency = dep => {
|
|
165
|
+
const resourceIdent = dep.getResourceIdentifier()
|
|
166
|
+
if (resourceIdent) {
|
|
167
|
+
const factory = compilation.dependencyFactories.get(dep.constructor)
|
|
168
|
+
if (factory === undefined) {
|
|
169
|
+
throw new Error(`No module factory available for dependency type: ${dep.constructor.name}`)
|
|
170
|
+
}
|
|
171
|
+
let innerMap = dependencies.get(factory)
|
|
172
|
+
if (innerMap === undefined) {
|
|
173
|
+
dependencies.set(factory, (innerMap = new Map()))
|
|
174
|
+
}
|
|
175
|
+
let list = innerMap.get(resourceIdent)
|
|
176
|
+
if (list === undefined) innerMap.set(resourceIdent, (list = []))
|
|
177
|
+
list.push(dep)
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
for (let module in meta.wxsModuleMap) {
|
|
182
|
+
isSync = false
|
|
183
|
+
const src = loaderUtils.urlToRequest(meta.wxsModuleMap[module], options.root)
|
|
184
|
+
// 编译render函数只在mpx文件中运行,此处issuer的context一定等同于当前loader的context
|
|
185
|
+
const expression = `require(${loaderUtils.stringifyRequest(this, src)})`
|
|
186
|
+
const deps = []
|
|
187
|
+
parser.parse(expression, {
|
|
188
|
+
current: {
|
|
189
|
+
addDependency: dep => {
|
|
190
|
+
dep.userRequest = module
|
|
191
|
+
deps.push(dep)
|
|
192
|
+
}
|
|
193
|
+
},
|
|
194
|
+
module: issuer
|
|
195
|
+
})
|
|
196
|
+
issuer.addVariable(module, expression, deps)
|
|
197
|
+
iterationOfArrayCallback(deps, addDependency)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (isSync) {
|
|
201
|
+
return result
|
|
202
|
+
} else {
|
|
203
|
+
const callback = this.async()
|
|
204
|
+
|
|
205
|
+
const sortedDependencies = []
|
|
206
|
+
for (const pair1 of dependencies) {
|
|
207
|
+
for (const pair2 of pair1[1]) {
|
|
208
|
+
sortedDependencies.push({
|
|
209
|
+
factory: pair1[0],
|
|
210
|
+
dependencies: pair2[1]
|
|
211
|
+
})
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
compilation.addModuleDependencies(
|
|
216
|
+
issuer,
|
|
217
|
+
sortedDependencies,
|
|
218
|
+
compilation.bail,
|
|
219
|
+
null,
|
|
220
|
+
true,
|
|
221
|
+
() => {
|
|
222
|
+
callback(null, result)
|
|
223
|
+
}
|
|
224
|
+
)
|
|
225
|
+
}
|
|
139
226
|
}
|
|
@@ -1,34 +1,29 @@
|
|
|
1
1
|
const babylon = require('@babel/parser')
|
|
2
2
|
const t = require('@babel/types')
|
|
3
|
-
const traverse = require('@babel/traverse').default
|
|
4
3
|
const generate = require('@babel/generator').default
|
|
5
4
|
|
|
6
5
|
module.exports = function transDynamicClassExpr (expr, { error } = {}) {
|
|
7
6
|
try {
|
|
8
|
-
const ast = babylon.
|
|
7
|
+
const ast = babylon.parseExpression(expr, {
|
|
9
8
|
plugins: [
|
|
10
9
|
'objectRestSpread'
|
|
11
10
|
]
|
|
12
11
|
})
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
if (
|
|
19
|
-
|
|
20
|
-
error && error(`Dynamic classname [${propertyName}] is not supported, which includes [-] char and [$] char at the same time.`)
|
|
21
|
-
} else {
|
|
22
|
-
property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
|
|
23
|
-
}
|
|
12
|
+
if (t.isObjectExpression(ast)) {
|
|
13
|
+
ast.properties.forEach((property) => {
|
|
14
|
+
if (t.isObjectProperty(property) && !property.computed) {
|
|
15
|
+
const propertyName = property.key.name || property.key.value
|
|
16
|
+
if (/-/.test(propertyName)) {
|
|
17
|
+
if (/\$/.test(propertyName)) {
|
|
18
|
+
error(`Dynamic classname [${propertyName}] is not supported, which includes [-] char and [$] char at the same time.`)
|
|
24
19
|
} else {
|
|
25
|
-
property.key = t.identifier(propertyName)
|
|
20
|
+
property.key = t.identifier(propertyName.replace(/-/g, '$$') + 'MpxDash')
|
|
26
21
|
}
|
|
27
22
|
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return generate(ast
|
|
23
|
+
}
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
return generate(ast, {
|
|
32
27
|
compact: true
|
|
33
28
|
}).code
|
|
34
29
|
} catch (e) {
|
package/lib/url-loader.js
CHANGED
|
@@ -1,33 +1,51 @@
|
|
|
1
1
|
const loaderUtils = require('loader-utils')
|
|
2
2
|
const mime = require('mime')
|
|
3
|
-
const parseRequest = require('./utils/parse-request')
|
|
4
3
|
const getOptions = loaderUtils.getOptions
|
|
4
|
+
const parseQuery = loaderUtils.parseQuery
|
|
5
5
|
|
|
6
6
|
function isStyleRequest (request) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
let elements = request.replace(/^-?!+/, '').replace(/!!+/g, '!').split('!')
|
|
8
|
+
elements.pop()
|
|
9
|
+
for (let i = 0; i < elements.length; i++) {
|
|
10
|
+
let element = elements[i]
|
|
11
|
+
let queryString = '?'
|
|
12
|
+
let loaderString = element
|
|
13
|
+
let idx = element.indexOf('?')
|
|
14
|
+
if (idx >= 0) {
|
|
15
|
+
queryString = element.substr(idx)
|
|
16
|
+
loaderString = element.substr(0, idx)
|
|
17
|
+
}
|
|
18
|
+
if (/css-loader/.test(loaderString)) {
|
|
19
|
+
return true
|
|
20
|
+
}
|
|
21
|
+
if (/content-loader/.test(loaderString)) {
|
|
22
|
+
let query = parseQuery(queryString)
|
|
23
|
+
if (query.type === 'styles') {
|
|
24
|
+
return true
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
10
28
|
return false
|
|
11
29
|
}
|
|
12
30
|
|
|
13
31
|
module.exports = function (src) {
|
|
14
32
|
let transBase64 = false
|
|
15
33
|
const options = Object.assign({}, getOptions(this))
|
|
16
|
-
const
|
|
17
|
-
const mimetype = options.mimetype || mime.getType(
|
|
18
|
-
const
|
|
19
|
-
const issuer = moduleGraph.getIssuer(this._module)
|
|
34
|
+
const filePath = this.resourcePath
|
|
35
|
+
const mimetype = options.mimetype || mime.getType(filePath)
|
|
36
|
+
const issuer = this._module.issuer
|
|
20
37
|
const publicPathScope = options.publicPathScope === 'all' ? 'all' : 'styleOnly'
|
|
38
|
+
const queryOption = parseQuery(this.resourceQuery || '?')
|
|
21
39
|
const limit = options.limit
|
|
22
|
-
const useLocal = !limit || src.length < limit ||
|
|
23
|
-
const isStyle = (issuer && issuer.request && isStyleRequest(issuer.request)) ||
|
|
40
|
+
const useLocal = !limit || src.length < limit || queryOption.useLocal
|
|
41
|
+
const isStyle = (issuer && issuer.request && isStyleRequest(issuer.request)) || queryOption.isStyle
|
|
24
42
|
|
|
25
43
|
if (isStyle) {
|
|
26
44
|
if (options.publicPath) {
|
|
27
45
|
if (useLocal) {
|
|
28
46
|
transBase64 = true
|
|
29
47
|
}
|
|
30
|
-
if (
|
|
48
|
+
if (queryOption.fallback) {
|
|
31
49
|
transBase64 = false
|
|
32
50
|
}
|
|
33
51
|
} else {
|
package/lib/utils/add-query.js
CHANGED
|
@@ -3,7 +3,7 @@ const stringifyQuery = require('./stringify-query')
|
|
|
3
3
|
const type = require('./type')
|
|
4
4
|
|
|
5
5
|
// 默认为非强行覆盖原query,如需强行覆盖传递force为true
|
|
6
|
-
module.exports = function
|
|
6
|
+
module.exports = function (request, data = {}, force, removeKeys) {
|
|
7
7
|
const { rawResourcePath: resourcePath, loaderString, queryObj: queryObjRaw } = parseRequest(request)
|
|
8
8
|
const queryObj = Object.assign({}, queryObjRaw)
|
|
9
9
|
if (force) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const isUrlRequestRaw = require('loader-utils').isUrlRequest
|
|
2
2
|
const tagRE = /\{\{((?:.|\n|\r)+?)\}\}(?!})/
|
|
3
3
|
|
|
4
|
-
module.exports = function isUrlRequest (url, root
|
|
4
|
+
module.exports = function isUrlRequest (url, root) {
|
|
5
5
|
// 对于非字符串或空字符串url直接返回false
|
|
6
6
|
if (!url || typeof url !== 'string') return false
|
|
7
7
|
// 对于@开头且后续字符串为合法标识符的情况也返回false,识别为theme变量
|
|
@@ -9,14 +9,5 @@ module.exports = function isUrlRequest (url, root, externals) {
|
|
|
9
9
|
if (/^.+:\/\//.test(url)) return false
|
|
10
10
|
// 对于url中存在Mustache插值的情况也返回false
|
|
11
11
|
if (tagRE.test(url)) return false
|
|
12
|
-
// url存在于externals中也返回false
|
|
13
|
-
if (externals && externals.some((external) => {
|
|
14
|
-
if (typeof external === 'string') {
|
|
15
|
-
return external === url
|
|
16
|
-
} else if (external instanceof RegExp) {
|
|
17
|
-
return external.test(url)
|
|
18
|
-
}
|
|
19
|
-
return false
|
|
20
|
-
})) return false
|
|
21
12
|
return isUrlRequestRaw(url, root)
|
|
22
13
|
}
|
package/lib/utils/normalize.js
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const path = require('path')
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
exports.
|
|
4
|
+
exports.lib = file => path.resolve(__dirname, '../', file)
|
|
5
|
+
|
|
6
|
+
exports.dep = dep => {
|
|
7
|
+
if (
|
|
8
|
+
fs.existsSync(path.resolve(__dirname, '../../node_modules', dep))
|
|
9
|
+
) {
|
|
10
|
+
// npm 2 or npm linked
|
|
11
|
+
return '@mpxjs/webpack-plugin/node_modules/' + dep
|
|
12
|
+
} else {
|
|
13
|
+
// npm 3
|
|
14
|
+
return dep
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -4,7 +4,7 @@ const path = require('path')
|
|
|
4
4
|
|
|
5
5
|
function genQueryObj (result) {
|
|
6
6
|
// 避免外部修改queryObj影响缓存
|
|
7
|
-
result.queryObj = parseQuery(result.resourceQuery
|
|
7
|
+
result.queryObj = parseQuery(result.resourceQuery)
|
|
8
8
|
return result
|
|
9
9
|
}
|
|
10
10
|
|
|
@@ -16,13 +16,13 @@ module.exports = function parseRequest (request) {
|
|
|
16
16
|
let resource = elements.pop()
|
|
17
17
|
let loaderString = elements.join('!')
|
|
18
18
|
let resourcePath = resource
|
|
19
|
-
let resourceQuery = ''
|
|
19
|
+
let resourceQuery = '?'
|
|
20
20
|
const queryIndex = resource.indexOf('?')
|
|
21
21
|
if (queryIndex >= 0) {
|
|
22
22
|
resourcePath = resource.slice(0, queryIndex)
|
|
23
23
|
resourceQuery = resource.slice(queryIndex)
|
|
24
24
|
}
|
|
25
|
-
const queryObj = parseQuery(resourceQuery
|
|
25
|
+
const queryObj = parseQuery(resourceQuery)
|
|
26
26
|
const rawResourcePath = resourcePath
|
|
27
27
|
if (queryObj.resourcePath) {
|
|
28
28
|
resourcePath = queryObj.resourcePath
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
}
|