@mpxjs/webpack-plugin 2.6.114-alpha.6 → 2.6.114-alpha.7

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.
Files changed (98) hide show
  1. package/lib/{dependency → dependencies}/AddEntryDependency.js +0 -0
  2. package/lib/dependencies/AppEntryDependency.js +58 -0
  3. package/lib/dependencies/CommonJsAsyncDependency.js +51 -0
  4. package/lib/dependencies/CommonJsVariableDependency.js +81 -0
  5. package/lib/dependencies/DynamicEntryDependency.js +171 -0
  6. package/lib/dependencies/FlagPluginDependency.js +24 -0
  7. package/lib/dependencies/InjectDependency.js +43 -0
  8. package/lib/dependencies/RecordGlobalComponentsDependency.js +50 -0
  9. package/lib/dependencies/RecordIndependentDependency.js +44 -0
  10. package/lib/dependencies/RecordResourceMapDependency.js +62 -0
  11. package/lib/dependencies/RemoveEntryDependency.js +40 -0
  12. package/lib/{dependency → dependencies}/ReplaceDependency.js +19 -2
  13. package/lib/dependencies/ResolveDependency.js +88 -0
  14. package/lib/extractor.js +82 -178
  15. package/lib/file-loader.js +7 -19
  16. package/lib/helpers.js +39 -334
  17. package/lib/independent-loader.js +52 -0
  18. package/lib/index.js +854 -542
  19. package/lib/json-compiler/helper.js +156 -0
  20. package/lib/json-compiler/index.js +242 -451
  21. package/lib/json-compiler/plugin.js +150 -0
  22. package/lib/json-compiler/{theme-loader.js → theme.js} +5 -3
  23. package/lib/loader.js +137 -240
  24. package/lib/native-loader.js +71 -133
  25. package/lib/parser.js +1 -2
  26. package/lib/partial-compile/index.js +35 -0
  27. package/lib/platform/json/wx/index.js +1 -1
  28. package/lib/platform/template/normalize-component-rules.js +2 -3
  29. package/lib/platform/template/wx/index.js +30 -4
  30. package/lib/record-loader.js +11 -0
  31. package/lib/{path-loader.js → resolve-loader.js} +0 -0
  32. package/lib/resolver/AddEnvPlugin.js +4 -3
  33. package/lib/resolver/AddModePlugin.js +4 -3
  34. package/lib/resolver/FixDescriptionInfoPlugin.js +28 -0
  35. package/lib/resolver/PackageEntryPlugin.js +23 -36
  36. package/lib/runtime/base.styl +5 -0
  37. package/lib/runtime/components/web/mpx-image.vue +20 -5
  38. package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
  39. package/lib/runtime/components/web/mpx-swiper.vue +18 -3
  40. package/lib/runtime/i18n.wxs +31 -11
  41. package/lib/runtime/optionProcessor.js +48 -3
  42. package/lib/selector.js +29 -10
  43. package/lib/style-compiler/index.js +15 -23
  44. package/lib/style-compiler/load-postcss-config.js +3 -1
  45. package/lib/style-compiler/plugins/conditional-strip.js +68 -65
  46. package/lib/style-compiler/plugins/rpx.js +43 -37
  47. package/lib/style-compiler/plugins/scope-id.js +79 -72
  48. package/lib/style-compiler/plugins/trans-special.js +25 -18
  49. package/lib/style-compiler/plugins/trim.js +13 -7
  50. package/lib/style-compiler/plugins/vw.js +22 -16
  51. package/lib/template-compiler/compiler.js +95 -197
  52. package/lib/template-compiler/index.js +52 -139
  53. package/lib/template-compiler/trans-dynamic-class-expr.js +18 -13
  54. package/lib/tenon/index.js +1 -3
  55. package/lib/tenon/processScript.js +52 -40
  56. package/lib/url-loader.js +11 -29
  57. package/lib/utils/add-query.js +1 -1
  58. package/lib/utils/const.js +10 -0
  59. package/lib/utils/emit-file.js +10 -0
  60. package/lib/utils/eval-json-js.js +31 -0
  61. package/lib/utils/get-entry-name.js +13 -0
  62. package/lib/utils/get-json-content.js +42 -0
  63. package/lib/utils/is-url-request.js +10 -1
  64. package/lib/utils/match-condition.js +4 -1
  65. package/lib/utils/normalize.js +4 -15
  66. package/lib/utils/parse-request.js +3 -3
  67. package/lib/utils/resolve.js +13 -0
  68. package/lib/utils/set.js +47 -0
  69. package/lib/utils/stringify-loaders-resource.js +25 -0
  70. package/lib/utils/stringify-query.js +4 -0
  71. package/lib/web/processJSON.js +113 -144
  72. package/lib/web/processScript.js +47 -34
  73. package/lib/web/processTemplate.js +57 -40
  74. package/lib/wxml/{wxml-loader.js → loader.js} +21 -62
  75. package/lib/wxs/WxsModuleIdsPlugin.js +29 -0
  76. package/lib/wxs/WxsParserPlugin.js +2 -2
  77. package/lib/wxs/WxsPlugin.js +4 -8
  78. package/lib/wxs/WxsTemplatePlugin.js +46 -92
  79. package/lib/wxs/{wxs-i18n-loader.js → i18n-loader.js} +5 -4
  80. package/lib/wxs/loader.js +142 -0
  81. package/lib/wxs/{wxs-pre-loader.js → pre-loader.js} +20 -5
  82. package/lib/wxss/loader.js +31 -43
  83. package/lib/wxss/localsLoader.js +1 -5
  84. package/lib/wxss/processCss.js +107 -103
  85. package/package.json +18 -20
  86. package/lib/built-in-loader.js +0 -49
  87. package/lib/content-loader.js +0 -13
  88. package/lib/dependency/ChildCompileDependency.js +0 -24
  89. package/lib/dependency/InjectDependency.js +0 -26
  90. package/lib/dependency/RemovedModuleDependency.js +0 -23
  91. package/lib/dependency/ResolveDependency.js +0 -53
  92. package/lib/plugin-loader.js +0 -287
  93. package/lib/staticConfig.js +0 -4
  94. package/lib/utils/get-main-compilation.js +0 -6
  95. package/lib/utils/read-json-for-src.js +0 -34
  96. package/lib/utils/try-require.js +0 -16
  97. package/lib/wxs/wxs-loader.js +0 -117
  98. package/lib/wxss/getImportPrefix.js +0 -30
