@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.
Files changed (108) hide show
  1. package/README.md +1 -1
  2. package/lib/config.js +14 -0
  3. package/lib/dependencies/AddEntryDependency.js +24 -0
  4. package/lib/dependencies/AppEntryDependency.js +2 -0
  5. package/lib/dependencies/CommonJsAsyncDependency.js +51 -0
  6. package/lib/dependencies/CommonJsVariableDependency.js +13 -6
  7. package/lib/dependencies/DynamicEntryDependency.js +85 -41
  8. package/lib/dependencies/FlagPluginDependency.js +1 -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/dependencies/ResolveDependency.js +11 -6
  13. package/lib/extractor.js +17 -7
  14. package/lib/file-loader.js +2 -2
  15. package/lib/helpers.js +6 -12
  16. package/lib/independent-loader.js +52 -0
  17. package/lib/index.js +595 -304
  18. package/lib/json-compiler/helper.js +36 -32
  19. package/lib/json-compiler/index.js +119 -66
  20. package/lib/json-compiler/plugin.js +23 -7
  21. package/lib/loader.js +135 -90
  22. package/lib/native-loader.js +37 -69
  23. package/lib/parser.js +1 -2
  24. package/lib/partial-compile/index.js +35 -0
  25. package/lib/platform/json/wx/index.js +8 -3
  26. package/lib/platform/template/normalize-component-rules.js +2 -3
  27. package/lib/platform/template/wx/component-config/button.js +17 -5
  28. package/lib/platform/template/wx/component-config/image.js +4 -0
  29. package/lib/platform/template/wx/component-config/input.js +4 -0
  30. package/lib/platform/template/wx/component-config/navigator.js +1 -1
  31. package/lib/platform/template/wx/component-config/rich-text.js +4 -0
  32. package/lib/platform/template/wx/component-config/scroll-view.js +4 -0
  33. package/lib/platform/template/wx/component-config/switch.js +4 -0
  34. package/lib/platform/template/wx/component-config/text.js +4 -0
  35. package/lib/platform/template/wx/component-config/textarea.js +5 -0
  36. package/lib/platform/template/wx/component-config/view.js +4 -0
  37. package/lib/platform/template/wx/index.js +149 -3
  38. package/lib/record-loader.js +2 -2
  39. package/lib/resolve-loader.js +4 -1
  40. package/lib/resolver/AddEnvPlugin.js +4 -3
  41. package/lib/resolver/AddModePlugin.js +4 -3
  42. package/lib/resolver/FixDescriptionInfoPlugin.js +28 -0
  43. package/lib/resolver/PackageEntryPlugin.js +23 -36
  44. package/lib/runtime/base.styl +5 -0
  45. package/lib/runtime/components/tenon/getInnerListeners.js +317 -0
  46. package/lib/runtime/components/tenon/tenon-button.vue +305 -0
  47. package/lib/runtime/components/tenon/tenon-image.vue +61 -0
  48. package/lib/runtime/components/tenon/tenon-input.vue +99 -0
  49. package/lib/runtime/components/tenon/tenon-rich-text.vue +21 -0
  50. package/lib/runtime/components/tenon/tenon-scroll-view.vue +124 -0
  51. package/lib/runtime/components/tenon/tenon-switch.vue +91 -0
  52. package/lib/runtime/components/tenon/tenon-text-area.vue +64 -0
  53. package/lib/runtime/components/tenon/tenon-text.vue +64 -0
  54. package/lib/runtime/components/tenon/tenon-view.vue +93 -0
  55. package/lib/runtime/components/tenon/util.js +44 -0
  56. package/lib/runtime/components/web/getInnerListeners.js +51 -45
  57. package/lib/runtime/components/web/mpx-image.vue +20 -5
  58. package/lib/runtime/components/web/mpx-keep-alive.vue +4 -1
  59. package/lib/runtime/components/web/mpx-movable-view.vue +6 -2
  60. package/lib/runtime/components/web/mpx-swiper.vue +37 -8
  61. package/lib/runtime/components/web/mpx-tab-bar-container.vue +2 -2
  62. package/lib/runtime/components/web/mpx-textarea.vue +1 -1
  63. package/lib/runtime/i18n.wxs +28 -8
  64. package/lib/runtime/optionProcessor.js +50 -20
  65. package/lib/runtime/optionProcessor.tenon.js +386 -0
  66. package/lib/runtime/stringify.wxs +6 -4
  67. package/lib/selector.js +23 -5
  68. package/lib/style-compiler/index.js +12 -13
  69. package/lib/style-compiler/load-postcss-config.js +3 -1
  70. package/lib/style-compiler/plugins/conditional-strip.js +68 -65
  71. package/lib/style-compiler/plugins/hm.js +20 -0
  72. package/lib/style-compiler/plugins/rpx.js +43 -37
  73. package/lib/style-compiler/plugins/scope-id.js +79 -72
  74. package/lib/style-compiler/plugins/trans-special.js +25 -18
  75. package/lib/style-compiler/plugins/trim.js +13 -7
  76. package/lib/style-compiler/plugins/vw.js +19 -12
  77. package/lib/template-compiler/bind-this.js +4 -4
  78. package/lib/template-compiler/compiler.js +172 -62
  79. package/lib/template-compiler/index.js +8 -9
  80. package/lib/template-compiler/trans-dynamic-class-expr.js +32 -22
  81. package/lib/tenon/index.js +105 -0
  82. package/lib/tenon/processJSON.js +356 -0
  83. package/lib/tenon/processScript.js +261 -0
  84. package/lib/tenon/processStyles.js +21 -0
  85. package/lib/tenon/processTemplate.js +133 -0
  86. package/lib/utils/const.js +6 -1
  87. package/lib/utils/eval-json-js.js +31 -0
  88. package/lib/utils/get-entry-name.js +3 -3
  89. package/lib/utils/get-json-content.js +42 -0
  90. package/lib/utils/get-relative-path.js +25 -0
  91. package/lib/utils/match-condition.js +4 -1
  92. package/lib/utils/normalize.js +4 -2
  93. package/lib/utils/resolve.js +13 -0
  94. package/lib/web/processJSON.js +113 -144
  95. package/lib/web/processScript.js +45 -38
  96. package/lib/web/processTemplate.js +56 -41
  97. package/lib/wxml/loader.js +1 -6
  98. package/lib/wxs/WxsModuleIdsPlugin.js +11 -14
  99. package/lib/wxs/i18n-loader.js +5 -4
  100. package/lib/wxs/loader.js +87 -56
  101. package/lib/wxs/pre-loader.js +30 -10
  102. package/lib/wxss/loader.js +3 -3
  103. package/lib/wxss/processCss.js +135 -131
  104. package/package.json +23 -17
  105. package/lib/built-in-loader.js +0 -49
  106. package/lib/dependencies/RecordStaticResourceDependency.js +0 -47
  107. package/lib/utils/get-main-compilation.js +0 -6
  108. package/lib/utils/read-json-for-src.js +0 -34
