@mpxjs/webpack-plugin 2.6.110 → 2.7.0-beta.10
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/lib/dependencies/AppEntryDependency.js +56 -0
- package/lib/dependencies/CommonJsVariableDependency.js +69 -0
- package/lib/dependencies/DynamicEntryDependency.js +131 -0
- package/lib/dependencies/FlagPluginDependency.js +23 -0
- package/lib/dependencies/InjectDependency.js +43 -0
- package/lib/dependencies/RecordGlobalComponentsDependency.js +50 -0
- package/lib/dependencies/RecordResourceMapDependency.js +52 -0
- package/lib/dependencies/RemoveEntryDependency.js +40 -0
- package/lib/{dependency → dependencies}/ReplaceDependency.js +19 -2
- package/lib/dependencies/ResolveDependency.js +84 -0
- package/lib/extractor.js +73 -178
- package/lib/file-loader.js +7 -19
- package/lib/helpers.js +42 -330
- package/lib/index.js +497 -376
- package/lib/json-compiler/helper.js +148 -0
- package/lib/json-compiler/index.js +195 -439
- package/lib/json-compiler/plugin.js +150 -0
- package/lib/json-compiler/{theme-loader.js → theme.js} +5 -3
- package/lib/loader.js +107 -226
- package/lib/native-loader.js +65 -132
- package/lib/parser.js +1 -2
- package/lib/record-loader.js +11 -0
- package/lib/{path-loader.js → resolve-loader.js} +0 -0
- package/lib/resolver/AddEnvPlugin.js +3 -2
- package/lib/resolver/AddModePlugin.js +3 -2
- package/lib/runtime/base.styl +5 -0
- package/lib/runtime/i18n.wxs +3 -3
- package/lib/runtime/optionProcessor.js +3 -3
- package/lib/selector.js +9 -11
- package/lib/style-compiler/index.js +12 -19
- package/lib/template-compiler/compiler.js +21 -162
- package/lib/template-compiler/index.js +47 -136
- package/lib/url-loader.js +11 -29
- package/lib/utils/add-query.js +1 -1
- package/lib/utils/const.js +9 -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 +41 -0
- package/lib/utils/is-url-request.js +10 -1
- package/lib/utils/normalize.js +0 -13
- 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 -142
- package/lib/web/processScript.js +32 -26
- package/lib/web/processTemplate.js +57 -39
- package/lib/wxml/{wxml-loader.js → loader.js} +24 -60
- package/lib/wxs/WxsModuleIdsPlugin.js +32 -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} +1 -3
- package/lib/wxs/{wxs-loader.js → loader.js} +41 -50
- package/lib/wxs/{wxs-pre-loader.js → pre-loader.js} +3 -4
- package/lib/wxss/loader.js +31 -43
- package/lib/wxss/localsLoader.js +1 -5
- package/package.json +5 -9
- 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/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/wxss/getImportPrefix.js +0 -30
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
const NodeTargetPlugin = require('webpack/lib/node/NodeTargetPlugin')
|
|
2
|
-
const
|
|
2
|
+
const EntryPlugin = require('webpack/lib/EntryPlugin')
|
|
3
3
|
const LimitChunkCountPlugin = require('webpack/lib/optimize/LimitChunkCountPlugin')
|
|
4
4
|
const path = require('path')
|
|
5
5
|
const WxsPlugin = require('./WxsPlugin')
|
|
6
|
-
const
|
|
7
|
-
const getMainCompilation = require('../utils/get-main-compilation')
|
|
6
|
+
const RecordResourceMapDependency = require('../dependencies/RecordResourceMapDependency')
|
|
8
7
|
const parseRequest = require('../utils/parse-request')
|
|
9
8
|
const toPosix = require('../utils/to-posix')
|
|
10
9
|
const fixRelative = require('../utils/fix-relative')
|
|
@@ -12,20 +11,18 @@ const config = require('../config')
|
|
|
12
11
|
|
|
13
12
|
module.exports = function () {
|
|
14
13
|
const nativeCallback = this.async()
|
|
15
|
-
const
|
|
16
|
-
const mpx =
|
|
17
|
-
const assetsInfo = mpx.assetsInfo
|
|
14
|
+
const moduleGraph = this._compilation.moduleGraph
|
|
15
|
+
const mpx = this.getMpx()
|
|
18
16
|
const mode = mpx.mode
|
|
19
|
-
const wxsMap = mpx.wxsMap
|
|
20
17
|
const getOutputPath = mpx.getOutputPath
|
|
21
|
-
const rootName = mainCompilation._preparedEntrypoints[0].name
|
|
22
18
|
let { resourcePath, queryObj } = parseRequest(this.resource)
|
|
23
|
-
const
|
|
19
|
+
const issuer = moduleGraph.getIssuer(this._module)
|
|
20
|
+
const { resourcePath: issuerResourcePath, queryObj: issuerQueryObj } = parseRequest(queryObj.issuerResource || issuer.resource)
|
|
24
21
|
const issuerPackageName = issuerQueryObj.packageRoot || mpx.currentPackageRoot || 'main'
|
|
25
22
|
const pagesMap = mpx.pagesMap
|
|
26
23
|
const componentsMap = mpx.componentsMap[issuerPackageName]
|
|
27
24
|
const staticResourcesMap = mpx.staticResourcesMap[issuerPackageName]
|
|
28
|
-
const issuerName = pagesMap[issuerResourcePath] || componentsMap[issuerResourcePath] || staticResourcesMap[issuerResourcePath]
|
|
25
|
+
const issuerName = pagesMap[issuerResourcePath] || componentsMap[issuerResourcePath] || staticResourcesMap[issuerResourcePath]
|
|
29
26
|
const issuerDir = path.dirname(issuerName)
|
|
30
27
|
|
|
31
28
|
const getName = (raw) => {
|
|
@@ -39,16 +36,8 @@ module.exports = function () {
|
|
|
39
36
|
}
|
|
40
37
|
const packageRoot = queryObj.packageRoot || ''
|
|
41
38
|
const ext = config[mode].wxs.ext
|
|
42
|
-
|
|
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
|
|
39
|
+
const filename = toPosix(path.join(packageRoot, getOutputPath(resourcePath, ext.slice(1), { ext })))
|
|
40
|
+
this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'staticResource', filename, packageRoot))
|
|
52
41
|
|
|
53
42
|
const callback = (err) => {
|
|
54
43
|
if (err) return nativeCallback(err)
|
|
@@ -57,47 +46,43 @@ module.exports = function () {
|
|
|
57
46
|
nativeCallback(null, `module.exports = ${JSON.stringify(relativePath)};`)
|
|
58
47
|
}
|
|
59
48
|
|
|
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
49
|
const outputOptions = {
|
|
71
|
-
filename
|
|
50
|
+
filename,
|
|
51
|
+
// 避免输出的wxs中包含es语法
|
|
52
|
+
environment: {
|
|
53
|
+
// The environment supports arrow functions ('() => { ... }').
|
|
54
|
+
arrowFunction: false,
|
|
55
|
+
// The environment supports BigInt as literal (123n).
|
|
56
|
+
bigIntLiteral: false,
|
|
57
|
+
// The environment supports const and let for variable declarations.
|
|
58
|
+
const: false,
|
|
59
|
+
// The environment supports destructuring ('{ a, b } = obj').
|
|
60
|
+
destructuring: false,
|
|
61
|
+
// The environment supports an async import() function to import EcmaScript modules.
|
|
62
|
+
dynamicImport: false,
|
|
63
|
+
// The environment supports 'for of' iteration ('for (const x of array) { ... }').
|
|
64
|
+
forOf: false,
|
|
65
|
+
// The environment supports ECMAScript Module syntax to import ECMAScript modules (import ... from '...').
|
|
66
|
+
module: false
|
|
67
|
+
}
|
|
72
68
|
}
|
|
73
69
|
// wxs文件必须经过pre-loader
|
|
74
|
-
const request =
|
|
70
|
+
const request = '!!' + this.remainingRequest
|
|
75
71
|
const plugins = [
|
|
76
72
|
new WxsPlugin({ mode }),
|
|
77
73
|
new NodeTargetPlugin(),
|
|
78
|
-
new
|
|
74
|
+
new EntryPlugin(this.context, request, { name: getName(filename) }),
|
|
79
75
|
new LimitChunkCountPlugin({ maxChunks: 1 })
|
|
80
76
|
]
|
|
81
77
|
|
|
82
|
-
const childCompiler =
|
|
78
|
+
const childCompiler = this._compilation.createChildCompiler(resourcePath, outputOptions, plugins)
|
|
83
79
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
compilation.
|
|
87
|
-
|
|
88
|
-
const dep = new ChildCompileDependency(entryModule)
|
|
89
|
-
wxsMap[filename].dep = dep
|
|
80
|
+
childCompiler.hooks.afterCompile.tap('MpxWebpackPlugin', (compilation) => {
|
|
81
|
+
// 持久化缓存,使用module.buildInfo.assets来输出文件
|
|
82
|
+
compilation.getAssets().forEach(({ name, source, info }) => {
|
|
83
|
+
this.emitFile(name, source.source(), undefined, info)
|
|
90
84
|
})
|
|
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()
|
|
85
|
+
compilation.clearAssets()
|
|
101
86
|
})
|
|
102
87
|
|
|
103
88
|
childCompiler.runAsChild((err, entries, compilation) => {
|
|
@@ -112,6 +97,12 @@ module.exports = function () {
|
|
|
112
97
|
compilation.contextDependencies.forEach((dep) => {
|
|
113
98
|
this.addContextDependency(dep)
|
|
114
99
|
}, this)
|
|
100
|
+
compilation.missingDependencies.forEach((dep) => {
|
|
101
|
+
this.addMissingDependency(dep)
|
|
102
|
+
})
|
|
103
|
+
compilation.buildDependencies.forEach((dep) => {
|
|
104
|
+
this.addBuildDependency(dep)
|
|
105
|
+
})
|
|
115
106
|
callback()
|
|
116
107
|
})
|
|
117
108
|
}
|
|
@@ -2,21 +2,20 @@ const babylon = require('@babel/parser')
|
|
|
2
2
|
const traverse = require('@babel/traverse').default
|
|
3
3
|
const t = require('@babel/types')
|
|
4
4
|
const generate = require('@babel/generator').default
|
|
5
|
-
const getMainCompilation = require('../utils/get-main-compilation')
|
|
6
5
|
const parseRequest = require('../utils/parse-request')
|
|
7
6
|
const isEmptyObject = require('../utils/is-empty-object')
|
|
8
7
|
const parseQuery = require('loader-utils').parseQuery
|
|
9
8
|
|
|
10
9
|
module.exports = function (content) {
|
|
11
10
|
this.cacheable()
|
|
12
|
-
const
|
|
11
|
+
const mpx = this.getMpx()
|
|
13
12
|
const module = this._module
|
|
14
|
-
const mode =
|
|
13
|
+
const mode = mpx.mode
|
|
15
14
|
const wxsModule = parseQuery(this.resourceQuery || '?').wxsModule
|
|
16
15
|
|
|
17
16
|
// 处理内联wxs
|
|
18
17
|
if (wxsModule) {
|
|
19
|
-
const wxsContentMap =
|
|
18
|
+
const wxsContentMap = mpx.wxsContentMap
|
|
20
19
|
const resourcePath = parseRequest(this.resource).resourcePath
|
|
21
20
|
content = wxsContentMap[`${resourcePath}~${wxsModule}`] || content
|
|
22
21
|
}
|
package/lib/wxss/loader.js
CHANGED
|
@@ -5,25 +5,22 @@
|
|
|
5
5
|
*/
|
|
6
6
|
const loaderUtils = require('loader-utils')
|
|
7
7
|
const processCss = require('./processCss')
|
|
8
|
-
const getImportPrefix = require('./getImportPrefix')
|
|
9
8
|
const compileExports = require('./compile-exports')
|
|
10
9
|
const createResolver = require('./createResolver')
|
|
11
10
|
const isUrlRequest = require('../utils/is-url-request')
|
|
12
|
-
const
|
|
13
|
-
const addQuery = require('../utils/add-query')
|
|
11
|
+
const createHelpers = require('../helpers')
|
|
14
12
|
|
|
15
13
|
module.exports = function (content, map) {
|
|
16
14
|
if (this.cacheable) this.cacheable()
|
|
17
|
-
|
|
18
15
|
const callback = this.async()
|
|
19
16
|
const query = loaderUtils.getOptions(this) || {}
|
|
20
|
-
const root = query.root
|
|
21
17
|
const moduleMode = query.modules || query.module
|
|
22
18
|
const camelCaseKeys = query.camelCase || query.camelcase
|
|
23
|
-
const sourceMap = this.sourceMap || false
|
|
24
19
|
const resolve = createResolver(query.alias)
|
|
25
|
-
const mpx =
|
|
20
|
+
const mpx = this.getMpx()
|
|
26
21
|
const externals = mpx.externals
|
|
22
|
+
const root = mpx.projectRoot
|
|
23
|
+
const sourceMap = mpx.cssSourceMap || false
|
|
27
24
|
|
|
28
25
|
if (sourceMap) {
|
|
29
26
|
if (map) {
|
|
@@ -43,25 +40,24 @@ module.exports = function (content, map) {
|
|
|
43
40
|
map = null
|
|
44
41
|
}
|
|
45
42
|
|
|
43
|
+
const { getRequestString } = createHelpers(this)
|
|
44
|
+
|
|
46
45
|
processCss(content, map, {
|
|
47
46
|
mode: moduleMode ? 'local' : 'global',
|
|
48
47
|
from: loaderUtils.getRemainingRequest(this).split('!').pop(),
|
|
49
48
|
to: loaderUtils.getCurrentRequest(this).split('!').pop(),
|
|
50
|
-
query
|
|
51
|
-
resolve
|
|
49
|
+
query,
|
|
50
|
+
resolve,
|
|
52
51
|
minimize: this.minimize,
|
|
53
52
|
loaderContext: this,
|
|
54
|
-
sourceMap
|
|
55
|
-
},
|
|
53
|
+
sourceMap
|
|
54
|
+
}, (err, result) => {
|
|
56
55
|
if (err) return callback(err)
|
|
57
56
|
|
|
58
57
|
let cssAsString = JSON.stringify(result.source)
|
|
59
58
|
|
|
60
|
-
// for importing CSS
|
|
61
|
-
const importUrlPrefix = getImportPrefix(this)
|
|
62
|
-
|
|
63
59
|
const alreadyImported = {}
|
|
64
|
-
const importJs = result.importItems.filter(
|
|
60
|
+
const importJs = result.importItems.filter((imp) => {
|
|
65
61
|
if (!imp.mediaQuery) {
|
|
66
62
|
if (alreadyImported[imp.url]) {
|
|
67
63
|
return false
|
|
@@ -69,43 +65,35 @@ module.exports = function (content, map) {
|
|
|
69
65
|
alreadyImported[imp.url] = true
|
|
70
66
|
}
|
|
71
67
|
return true
|
|
72
|
-
}).map(
|
|
73
|
-
if (!isUrlRequest(imp.url, root
|
|
74
|
-
if (typeof external === 'string') {
|
|
75
|
-
return external === imp.url
|
|
76
|
-
} else if (external instanceof RegExp) {
|
|
77
|
-
return external.test(imp.url)
|
|
78
|
-
}
|
|
79
|
-
return false
|
|
80
|
-
})) {
|
|
68
|
+
}).map((imp) => {
|
|
69
|
+
if (!isUrlRequest(imp.url, root, externals)) {
|
|
81
70
|
return 'exports.push([module.id, ' +
|
|
82
71
|
JSON.stringify('@import url(' + imp.url + ');') + ', ' +
|
|
83
72
|
JSON.stringify(imp.mediaQuery) + ']);'
|
|
84
73
|
} else {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return 'exports.i(require(' + loaderUtils.stringifyRequest(this, importUrl) + '), ' + JSON.stringify(imp.mediaQuery) + ');'
|
|
74
|
+
const requestString = getRequestString('styles', { src: imp.url }, {
|
|
75
|
+
isStatic: true,
|
|
76
|
+
issuerFile: mpx.getExtractedFile(this.resource),
|
|
77
|
+
fromImport: true
|
|
78
|
+
})
|
|
79
|
+
return 'exports.push([module.id, ' +
|
|
80
|
+
JSON.stringify('@import "') +
|
|
81
|
+
'+ require(' + requestString + ') +' +
|
|
82
|
+
JSON.stringify('";') + ', ' +
|
|
83
|
+
JSON.stringify(imp.mediaQuery) + ']);'
|
|
96
84
|
}
|
|
97
|
-
}
|
|
85
|
+
}).join('\n')
|
|
98
86
|
|
|
99
|
-
|
|
87
|
+
const importItemMatcher = (item) => {
|
|
100
88
|
const match = result.importItemRegExp.exec(item)
|
|
101
89
|
const idx = +match[1]
|
|
102
90
|
const importItem = result.importItems[idx]
|
|
103
|
-
const importUrl =
|
|
91
|
+
const importUrl = importItem.url
|
|
104
92
|
return '" + require(' + loaderUtils.stringifyRequest(this, importUrl) + ').locals' +
|
|
105
93
|
'[' + JSON.stringify(importItem.export) + '] + "'
|
|
106
94
|
}
|
|
107
95
|
|
|
108
|
-
cssAsString = cssAsString.replace(result.importItemRegExpG, importItemMatcher
|
|
96
|
+
cssAsString = cssAsString.replace(result.importItemRegExpG, importItemMatcher)
|
|
109
97
|
|
|
110
98
|
// helper for ensuring valid CSS strings from requires
|
|
111
99
|
let urlEscapeHelper = ''
|
|
@@ -113,7 +101,7 @@ module.exports = function (content, map) {
|
|
|
113
101
|
if (query.url !== false && result.urlItems.length > 0) {
|
|
114
102
|
urlEscapeHelper = 'var escape = require(' + loaderUtils.stringifyRequest(this, '!!' + require.resolve('./url/escape.js')) + ');\n'
|
|
115
103
|
|
|
116
|
-
cssAsString = cssAsString.replace(result.urlItemRegExpG,
|
|
104
|
+
cssAsString = cssAsString.replace(result.urlItemRegExpG, (item) => {
|
|
117
105
|
const match = result.urlItemRegExp.exec(item)
|
|
118
106
|
let idx = +match[1]
|
|
119
107
|
const urlItem = result.urlItems[idx]
|
|
@@ -129,10 +117,10 @@ module.exports = function (content, map) {
|
|
|
129
117
|
}
|
|
130
118
|
urlRequest = url
|
|
131
119
|
return '" + escape(require(' + loaderUtils.stringifyRequest(this, urlRequest) + ')) + "'
|
|
132
|
-
}
|
|
120
|
+
})
|
|
133
121
|
}
|
|
134
122
|
|
|
135
|
-
let exportJs = compileExports(result, importItemMatcher
|
|
123
|
+
let exportJs = compileExports(result, importItemMatcher, camelCaseKeys)
|
|
136
124
|
if (exportJs) {
|
|
137
125
|
exportJs = 'exports.locals = ' + exportJs + ';'
|
|
138
126
|
}
|
|
@@ -165,5 +153,5 @@ module.exports = function (content, map) {
|
|
|
165
153
|
moduleJs + '\n\n' +
|
|
166
154
|
'// exports\n' +
|
|
167
155
|
exportJs)
|
|
168
|
-
}
|
|
156
|
+
})
|
|
169
157
|
}
|
package/lib/wxss/localsLoader.js
CHANGED
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
var loaderUtils = require('loader-utils')
|
|
7
7
|
var processCss = require('./processCss')
|
|
8
|
-
var getImportPrefix = require('./getImportPrefix')
|
|
9
8
|
var compileExports = require('./compile-exports')
|
|
10
9
|
var createResolver = require('./createResolver')
|
|
11
10
|
|
|
@@ -26,14 +25,11 @@ module.exports = function (content) {
|
|
|
26
25
|
}, function (err, result) {
|
|
27
26
|
if (err) return callback(err)
|
|
28
27
|
|
|
29
|
-
// for importing CSS
|
|
30
|
-
var importUrlPrefix = getImportPrefix(this, query)
|
|
31
|
-
|
|
32
28
|
function importItemMatcher (item) {
|
|
33
29
|
var match = result.importItemRegExp.exec(item)
|
|
34
30
|
var idx = +match[1]
|
|
35
31
|
var importItem = result.importItems[idx]
|
|
36
|
-
var importUrl =
|
|
32
|
+
var importUrl = importItem.url
|
|
37
33
|
return '" + require(' + loaderUtils.stringifyRequest(this, importUrl) + ')' +
|
|
38
34
|
'[' + JSON.stringify(importItem.export) + '] + "'
|
|
39
35
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mpxjs/webpack-plugin",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0-beta.10",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"html-minifier": "^3.5.8",
|
|
41
41
|
"icss-utils": "^2.1.0",
|
|
42
42
|
"json5": "^2.1.3",
|
|
43
|
-
"loader-utils": "
|
|
43
|
+
"loader-utils": "^2.0.2",
|
|
44
44
|
"lodash": "^4.17.15",
|
|
45
45
|
"lodash.camelcase": "^4.3.0",
|
|
46
46
|
"lru-cache": "^4.1.2",
|
|
@@ -54,14 +54,10 @@
|
|
|
54
54
|
"postcss-modules-values": "^1.3.0",
|
|
55
55
|
"postcss-selector-parser": "^2.0.0",
|
|
56
56
|
"postcss-value-parser": "^3.3.0",
|
|
57
|
-
"
|
|
58
|
-
"source-list-map": "^2.0.0",
|
|
59
|
-
"webpack-sources": "^1.1.0"
|
|
57
|
+
"source-list-map": "^2.0.0"
|
|
60
58
|
},
|
|
61
59
|
"peerDependencies": {
|
|
62
|
-
"
|
|
63
|
-
"webpack": "^4.0.0",
|
|
64
|
-
"webpack-cli": "^3.0.0"
|
|
60
|
+
"webpack": "^5.48.0"
|
|
65
61
|
},
|
|
66
62
|
"publishConfig": {
|
|
67
63
|
"registry": "https://registry.npmjs.org"
|
|
@@ -81,5 +77,5 @@
|
|
|
81
77
|
"@types/babel-traverse": "^6.25.4",
|
|
82
78
|
"@types/babel-types": "^7.0.4"
|
|
83
79
|
},
|
|
84
|
-
"gitHead": "
|
|
80
|
+
"gitHead": "fc256c06948aa20fca8acfdf29ec57ea453647d7"
|
|
85
81
|
}
|
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
|