@@ -0,0 +1,150 @@
1
+ const async = require('async')
2
+ const JSON5 = require('json5')
3
+ const getEntryName = require('../utils/get-entry-name')
4
+ const FlagPluginDependency = require('../dependencies/FlagPluginDependency')
5
+ const RemoveEntryDependency = require('../dependencies/RemoveEntryDependency')
6
+ const createJSONHelper = require('./helper')
7
+ const { MPX_DISABLE_EXTRACTOR_CACHE, RESOLVE_IGNORED_ERR } = require('../utils/const')
8
+
9
+ module.exports = function (source) {
10
+ // 该loader中会在每次编译中动态添加entry,不能缓存,否则watch不好使
11
+ const nativeCallback = this.async()
12
+
13
+ const mpx = this.getMpx()
14
+
15
+ if (!mpx) {
16
+ return nativeCallback(null, source)
17
+ }
18
+
19
+ // json模块必须每次都创建(但并不是每次都需要build),用于动态添加编译入口,传递信息以禁用父级extractor的缓存
20
+ this.emitFile(MPX_DISABLE_EXTRACTOR_CACHE, '', undefined, { skipEmit: true })
21
+
22
+ this._module.addPresentationalDependency(new FlagPluginDependency())
23
+
24
+ const emitWarning = (msg) => {
25
+ this.emitWarning(
26
+ new Error('[plugin loader][' + this.resource + ']: ' + msg)
27
+ )
28
+ }
29
+
30
+ const emitError = (msg) => {
31
+ this.emitError(
32
+ new Error('[plugin loader][' + this.resource + ']: ' + msg)
33
+ )
34
+ }
35
+
36
+ const {
37
+ processPage,
38
+ processDynamicEntry,
39
+ processComponent,
40
+ processJsExport
41
+ } = createJSONHelper({
42
+ loaderContext: this,
43
+ emitWarning,
44
+ emitError
45
+ })
46
+
47
+ const context = this.context
48
+ const relativePath = this._compilation.outputOptions.publicPath || ''
49
+ const mode = mpx.mode
50
+ const srcMode = mpx.srcMode
51
+ const entryName = getEntryName(this)
52
+ // 最终输出中不需要为plugin.json产生chunk,而是使用extractor输出,删除plugin.json对应的entrypoint
53
+ if (entryName) this._module.addPresentationalDependency(new RemoveEntryDependency(entryName))
54
+
55
+ // 新模式下plugin.json输出依赖于extractor
56
+ const callback = (err, processOutput) => {
57
+ if (err) return nativeCallback(err)
58
+ let output = `var pluginEntry = ${JSON.stringify(pluginEntry, null, 2)};\n`
59
+ if (processOutput) output = processOutput(output)
60
+ output += `module.exports = JSON.stringify(pluginEntry, null, 2);\n`
61
+ nativeCallback(null, output)
62
+ }
63
+
64
+ let pluginEntry
65
+ try {
66
+ pluginEntry = JSON5.parse(source)
67
+ } catch (err) {
68
+ return callback(err)
69
+ }
70
+
71
+ const processMain = (main, callback) => {
72
+ if (!main) return callback()
73
+ processJsExport(main, context, '', (err, entry) => {
74
+ if (err === RESOLVE_IGNORED_ERR) {
75
+ delete pluginEntry.main
76
+ return callback()
77
+ }
78
+ if (err) return callback(err)
79
+ pluginEntry.main = entry
80
+ callback()
81
+ })
82
+ }
83
+
84
+ const processComponents = (components, callback) => {
85
+ if (!components) return callback()
86
+ async.eachOf(components, (component, name, callback) => {
87
+ processComponent(component, context, { relativePath }, (err, entry) => {
88
+ if (err === RESOLVE_IGNORED_ERR) {
89
+ delete components[name]
90
+ return callback()
91
+ }
92
+ if (err) return callback(err)
93
+ components[name] = entry
94
+ callback()
95
+ })
96
+ }, callback)
97
+ }
98
+
99
+ const processPages = (pages, callback) => {
100
+ if (!pages) return callback()
101
+ if (srcMode === 'ali') {
102
+ const reversedMap = {}
103
+ const publicPages = pluginEntry.publicPages || {}
104
+ Object.keys(publicPages).forEach((key) => {
105
+ const item = publicPages[key]
106
+ reversedMap[item] = key
107
+ })
108
+ pages = pages.reduce((page, target, index) => {
109
+ const key = reversedMap[page] || `__private_page_${index}__`
110
+ target[key] = page
111
+ }, {})
112
+ }
113
+
114
+ if (mode === 'ali') {
115
+ pluginEntry.publicPages = {}
116
+ pluginEntry.pages = []
117
+ }
118
+
119
+ async.eachOf(pages, (page, key, callback) => {
120
+ processPage(page, context, '', (err, entry) => {
121
+ if (err === RESOLVE_IGNORED_ERR) {
122
+ delete pages[key]
123
+ return callback()
124
+ }
125
+ if (err) return callback(err)
126
+ if (mode === 'ali') {
127
+ pluginEntry.pages.push(entry)
128
+ if (!/^__private_page_\d+__$/.test(key)) {
129
+ pluginEntry.publicPages[key] = entry
130
+ }
131
+ } else {
132
+ pages[key] = entry
133
+ }
134
+ callback()
135
+ })
136
+ }, callback)
137
+ }
138
+
139
+ async.parallel([
140
+ (callback) => {
141
+ return processMain(pluginEntry.main, callback)
142
+ }, (callback) => {
143
+ return processComponents(pluginEntry.publicComponents, callback)
144
+ }, (callback) => {
145
+ return processPages(pluginEntry.pages, callback)
146
+ }
147
+ ], (err) => {
148
+ return callback(err, processDynamicEntry)
149
+ })
150
+ }
@@ -8,9 +8,11 @@ function isFile (request) {
8
8
  }
9
9
 
10
10
  module.exports = function (raw) {
11
- const options = loaderUtils.getOptions(this) || {}
12
- const isUrlRequest = r => isUrlRequestRaw(r, options.root)
13
- const urlToRequest = r => loaderUtils.urlToRequest(r, options.root)
11
+ const mpx = this.getMpx()
12
+ const root = mpx.projectRoot
13
+ const externals = mpx.externals
14
+ const isUrlRequest = r => isUrlRequestRaw(r, root, externals)
15
+ const urlToRequest = r => loaderUtils.urlToRequest(r, root)
14
16
 
15
17
  const json = JSON5.parse(raw)
16
18
  let output = `var json = ${JSON.stringify(json, null, 2)};\n`