@@ -3,156 +3,160 @@
3
3
  Author Tobias Koppers @sokra
4
4
  Modified by @hiyuki
5
5
  */
6
- var formatCodeFrame = require('babel-code-frame')
7
- var Tokenizer = require('css-selector-tokenizer')
8
- var postcss = require('postcss')
9
- var loaderUtils = require('loader-utils')
10
- var assign = require('object-assign')
11
- var getLocalIdent = require('./getLocalIdent')
6
+ const formatCodeFrame = require('@babel/code-frame')
7
+ const Tokenizer = require('css-selector-tokenizer')
8
+ const postcss = require('postcss')
9
+ const loaderUtils = require('loader-utils')
10
+ const assign = require('object-assign')
11
+ const getLocalIdent = require('./getLocalIdent')
12
12
 
13
- var icssUtils = require('icss-utils')
14
- var localByDefault = require('postcss-modules-local-by-default')
15
- var extractImports = require('postcss-modules-extract-imports')
16
- var modulesScope = require('postcss-modules-scope')
17
- var modulesValues = require('postcss-modules-values')
18
- var valueParser = require('postcss-value-parser')
19
- var isUrlRequest = require('../utils/is-url-request')
13
+ const icssUtils = require('icss-utils')
14
+ const localByDefault = require('postcss-modules-local-by-default')
15
+ const extractImports = require('postcss-modules-extract-imports')
16
+ const modulesScope = require('postcss-modules-scope')
17
+ const modulesValues = require('postcss-modules-values')
18
+ const valueParser = require('postcss-value-parser')
19
+ const isUrlRequest = require('../utils/is-url-request')
20
+ // css-loader-parser
20
21
 
