@mpxjs/webpack-plugin 2.6.103 → 2.7.0-alpha.0
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 +74 -0
- package/lib/dependencies/DynamicEntryDependency.js +127 -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/RecordStaticResourceDependency.js +47 -0
- package/lib/{dependency → dependencies}/ReplaceDependency.js +19 -2
- package/lib/dependencies/ResolveDependency.js +83 -0
- package/lib/extractor.js +72 -179
- package/lib/file-loader.js +7 -19
- package/lib/helpers.js +41 -331
- package/lib/index.js +475 -365
- package/lib/json-compiler/helper.js +152 -0
- package/lib/json-compiler/index.js +148 -407
- package/lib/json-compiler/plugin.js +134 -0
- package/lib/json-compiler/{theme-loader.js → theme.js} +5 -3
- package/lib/loader.js +78 -177
- package/lib/native-loader.js +40 -70
- package/lib/record-loader.js +11 -0
- package/lib/{path-loader.js → resolve-loader.js} +0 -0
- package/lib/runtime/i18n.wxs +3 -3
- package/lib/selector.js +8 -7
- package/lib/style-compiler/index.js +14 -15
- package/lib/template-compiler/compiler.js +16 -153
- package/lib/template-compiler/index.js +46 -132
- package/lib/url-loader.js +11 -29
- package/lib/utils/add-query.js +1 -1
- package/lib/utils/const.js +5 -0
- package/lib/utils/emit-file.js +10 -0
- package/lib/utils/get-entry-name.js +13 -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/set.js +47 -0
- package/lib/utils/stringify-loaders-resource.js +25 -0
- package/lib/utils/stringify-query.js +4 -0
- package/lib/web/processScript.js +3 -3
- package/lib/web/processTemplate.js +2 -0
- 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} +0 -0
- package/lib/wxs/{wxs-loader.js → loader.js} +33 -38
- package/lib/wxs/{wxs-pre-loader.js → pre-loader.js} +0 -0
- package/lib/wxss/loader.js +31 -43
- package/lib/wxss/localsLoader.js +1 -5
- package/package.json +4 -8
- 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/utils/try-require.js +0 -16
- package/lib/wxss/getImportPrefix.js +0 -30
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const {
|
|
2
|
+
compareModulesByPreOrderIndexOrIdentifier
|
|
3
|
+
} = require('webpack/lib/util/comparators')
|
|
4
|
+
const { assignAscendingModuleIds } = require('webpack/lib/ids/IdHelpers')
|
|
5
|
+
|
|
6
|
+
/** @typedef {import("../Compiler")} Compiler */
|
|
7
|
+
/** @typedef {import("../Module")} Module */
|
|
8
|
+
|
|
9
|
+
class WxsModuleIdsPlugin {
|
|
10
|
+
apply (compilation) {
|
|
11
|
+
compilation.hooks.moduleIds.tap({
|
|
12
|
+
name: 'WxsModuleIdsPlugin',
|
|
13
|
+
// 放在最前面执行,确保生成的代码模块为数组形式,符合wxs规范
|
|
14
|
+
stage: -1000
|
|
15
|
+
}, modules => {
|
|
16
|
+
const chunkGraph = compilation.chunkGraph
|
|
17
|
+
const modulesInNaturalOrder = Array.from(modules)
|
|
18
|
+
.filter(
|
|
19
|
+
m =>
|
|
20
|
+
m.needId &&
|
|
21
|
+
chunkGraph.getNumberOfModuleChunks(m) > 0 &&
|
|
22
|
+
chunkGraph.getModuleId(m) === null
|
|
23
|
+
)
|
|
24
|
+
.sort(
|
|
25
|
+
compareModulesByPreOrderIndexOrIdentifier(compilation.moduleGraph)
|
|
26
|
+
)
|
|
27
|
+
assignAscendingModuleIds(modulesInNaturalOrder, compilation)
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = WxsModuleIdsPlugin
|
|
@@ -3,11 +3,11 @@ class WxsParserPlugin {
|
|
|
3
3
|
this.options = options
|
|
4
4
|
}
|
|
5
5
|
|
|
6
|
-
apply (parser
|
|
6
|
+
apply (parser) {
|
|
7
7
|
parser.hooks.program.tap({
|
|
8
8
|
name: 'WxsParserPlugin',
|
|
9
9
|
// 放在最后面执行
|
|
10
|
-
stage:
|
|
10
|
+
stage: 1000
|
|
11
11
|
}, ast => {
|
|
12
12
|
const module = parser.state.module
|
|
13
13
|
if (module.buildInfo) {
|
package/lib/wxs/WxsPlugin.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const WxsTemplatePlugin = require('./WxsTemplatePlugin')
|
|
2
2
|
const WxsParserPlugin = require('./WxsParserPlugin')
|
|
3
|
+
const WxsModuleIdsPlugin = require('./WxsModuleIdsPlugin')
|
|
3
4
|
|
|
4
5
|
class WxsPlugin {
|
|
5
6
|
constructor (options = { mode: 'wx' }) {
|
|
@@ -8,20 +9,15 @@ class WxsPlugin {
|
|
|
8
9
|
|
|
9
10
|
apply (compiler) {
|
|
10
11
|
compiler.hooks.thisCompilation.tap('WxsPlugin', (compilation, { normalModuleFactory }) => {
|
|
11
|
-
new WxsTemplatePlugin(this.options).apply(
|
|
12
|
-
|
|
13
|
-
compilation
|
|
14
|
-
)
|
|
12
|
+
new WxsTemplatePlugin(this.options).apply(compilation)
|
|
13
|
+
new WxsModuleIdsPlugin(this.options).apply(compilation)
|
|
15
14
|
|
|
16
15
|
compilation.hooks.buildModule.tap('WxsPlugin', (module) => {
|
|
17
16
|
module.wxs = true
|
|
18
17
|
})
|
|
19
18
|
|
|
20
19
|
const handler = (parser) => {
|
|
21
|
-
new WxsParserPlugin(this.options).apply(
|
|
22
|
-
parser,
|
|
23
|
-
compilation
|
|
24
|
-
)
|
|
20
|
+
new WxsParserPlugin(this.options).apply(parser)
|
|
25
21
|
}
|
|
26
22
|
|
|
27
23
|
normalModuleFactory.hooks.parser
|
|
@@ -1,104 +1,58 @@
|
|
|
1
|
-
const Template = require('webpack/lib/Template')
|
|
2
1
|
const config = require('../config')
|
|
3
|
-
const { ConcatSource } = require('webpack
|
|
2
|
+
const { ConcatSource } = require('webpack').sources
|
|
3
|
+
const JavascriptModulesPlugin = require('webpack/lib/javascript/JavascriptModulesPlugin')
|
|
4
4
|
|
|
5
|
-
module.exports = class
|
|
5
|
+
module.exports = class WxsTemplatePlugin {
|
|
6
6
|
constructor (options = { mode: 'wx' }) {
|
|
7
7
|
this.options = options
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
apply (
|
|
11
|
-
|
|
12
|
-
return Template.asString([
|
|
13
|
-
'// Check if module is in cache',
|
|
14
|
-
'if(installedModules[moduleId]) {',
|
|
15
|
-
Template.indent('return installedModules[moduleId].exports;'),
|
|
16
|
-
'}',
|
|
17
|
-
'// Create a new module (and put it into the cache)',
|
|
18
|
-
'var module = installedModules[moduleId] = {',
|
|
19
|
-
Template.indent(mainTemplate.hooks.moduleObj.call('', chunk, hash, 'moduleId')),
|
|
20
|
-
'};',
|
|
21
|
-
'',
|
|
22
|
-
Template.asString(
|
|
23
|
-
[
|
|
24
|
-
'// Execute the module function',
|
|
25
|
-
'// wxs连call都不支持我也是服气...',
|
|
26
|
-
`modules[moduleId](module, module.exports, ${mainTemplate.renderRequireFunctionForModule(
|
|
27
|
-
hash,
|
|
28
|
-
chunk,
|
|
29
|
-
'moduleId'
|
|
30
|
-
)});`
|
|
31
|
-
]
|
|
32
|
-
),
|
|
33
|
-
'',
|
|
34
|
-
'// Flag the module as loaded',
|
|
35
|
-
'module.l = true;',
|
|
36
|
-
'',
|
|
37
|
-
'// Return the exports of the module',
|
|
38
|
-
'return module.exports;'
|
|
39
|
-
])
|
|
40
|
-
})
|
|
41
|
-
mainTemplate.hooks.requireExtensions.tap(
|
|
42
|
-
'WxsMainTemplatePlugin',
|
|
43
|
-
() => {
|
|
44
|
-
return Template.asString([
|
|
45
|
-
'// define harmony function exports',
|
|
46
|
-
`${mainTemplate.requireFn}.d = function(exports, name, getter) {`,
|
|
47
|
-
Template.indent([
|
|
48
|
-
'exports[name] = getter();'
|
|
49
|
-
]),
|
|
50
|
-
'};',
|
|
51
|
-
'',
|
|
52
|
-
'// define __esModule on exports',
|
|
53
|
-
`${mainTemplate.requireFn}.r = function(exports) {`,
|
|
54
|
-
Template.indent([
|
|
55
|
-
'exports.__esModule = true;'
|
|
56
|
-
]),
|
|
57
|
-
'};',
|
|
58
|
-
'',
|
|
59
|
-
'// getDefaultExport function for compatibility with non-harmony modules',
|
|
60
|
-
mainTemplate.requireFn + '.n = function(module) {',
|
|
61
|
-
Template.indent([
|
|
62
|
-
'var getter = module && module.__esModule ?',
|
|
63
|
-
Template.indent([
|
|
64
|
-
'function getDefault() { return module["default"]; } :',
|
|
65
|
-
'function getModuleExports() { return module; };'
|
|
66
|
-
]),
|
|
67
|
-
`getter.a = getter();`,
|
|
68
|
-
'return getter;'
|
|
69
|
-
]),
|
|
70
|
-
'};'
|
|
71
|
-
])
|
|
72
|
-
}
|
|
73
|
-
)
|
|
74
|
-
mainTemplate.hooks.renderWithEntry.tap(
|
|
75
|
-
'WxsMainTemplatePlugin',
|
|
76
|
-
(source, chunk, hash) => {
|
|
77
|
-
const prefix = config[this.options.mode].wxs.templatePrefix
|
|
78
|
-
return new ConcatSource(prefix, source)
|
|
79
|
-
}
|
|
80
|
-
)
|
|
10
|
+
apply (compilation) {
|
|
11
|
+
const hooks = JavascriptModulesPlugin.getCompilationHooks(compilation)
|
|
81
12
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (chunk.entryModule) {
|
|
86
|
-
buf.push('// Load entry module and return exports')
|
|
87
|
-
buf.push(
|
|
88
|
-
`var entryExports = ${mainTemplate.renderRequireFunctionForModule(
|
|
89
|
-
hash,
|
|
90
|
-
chunk,
|
|
91
|
-
JSON.stringify(chunk.entryModule.id)
|
|
92
|
-
)}(${mainTemplate.requireFn}.s = ${JSON.stringify(chunk.entryModule.id)});`
|
|
93
|
-
)
|
|
94
|
-
buf.push('return entryExports && entryExports.__esModule? entryExports["default"] : entryExports;')
|
|
95
|
-
}
|
|
96
|
-
return Template.asString(buf)
|
|
13
|
+
hooks.renderStartup.tap('WxsTemplatePlugin', (source) => {
|
|
14
|
+
const postfix = 'return __webpack_exports__ && __webpack_exports__.__esModule? __webpack_exports__["default"] : __webpack_exports__;\n'
|
|
15
|
+
return new ConcatSource(source, postfix)
|
|
97
16
|
})
|
|
98
17
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
18
|
+
hooks.render.tap('WxsTemplatePlugin', (source) => {
|
|
19
|
+
const prefix = config[this.options.mode].wxs.templatePrefix
|
|
20
|
+
return new ConcatSource(prefix, source)
|
|
102
21
|
})
|
|
22
|
+
|
|
23
|
+
// todo webpack5的新的代码生成模式下完美支持.d.r.n的成本较高,暂不处理,wxs暂时只支持wx源码形式
|
|
24
|
+
// mainTemplate.hooks.requireExtensions.tap(
|
|
25
|
+
// 'WxsMainTemplatePlugin',
|
|
26
|
+
// () => {
|
|
27
|
+
// return Template.asString([
|
|
28
|
+
// '// define harmony function exports',
|
|
29
|
+
// `${mainTemplate.requireFn}.d = function(exports, name, getter) {`,
|
|
30
|
+
// Template.indent([
|
|
31
|
+
// 'exports[name] = getter();'
|
|
32
|
+
// ]),
|
|
33
|
+
// '};',
|
|
34
|
+
// '',
|
|
35
|
+
// '// define __esModule on exports',
|
|
36
|
+
// `${mainTemplate.requireFn}.r = function(exports) {`,
|
|
37
|
+
// Template.indent([
|
|
38
|
+
// 'exports.__esModule = true;'
|
|
39
|
+
// ]),
|
|
40
|
+
// '};',
|
|
41
|
+
// '',
|
|
42
|
+
// '// getDefaultExport function for compatibility with non-harmony modules',
|
|
43
|
+
// mainTemplate.requireFn + '.n = function(module) {',
|
|
44
|
+
// Template.indent([
|
|
45
|
+
// 'var getter = module && module.__esModule ?',
|
|
46
|
+
// Template.indent([
|
|
47
|
+
// 'function getDefault() { return module["default"]; } :',
|
|
48
|
+
// 'function getModuleExports() { return module; };'
|
|
49
|
+
// ]),
|
|
50
|
+
// `getter.a = getter();`,
|
|
51
|
+
// 'return getter;'
|
|
52
|
+
// ]),
|
|
53
|
+
// '};'
|
|
54
|
+
// ])
|
|
55
|
+
// }
|
|
56
|
+
// )
|
|
103
57
|
}
|
|
104
58
|
}
|
|
File without changes
|
|
@@ -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 RecordStaticResourceDependency = require('../dependencies/RecordStaticResourceDependency')
|
|
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,19 +11,19 @@ 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
17
|
const wxsMap = mpx.wxsMap
|
|
20
|
-
const
|
|
18
|
+
const appInfo = mpx.appInfo
|
|
21
19
|
let { resourcePath, queryObj } = parseRequest(this.resource)
|
|
22
|
-
const
|
|
20
|
+
const issuer = moduleGraph.getIssuer(this._module)
|
|
21
|
+
const { resourcePath: issuerResourcePath, queryObj: issuerQueryObj } = parseRequest(queryObj.issuerResource || issuer.resource)
|
|
23
22
|
const issuerPackageName = issuerQueryObj.packageRoot || mpx.currentPackageRoot || 'main'
|
|
24
23
|
const pagesMap = mpx.pagesMap
|
|
25
24
|
const componentsMap = mpx.componentsMap[issuerPackageName]
|
|
26
25
|
const staticResourcesMap = mpx.staticResourcesMap[issuerPackageName]
|
|
27
|
-
const issuerName = pagesMap[issuerResourcePath] || componentsMap[issuerResourcePath] || staticResourcesMap[issuerResourcePath]
|
|
26
|
+
const issuerName = issuerResourcePath === appInfo.resourcePath ? appInfo.name : (pagesMap[issuerResourcePath] || componentsMap[issuerResourcePath] || staticResourcesMap[issuerResourcePath])
|
|
28
27
|
const issuerDir = path.dirname(issuerName)
|
|
29
28
|
|
|
30
29
|
const getName = (raw) => {
|
|
@@ -36,18 +35,10 @@ module.exports = function () {
|
|
|
36
35
|
if (wxsModule) {
|
|
37
36
|
resourcePath = `${resourcePath}~${wxsModule}`
|
|
38
37
|
}
|
|
39
|
-
|
|
38
|
+
const packageRoot = queryObj.packageRoot || ''
|
|
40
39
|
const name = path.parse(resourcePath).name + mpx.pathHash(resourcePath)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
filename = mpx.getPackageInfo({
|
|
44
|
-
resource: this.resource,
|
|
45
|
-
outputPath: filename,
|
|
46
|
-
resourceType: 'staticResources',
|
|
47
|
-
warn: (err) => {
|
|
48
|
-
this.emitWarning(err)
|
|
49
|
-
}
|
|
50
|
-
}).outputPath
|
|
40
|
+
const filename = toPosix(path.join(packageRoot, /^\.([^.]+)/.exec(config[mode].wxs.ext)[1], `${name}${config[mode].wxs.ext}`))
|
|
41
|
+
this._module.addPresentationalDependency(new RecordStaticResourceDependency(resourcePath, filename, packageRoot))
|
|
51
42
|
|
|
52
43
|
const callback = (err) => {
|
|
53
44
|
if (err) return nativeCallback(err)
|
|
@@ -70,33 +61,31 @@ module.exports = function () {
|
|
|
70
61
|
filename
|
|
71
62
|
}
|
|
72
63
|
// wxs文件必须经过pre-loader
|
|
73
|
-
const request =
|
|
64
|
+
const request = '!!' + this.remainingRequest
|
|
74
65
|
const plugins = [
|
|
75
66
|
new WxsPlugin({ mode }),
|
|
76
67
|
new NodeTargetPlugin(),
|
|
77
|
-
new
|
|
68
|
+
new EntryPlugin(this.context, request, { name: getName(filename) }),
|
|
78
69
|
new LimitChunkCountPlugin({ maxChunks: 1 })
|
|
79
70
|
]
|
|
80
71
|
|
|
81
|
-
const childCompiler =
|
|
72
|
+
const childCompiler = this._compilation.createChildCompiler(resourcePath, outputOptions, plugins)
|
|
82
73
|
|
|
83
|
-
let entryModule
|
|
84
|
-
childCompiler.hooks.thisCompilation.tap('MpxWebpackPlugin ', (compilation) => {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
})
|
|
74
|
+
// let entryModule
|
|
75
|
+
// childCompiler.hooks.thisCompilation.tap('MpxWebpackPlugin ', (compilation) => {
|
|
76
|
+
// compilation.hooks.succeedEntry.tap('MpxWebpackPlugin', (entry, name, module) => {
|
|
77
|
+
// entryModule = module
|
|
78
|
+
// // const dep = new ChildCompileDependency(entryModule)
|
|
79
|
+
// // wxsMap[filename].dep = dep
|
|
80
|
+
// })
|
|
81
|
+
// })
|
|
91
82
|
|
|
92
|
-
childCompiler.hooks.afterCompile.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
assetInfo.modules.push(entryModule)
|
|
97
|
-
assetsInfo.set(name, assetInfo)
|
|
83
|
+
childCompiler.hooks.afterCompile.tap('MpxWebpackPlugin', (compilation) => {
|
|
84
|
+
// 持久化缓存,使用module.buildInfo.assets来输出文件
|
|
85
|
+
compilation.getAssets().forEach(({ name, source, info }) => {
|
|
86
|
+
this.emitFile(name, source.source(), undefined, info)
|
|
98
87
|
})
|
|
99
|
-
|
|
88
|
+
compilation.clearAssets()
|
|
100
89
|
})
|
|
101
90
|
|
|
102
91
|
childCompiler.runAsChild((err, entries, compilation) => {
|
|
@@ -111,6 +100,12 @@ module.exports = function () {
|
|
|
111
100
|
compilation.contextDependencies.forEach((dep) => {
|
|
112
101
|
this.addContextDependency(dep)
|
|
113
102
|
}, this)
|
|
103
|
+
compilation.missingDependencies.forEach((dep) => {
|
|
104
|
+
this.addMissingDependency(dep)
|
|
105
|
+
})
|
|
106
|
+
compilation.buildDependencies.forEach((dep) => {
|
|
107
|
+
this.addBuildDependency(dep)
|
|
108
|
+
})
|
|
114
109
|
callback()
|
|
115
110
|
})
|
|
116
111
|
}
|
|
File without changes
|
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-alpha.0",
|
|
4
4
|
"description": "mpx compile core",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"mpx"
|
|
@@ -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": "43fe072e744b33b841b8e396677711e414bcca8b"
|
|
85
81
|
}
|
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
|