21
- var parserPlugin = postcss.plugin('css-loader-parser', function (options) {
22
- return function (css) {
23
- var imports = {}
24
- var exports = {}
25
- var importItems = []
26
- var urlItems = []
22
+ const parserPlugin = function (options) {
23
+ return {
24
+ postcssPlugin: 'css-loader-parser',
25
+ Once (css) {
26
+ const imports = {}
27
+ let exports = {}
28
+ const importItems = []
29
+ const urlItems = []
30
+
31
+ function replaceImportsInString (str) {
32
+ if (options.import) {
33
+ const tokens = valueParser(str)
34
+ tokens.walk(function (node) {
35
+ if (node.type !== 'word') {
36
+ return
37
+ }
38
+ const token = node.value
39
+ const importIndex = imports['$' + token]
40
+ if (typeof importIndex === 'number') {
41
+ node.value = '___CSS_LOADER_IMPORT___' + importIndex + '___'
42
+ }
43
+ })
44
+ return tokens.toString()
45
+ }
46
+ return str
47
+ }
27
48
 
28
- function replaceImportsInString (str) {
29
49
  if (options.import) {
30
- var tokens = valueParser(str)
31
- tokens.walk(function (node) {
32
- if (node.type !== 'word') {
50
+ css.walkAtRules(/^import$/i, function (rule) {
51
+ const values = Tokenizer.parseValues(rule.params)
52
+ let url = values.nodes[0].nodes[0]
53
+ if (url && url.type === 'url') {
54
+ url = url.url
55
+ } else if (url && url.type === 'string') {
56
+ url = url.value
57
+ } else throw rule.error('Unexpected format ' + rule.params)
58
+ if (!url.replace(/\s/g, '').length) {
33
59
  return
34
60
  }
35
- var token = node.value
36
- var importIndex = imports['$' + token]
37
- if (typeof importIndex === 'number') {
38
- node.value = '___CSS_LOADER_IMPORT___' + importIndex + '___'
61
+ values.nodes[0].nodes.shift()
62
+ const mediaQuery = Tokenizer.stringifyValues(values)
63
+
64
+ if (isUrlRequest(url, options.root)) {
65
+ url = loaderUtils.urlToRequest(url, options.root)
39
66
  }
67
+
68
+ importItems.push({
69
+ url: url,
70
+ mediaQuery: mediaQuery
71
+ })
72
+ rule.remove()
40
73
  })
41
- return tokens.toString()
42
74
  }
43
- return str
44
- }
45
-
46
- if (options.import) {
47
- css.walkAtRules(/^import$/i, function (rule) {
48
- var values = Tokenizer.parseValues(rule.params)
49
- var url = values.nodes[0].nodes[0]
50
- if (url && url.type === 'url') {
51
- url = url.url
52
- } else if (url && url.type === 'string') {
53
- url = url.value
54
- } else throw rule.error('Unexpected format ' + rule.params)
55
- if (!url.replace(/\s/g, '').length) {
56
- return
57
- }
58
- values.nodes[0].nodes.shift()
59
- var mediaQuery = Tokenizer.stringifyValues(values)
60
75
 
61
- if (isUrlRequest(url, options.root)) {
62
- url = loaderUtils.urlToRequest(url, options.root)
63
- }
64
-
65
- importItems.push({
66
- url: url,
67
- mediaQuery: mediaQuery
76
+ const icss = icssUtils.extractICSS(css)
77
+ exports = icss.icssExports
78
+ Object.keys(icss.icssImports).forEach(function (key) {
79
+ const url = loaderUtils.parseString(key)
80
+ Object.keys(icss.icssImports[key]).forEach(function (prop) {
81
+ imports['$' + prop] = importItems.length
82
+ importItems.push({
83
+ url: url,
84
+ export: icss.icssImports[key][prop]
85
+ })
68
86
  })
69
- rule.remove()
70
87
  })
71
- }
72
88
 
73
- var icss = icssUtils.extractICSS(css)
74
- exports = icss.icssExports
75
- Object.keys(icss.icssImports).forEach(function (key) {
76
- var url = loaderUtils.parseString(key)
77
- Object.keys(icss.icssImports[key]).forEach(function (prop) {
78
- imports['$' + prop] = importItems.length
79
- importItems.push({
80
- url: url,
81
- export: icss.icssImports[key][prop]
82
- })
89
+ Object.keys(exports).forEach(function (exportName) {
90
+ exports[exportName] = replaceImportsInString(exports[exportName])
83
91
  })
84
- })
85
-
86
- Object.keys(exports).forEach(function (exportName) {
87
- exports[exportName] = replaceImportsInString(exports[exportName])
88
- })
89
92
 
90
- function isAlias (url) {
91
- // Handle alias starting by / and root disabled
92
- return url !== options.resolve(url)
93
- }
93
+ function isAlias (url) {
94
+ // Handle alias starting by / and root disabled
95
+ return url !== options.resolve(url)
96
+ }
94
97
 
95
- function processNode (item) {
96
- switch (item.type) {
97
- case 'value':
98
- item.nodes.forEach(processNode)
99
- break
100
- case 'nested-item':
101
- item.nodes.forEach(processNode)
102
- break
103
- case 'item':
104
- var importIndex = imports['$' + item.name]
105
- if (typeof importIndex === 'number') {
106
- item.name = '___CSS_LOADER_IMPORT___' + importIndex + '___'
107
- }
108
- break
109
- case 'url':
110
- if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && (isAlias(item.url) || isUrlRequest(item.url, options.root))) {
111
- // Strip quotes, they will be re-added if the module needs them
112
- item.stringType = ''
113
- delete item.innerSpacingBefore
114
- delete item.innerSpacingAfter
115
- var url = item.url
116
- item.url = '___CSS_LOADER_URL___' + urlItems.length + '___'
117
- urlItems.push({
118
- url: url
119
- })
120
- }
121
- break
98
+ function processNode (item) {
99
+ switch (item.type) {
100
+ case 'value':
101
+ item.nodes.forEach(processNode)
102
+ break
103
+ case 'nested-item':
104
+ item.nodes.forEach(processNode)
105
+ break
106
+ case 'item':
107
+ const importIndex = imports['$' + item.name]
108
+ if (typeof importIndex === 'number') {
109
+ item.name = '___CSS_LOADER_IMPORT___' + importIndex + '___'
110
+ }
111
+ break
112
+ case 'url':
113
+ if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && (isAlias(item.url) || isUrlRequest(item.url, options.root))) {
114
+ // Strip quotes, they will be re-added if the module needs them
115
+ item.stringType = ''
116
+ delete item.innerSpacingBefore
117
+ delete item.innerSpacingAfter
118
+ const url = item.url
119
+ item.url = '___CSS_LOADER_URL___' + urlItems.length + '___'
120
+ urlItems.push({
121
+ url: url
122
+ })
123
+ }
124
+ break
125
+ }
122
126
  }
123
- }
124
127
 
125
- css.walkDecls(function (decl) {
126
- var values = Tokenizer.parseValues(decl.value)
127
- values.nodes.forEach(function (value) {
128
- value.nodes.forEach(processNode)
128
+ css.walkDecls(function (decl) {
129
+ const values = Tokenizer.parseValues(decl.value)
130
+ values.nodes.forEach(function (value) {
131
+ value.nodes.forEach(processNode)
132
+ })
133
+ decl.value = Tokenizer.stringifyValues(values)
134
+ })
135
+ css.walkAtRules(function (atrule) {
136
+ if (typeof atrule.params === 'string') {
137
+ atrule.params = replaceImportsInString(atrule.params)
138
+ }
129
139
  })
130
- decl.value = Tokenizer.stringifyValues(values)
131
- })
132
- css.walkAtRules(function (atrule) {
133
- if (typeof atrule.params === 'string') {
134
- atrule.params = replaceImportsInString(atrule.params)
135
- }
136
- })
137
140
 
138
- options.importItems = importItems
139
- options.urlItems = urlItems
140
- options.exports = exports
141
+ options.importItems = importItems
142
+ options.urlItems = urlItems
143
+ options.exports = exports
144
+ }
141
145
  }
142
- })
146
+ }
143
147
 
144
148
  module.exports = function processCss (inputSource, inputMap, options, callback) {
145
- var query = options.query
146
- var root = query.root && query.root.length > 0 ? query.root.replace(/\/$/, '') : query.root
147
- var context = query.context
148
- var localIdentName = query.localIdentName || '[hash:base64]'
149
- var localIdentRegExp = query.localIdentRegExp
150
- var forceMinimize = query.minimize
151
- var minimize = typeof forceMinimize !== 'undefined' ? !!forceMinimize : options.minimize
149
+ const query = options.query
150
+ const root = query.root && query.root.length > 0 ? query.root.replace(/\/$/, '') : query.root
151
+ const context = query.context
152
+ const localIdentName = query.localIdentName || '[hash:base64]'
153
+ const localIdentRegExp = query.localIdentRegExp
154
+ const forceMinimize = query.minimize
155
+ const minimize = typeof forceMinimize !== 'undefined' ? !!forceMinimize : options.minimize
152
156
 
153
- var customGetLocalIdent = query.getLocalIdent || getLocalIdent
157
+ const customGetLocalIdent = query.getLocalIdent || getLocalIdent
154
158
 
155
- var parserOptions = {
159
+ const parserOptions = {
156
160
  root: root,
157
161
  mode: options.mode,
158
162
  url: query.url !== false,
@@ -160,7 +164,7 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
160
164
  resolve: options.resolve
161
165
  }
162
166
 
163
- var pipeline = postcss([
167
+ const pipeline = postcss([
164
168
  modulesValues,
165
169
  localByDefault({
166
170
  mode: options.mode,
@@ -192,8 +196,8 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
192
196
  ])
193
197
 
194
198
  if (minimize) {
195
- var cssnano = require('cssnano')
196
- var minimizeOptions = assign({}, query.minimize);
199
+ const cssnano = require('cssnano')
200
+ const minimizeOptions = assign({}, query.minimize);
197
201
  ['zindex', 'normalizeUrl', 'discardUnused', 'mergeIdents', 'reduceIdents', 'autoprefixer', 'svgo'].forEach(function (name) {
198
202
  if (typeof minimizeOptions[name] === 'undefined') {
199
203
  minimizeOptions[name] = false
@@ -226,7 +230,7 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
226
230
  })
227
231
  }).catch(function (err) {
228
232
  if (err.name === 'CssSyntaxError') {
229
- var wrappedError = new CSSLoaderError(
233
+ const wrappedError = new CSSLoaderError(
230
234
  'Syntax Error',
231
235
  err.reason,
232
236
  err.line != null && err.column != null
@@ -242,7 +246,7 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
242
246
  }
243
247
 
244
248
  function formatMessage (message, loc, source) {
245
- var formatted = message
249
+ let formatted = message
246
250
  if (loc) {
247
251
  formatted = formatted +
248
252
  ' (' + loc.line + ':' + loc.column + ')'
@@ -260,7 +264,7 @@ function CSSLoaderError (name, message, loc, source, error) {
260
264
  this.name = name
261
265
  this.error = error
262
266
  this.message = formatMessage(message, loc, source)
263
- this.hideStack = true
267
+ this.message = formatMessage(message, loc, source)
264
268
  }
265
269
 
266
270
  CSSLoaderError.prototype = Object.create(Error.prototype)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.7.0-alpha.0",
3
+ "version": "2.7.0-alpha.2",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -15,6 +15,11 @@
15
15
  "lib"
16
16
  ],
17
17
  "dependencies": {
18
+ "@babel/code-frame": "^7.16.0",
19
+ "@babel/generator": "^7.16.0",
20
+ "@babel/parser": "^7.16.2",
21
+ "@babel/traverse": "^7.16.0",
22
+ "@babel/types": "^7.16.0",
18
23
  "@better-scroll/core": "^2.2.1",
19
24
  "@better-scroll/movable": "^2.2.1",
20
25
  "@better-scroll/observe-dom": "^2.2.1",
@@ -22,17 +27,15 @@
22
27
  "@better-scroll/slide": "^2.2.1",
23
28
  "@better-scroll/wheel": "^2.2.1",
24
29
  "@better-scroll/zoom": "^2.2.1",
30
+ "@hummer/tenon-dev-server-webpack-plugin": "0.0.2",
31
+ "@hummer/tenon-loader": "^1.1.0",
32
+ "@hummer/tenon-style-loader": "^0.2.0",
25
33
  "acorn-walk": "^7.2.0",
26
34
  "async": "^2.6.0",
27
- "babel-code-frame": "^6.26.0",
28
- "babel-generator": "^6.26.1",
29
- "babel-traverse": "^6.26.0",
30
- "babel-types": "^6.26.0",
31
- "babylon": "^6.18.0",
32
35
  "consolidate": "^0.15.1",
33
36
  "css": "^2.2.1",
34
37
  "css-selector-tokenizer": "^0.7.0",
35
- "cssnano": "^3.10.0",
38
+ "cssnano": "^5.0.16",
36
39
  "de-indent": "^1.0.2",
37
40
  "fastparse": "^1.1.1",
38
41
  "hash-sum": "^1.0.2",
@@ -40,20 +43,20 @@
40
43
  "html-minifier": "^3.5.8",
41
44
  "icss-utils": "^2.1.0",
42
45
  "json5": "^2.1.3",
43
- "loader-utils": "1.1.0",
46
+ "loader-utils": "^2.0.2",
44
47
  "lodash": "^4.17.15",
45
48
  "lodash.camelcase": "^4.3.0",
46
49
  "lru-cache": "^4.1.2",
47
50
  "mime": "^2.2.2",
48
51
  "object-assign": "^4.1.1",
49
- "postcss": "^6.0.19",
50
- "postcss-load-config": "^1.2.0",
51
- "postcss-modules-extract-imports": "^1.2.0",
52
- "postcss-modules-local-by-default": "^1.2.0",
53
- "postcss-modules-scope": "^1.1.0",
54
- "postcss-modules-values": "^1.3.0",
55
- "postcss-selector-parser": "^2.0.0",
56
- "postcss-value-parser": "^3.3.0",
52
+ "postcss": "^8.4.5",
53
+ "postcss-load-config": "^3.1.1",
54
+ "postcss-modules-extract-imports": "^3.0.0",
55
+ "postcss-modules-local-by-default": "^4.0.0",
56
+ "postcss-modules-scope": "^3.0.0",
57
+ "postcss-modules-values": "^4.0.0",
58
+ "postcss-selector-parser": "^6.0.8",
59
+ "postcss-value-parser": "^4.0.2",
57
60
  "source-list-map": "^2.0.0"
58
61
  },
59
62
  "peerDependencies": {
@@ -77,5 +80,8 @@
77
80
  "@types/babel-traverse": "^6.25.4",
78
81
  "@types/babel-types": "^7.0.4"
79
82
  },
80
- "gitHead": "43fe072e744b33b841b8e396677711e414bcca8b"
83
+ "engines": {
84
+ "node": ">=14.14.0"
85
+ },
86
+ "gitHead": "75746a75d879c5d202ec096f58281ed43f0ff351"
81
87
  }
@@ -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
- }
@@ -1,47 +0,0 @@
1
- const NullDependency = require('webpack/lib/dependencies/NullDependency')
2
- const makeSerializable = require('webpack/lib/util/makeSerializable')
3
-
4
- class RecordStaticResourceDependency extends NullDependency {
5
- constructor (resourcePath, outputPath, packageRoot = '') {
6
- super()
7
- this.resourcePath = resourcePath
8
- this.outputPath = outputPath
9
- this.packageRoot = packageRoot
10
- }
11
-
12
- get type () {
13
- return 'mpx record static resource'
14
- }
15
-
16
- mpxAction (module, compilation, callback) {
17
- const mpx = compilation.__mpx__
18
- const packageName = this.packageRoot || 'main'
19
- mpx.staticResourcesMap[packageName][this.resourcePath] = this.outputPath
20
- return callback()
21
- }
22
-
23
- serialize (context) {
24
- const { write } = context
25
- write(this.resourcePath)
26
- write(this.outputPath)
27
- write(this.packageRoot)
28
- super.serialize(context)
29
- }
30
-
31
- deserialize (context) {
32
- const { read } = context
33
- this.resourcePath = read()
34
- this.outputPath = read()
35
- this.packageRoot = read()
36
- super.deserialize(context)
37
- }
38
- }
39
-
40
- RecordStaticResourceDependency.Template = class RecordStaticResourceDependencyTemplate {
41
- apply () {
42
- }
43
- }
44
-
45
- makeSerializable(RecordStaticResourceDependency, '@mpxjs/webpack-plugin/lib/dependencies/RecordStaticResourceDependency')
46
-
47
- module.exports = RecordStaticResourceDependency
@@ -1,6 +0,0 @@
1
- module.exports = function (compilation) {
2
- while (compilation.compiler.parentCompilation) {
3
- compilation = compilation.compiler.parentCompilation
4
- }
5
- return compilation
6
- }
@@ -1,34 +0,0 @@
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
- }