@mpxjs/webpack-plugin 2.7.52 → 2.8.0-beta.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 (71) hide show
  1. package/lib/config.js +24 -24
  2. package/lib/dependencies/CommonJsVariableDependency.js +1 -1
  3. package/lib/dependencies/DynamicEntryDependency.js +18 -11
  4. package/lib/extractor.js +1 -1
  5. package/lib/helpers.js +3 -1
  6. package/lib/index.js +24 -21
  7. package/lib/json-compiler/helper.js +1 -1
  8. package/lib/json-compiler/index.js +17 -17
  9. package/lib/json-compiler/plugin.js +3 -2
  10. package/lib/json-compiler/theme.js +1 -1
  11. package/lib/loader.js +3 -3
  12. package/lib/native-loader.js +1 -1
  13. package/lib/platform/json/normalize-test.js +3 -1
  14. package/lib/platform/run-rules.js +2 -2
  15. package/lib/platform/template/wx/component-config/camera.js +3 -3
  16. package/lib/platform/template/wx/component-config/canvas.js +5 -5
  17. package/lib/platform/template/wx/component-config/map.js +5 -5
  18. package/lib/platform/template/wx/component-config/navigator.js +7 -7
  19. package/lib/platform/template/wx/component-config/progress.js +4 -4
  20. package/lib/platform/template/wx/component-config/scroll-view.js +3 -3
  21. package/lib/platform/template/wx/component-config/slider.js +6 -6
  22. package/lib/platform/template/wx/component-config/swiper.js +2 -2
  23. package/lib/platform/template/wx/component-config/video.js +4 -4
  24. package/lib/platform/template/wx/component-config/view.js +4 -4
  25. package/lib/platform/template/wx/index.js +45 -13
  26. package/lib/resolver/PackageEntryPlugin.js +1 -1
  27. package/lib/runtime/components/web/filterTag.js +6 -6
  28. package/lib/runtime/components/web/getInnerListeners.js +1 -1
  29. package/lib/runtime/components/web/mpx-button.vue +0 -1
  30. package/lib/runtime/components/web/mpx-icon.vue +1 -1
  31. package/lib/runtime/components/web/mpx-keep-alive.vue +2 -2
  32. package/lib/runtime/components/web/mpx-picker.vue +1 -1
  33. package/lib/runtime/components/web/mpx-progress.vue +1 -1
  34. package/lib/runtime/components/web/mpx-scroll-view.vue +1 -1
  35. package/lib/runtime/env.js +1 -0
  36. package/lib/runtime/i18n.wxs +44 -81
  37. package/lib/runtime/optionProcessor.d.ts +0 -4
  38. package/lib/runtime/optionProcessor.js +15 -13
  39. package/lib/runtime/stringify.wxs +3 -3
  40. package/lib/runtime/swanHelper.wxs +2 -2
  41. package/lib/runtime/{components/web/util.js → utils.js} +8 -5
  42. package/lib/script-setup-compiler/index.js +1163 -0
  43. package/lib/style-compiler/index.js +1 -1
  44. package/lib/style-compiler/plugins/rpx.js +1 -1
  45. package/lib/style-compiler/plugins/vw.js +6 -4
  46. package/lib/template-compiler/bind-this.js +5 -5
  47. package/lib/template-compiler/compiler.js +122 -179
  48. package/lib/template-compiler/index.js +3 -3
  49. package/lib/utils/add-query.js +2 -1
  50. package/lib/utils/gen-component-tag.js +1 -1
  51. package/lib/utils/has-own.js +5 -0
  52. package/lib/utils/is-empty-object.js +2 -1
  53. package/lib/utils/parse-request.js +3 -3
  54. package/lib/utils/{index.js → process-defs.js} +3 -10
  55. package/lib/utils/stringify-query.js +23 -21
  56. package/lib/web/processJSON.js +5 -5
  57. package/lib/web/processScript.js +16 -19
  58. package/lib/web/processTemplate.js +1 -1
  59. package/lib/wxml/loader.js +3 -3
  60. package/lib/wxs/i18n-loader.js +4 -11
  61. package/lib/wxs/pre-loader.js +51 -44
  62. package/lib/wxss/compile-exports.js +4 -4
  63. package/lib/wxss/createResolver.js +3 -3
  64. package/lib/wxss/css-base.js +13 -13
  65. package/lib/wxss/getLocalIdent.js +5 -4
  66. package/lib/wxss/loader.js +1 -1
  67. package/lib/wxss/localsLoader.js +14 -14
  68. package/lib/wxss/processCss.js +10 -7
  69. package/package.json +4 -3
  70. package/lib/utils/env.js +0 -4
  71. package/lib/utils/parse-asset.js +0 -195
@@ -3,18 +3,18 @@
3
3
  Author Tobias Koppers @sokra
4
4
  Modified by @hiyuki
5
5
  */
6
- var loaderUtils = require('loader-utils')
7
- var processCss = require('./processCss')
8
- var compileExports = require('./compile-exports')
9
- var createResolver = require('./createResolver')
6
+ const loaderUtils = require('loader-utils')
7
+ const processCss = require('./processCss')
8
+ const compileExports = require('./compile-exports')
9
+ const createResolver = require('./createResolver')
10
10
 
11
11
  module.exports = function (content) {
12
12
  if (this.cacheable) this.cacheable()
13
- var callback = this.async()
14
- var query = loaderUtils.getOptions(this) || {}
15
- var moduleMode = query.modules || query.module
16
- var camelCaseKeys = query.camelCase || query.camelcase
17
- var resolve = createResolver(query.alias)
13
+ const callback = this.async()
14
+ const query = loaderUtils.getOptions(this) || {}
15
+ const moduleMode = query.modules || query.module
16
+ const camelCaseKeys = query.camelCase || query.camelcase
17
+ const resolve = createResolver(query.alias)
18
18
 
19
19
  processCss(content, null, {
20
20
  mode: moduleMode ? 'local' : 'global',
@@ -26,15 +26,15 @@ module.exports = function (content) {
26
26
  if (err) return callback(err)
27
27
 
28
28
  function importItemMatcher (item) {
29
- var match = result.importItemRegExp.exec(item)
30
- var idx = +match[1]
31
- var importItem = result.importItems[idx]
32
- var importUrl = importItem.url
29
+ const match = result.importItemRegExp.exec(item)
30
+ const idx = +match[1]
31
+ const importItem = result.importItems[idx]
32
+ const importUrl = importItem.url
33
33
  return '" + require(' + loaderUtils.stringifyRequest(this, importUrl) + ')' +
34
34
  '[' + JSON.stringify(importItem.export) + '] + "'
35
35
  }
36
36
 
37
- var exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys)
37
+ let exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys)
38
38
  if (exportJs) {
39
39
  exportJs = 'module.exports = ' + exportJs + ';'
40
40
  }
@@ -103,12 +103,13 @@ const parserPlugin = function (options) {
103
103
  case 'nested-item':
104
104
  item.nodes.forEach(processNode)
105
105
  break
106
- case 'item':
106
+ case 'item': {
107
107
  const importIndex = imports['$' + item.name]
108
108
  if (typeof importIndex === 'number') {
109
109
  item.name = '___CSS_LOADER_IMPORT___' + importIndex + '___'
110
110
  }
111
111
  break
112
+ }
112
113
  case 'url':
113
114
  if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && (isAlias(item.url) || isUrlRequest(item.url, options.root))) {
114
115
  // Strip quotes, they will be re-added if the module needs them
@@ -210,12 +211,14 @@ module.exports = function processCss (inputSource, inputMap, options, callback)
210
211
  // we need a prefix to avoid path rewriting of PostCSS
211
212
  from: '/css-loader!' + options.from,
212
213
  to: options.to,
213
- map: options.sourceMap ? {
214
- prev: inputMap,
215
- sourcesContent: true,
216
- inline: false,
217
- annotation: false
218
- } : null
214
+ map: options.sourceMap
215
+ ? {
216
+ prev: inputMap,
217
+ sourcesContent: true,
218
+ inline: false,
219
+ annotation: false
220
+ }
221
+ : null
219
222
  }).then(function (result) {
220
223
  callback(null, {
221
224
  source: result.css,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.7.52",
3
+ "version": "2.8.0-beta.2",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -60,7 +60,8 @@
60
60
  "webpack": "^5.48.0"
61
61
  },
62
62
  "publishConfig": {
63
- "registry": "https://registry.npmjs.org"
63
+ "registry": "https://registry.npmjs.org",
64
+ "access": "public"
64
65
  },
65
66
  "repository": {
66
67
  "type": "git",
@@ -80,5 +81,5 @@
80
81
  "engines": {
81
82
  "node": ">=14.14.0"
82
83
  },
83
- "gitHead": "187abad504151455e045c0adf2fe7f81412e0fef"
84
+ "gitHead": "cd57f83a9d47236f527bd51a8650119514f4b433"
84
85
  }
package/lib/utils/env.js DELETED
@@ -1,4 +0,0 @@
1
- /**
2
- * 判断当前环境是否是浏览器环境
3
- */
4
- exports.inBrowser = typeof window !== 'undefined'
@@ -1,195 +0,0 @@
1
- const _ = require('lodash')
2
-
3
- const acorn = require('acorn')
4
-
5
- const walk = require('acorn-walk')
6
-
7
- module.exports = parseAsset
8
-
9
- function parseAsset (content) {
10
- const ast = acorn.parse(content, {
11
- sourceType: 'script',
12
- // I believe in a bright future of ECMAScript!
13
- // Actually, it's set to `2050` to support the latest ECMAScript version that currently exists.
14
- // Seems like `acorn` supports such weird option value.
15
- ecmaVersion: 2050
16
- })
17
- const walkState = {
18
- locations: null
19
- }
20
- walk.recursive(ast, walkState, {
21
- AssignmentExpression (node, state, c) {
22
- if (state.locations) return // Modules are stored in exports.modules:
23
- // exports.modules = {};
24
-
25
- const {
26
- left,
27
- right
28
- } = node
29
-
30
- if (left && left.object && left.object.name === 'exports' && left.property && left.property.name === 'modules' && isModulesHash(right)) {
31
- state.locations = getModulesLocations(right)
32
- }
33
-
34
- // module.exports = ... recursive walk right
35
- if (left && left.object && left.object.name === 'module' && left.property && left.property.name === 'exports') {
36
- c(right, state)
37
- }
38
- },
39
-
40
- CallExpression (node, state, c) {
41
- if (state.locations) return
42
- const args = node.arguments // Main chunk with webpack loader.
43
- // Modules are stored in first argument:
44
- // (function (...) {...})(<modules>)
45
-
46
- if (node.callee.type === 'FunctionExpression' && !node.callee.id && args.length === 1 && isSimpleModulesList(args[0])) {
47
- state.locations = getModulesLocations(args[0])
48
- return
49
- } // Async Webpack < v4 chunk without webpack loader.
50
- // webpackJsonp([<chunks>], <modules>, ...)
51
- // As function name may be changed with `output.jsonpFunction` option we can't rely on it's default name.
52
-
53
- if (node.callee.type === 'Identifier' && mayBeAsyncChunkArguments(args) && isModulesList(args[1])) {
54
- state.locations = getModulesLocations(args[1])
55
- return
56
- } // Async Webpack v4 chunk without webpack loader.
57
- // (window.webpackJsonp=window.webpackJsonp||[]).push([[<chunks>], <modules>, ...]);
58
- // As function name may be changed with `output.jsonpFunction` option we can't rely on it's default name.
59
-
60
- if (isAsyncChunkPushExpression(node)) {
61
- state.locations = getModulesLocations(args[0].elements[1])
62
- return
63
- } // Webpack v4 WebWorkerChunkTemplatePlugin
64
- // globalObject.chunkCallbackName([<chunks>],<modules>, ...);
65
- // Both globalObject and chunkCallbackName can be changed through the config, so we can't check them.
66
-
67
- if (isAsyncWebWorkerChunkExpression(node)) {
68
- state.locations = getModulesLocations(args[1])
69
- return
70
- } // Walking into arguments because some of plugins (e.g. `DedupePlugin`) or some Webpack
71
- // features (e.g. `umd` library output) can wrap modules list into additional IIFE.
72
-
73
- _.each(args, arg => c(arg, state))
74
- }
75
-
76
- })
77
- let modules
78
-
79
- if (walkState.locations) {
80
- modules = _.mapValues(walkState.locations, loc => content.slice(loc.start, loc.end))
81
- } else {
82
- modules = {}
83
- }
84
-
85
- return modules
86
- }
87
-
88
- function isModulesList (node) {
89
- return isSimpleModulesList(node) || // Modules are contained in expression `Array([minimum ID]).concat([<module>, <module>, ...])`
90
- isOptimizedModulesArray(node)
91
- }
92
-
93
- function isSimpleModulesList (node) {
94
- return (// Modules are contained in hash. Keys are module ids.
95
- isModulesHash(node) || // Modules are contained in array. Indexes are module ids.
96
- isModulesArray(node)
97
- )
98
- }
99
-
100
- function isModulesHash (node) {
101
- return node.type === 'ObjectExpression' && _(node.properties).map('value').every(isModuleWrapper)
102
- }
103
-
104
- function isModulesArray (node) {
105
- return node.type === 'ArrayExpression' && _.every(node.elements, elem => // Some of array items may be skipped because there is no module with such id
106
- !elem || isModuleWrapper(elem))
107
- }
108
-
109
- function isOptimizedModulesArray (node) {
110
- // Checking whether modules are contained in `Array(<minimum ID>).concat(...modules)` array:
111
- // https://github.com/webpack/webpack/blob/v1.14.0/lib/Template.js#L91
112
- // The `<minimum ID>` + array indexes are module ids
113
- return node.type === 'CallExpression' && node.callee.type === 'MemberExpression' && // Make sure the object called is `Array(<some number>)`
114
- node.callee.object.type === 'CallExpression' && node.callee.object.callee.type === 'Identifier' && node.callee.object.callee.name === 'Array' && node.callee.object.arguments.length === 1 && isNumericId(node.callee.object.arguments[0]) && // Make sure the property X called for `Array(<some number>).X` is `concat`
115
- node.callee.property.type === 'Identifier' && node.callee.property.name === 'concat' && // Make sure exactly one array is passed in to `concat`
116
- node.arguments.length === 1 && isModulesArray(node.arguments[0])
117
- }
118
-
119
- function isModuleWrapper (node) {
120
- /* eslint-disable no-mixed-operators */
121
- return (// It's an anonymous function expression that wraps module
122
- (node.type === 'FunctionExpression' || node.type === 'ArrowFunctionExpression') && !node.id || // If `DedupePlugin` is used it can be an ID of duplicated module...
123
- isModuleId(node) || // or an array of shape [<module_id>, ...args]
124
- node.type === 'ArrayExpression' && node.elements.length > 1 && isModuleId(node.elements[0])
125
- )
126
- }
127
-
128
- function isModuleId (node) {
129
- return node.type === 'Literal' && (isNumericId(node) || typeof node.value === 'string')
130
- }
131
-
132
- function isNumericId (node) {
133
- return node.type === 'Literal' && Number.isInteger(node.value) && node.value >= 0
134
- }
135
-
136
- function isChunkIds (node) {
137
- // Array of numeric or string ids. Chunk IDs are strings when NamedChunksPlugin is used
138
- return node.type === 'ArrayExpression' && _.every(node.elements, isModuleId)
139
- }
140
-
141
- function isAsyncChunkPushExpression (node) {
142
- const {
143
- callee,
144
- arguments: args
145
- } = node
146
- return callee.type === 'MemberExpression' && callee.property.name === 'push' && callee.object.type === 'AssignmentExpression' && args.length === 1 && args[0].type === 'ArrayExpression' && mayBeAsyncChunkArguments(args[0].elements) && isModulesList(args[0].elements[1])
147
- }
148
-
149
- function mayBeAsyncChunkArguments (args) {
150
- return args.length >= 2 && isChunkIds(args[0])
151
- }
152
-
153
- function isAsyncWebWorkerChunkExpression (node) {
154
- const {
155
- callee,
156
- type,
157
- arguments: args
158
- } = node
159
- return type === 'CallExpression' && callee.type === 'MemberExpression' && args.length === 2 && isChunkIds(args[0]) && isModulesList(args[1])
160
- }
161
-
162
- function getModulesLocations (node) {
163
- if (node.type === 'ObjectExpression') {
164
- // Modules hash
165
- const modulesNodes = node.properties
166
- return _.transform(modulesNodes, (result, moduleNode) => {
167
- const moduleId = moduleNode.key.name || moduleNode.key.value
168
- result[moduleId] = getModuleLocation(moduleNode.value)
169
- }, {})
170
- }
171
-
172
- const isOptimizedArray = node.type === 'CallExpression'
173
-
174
- if (node.type === 'ArrayExpression' || isOptimizedArray) {
175
- // Modules array or optimized array
176
- const minId = isOptimizedArray // Get the [minId] value from the Array() call first argument literal value
177
- ? node.callee.object.arguments[0].value // `0` for simple array
178
- : 0
179
- const modulesNodes = isOptimizedArray // The modules reside in the `concat()` function call arguments
180
- ? node.arguments[0].elements : node.elements
181
- return _.transform(modulesNodes, (result, moduleNode, i) => {
182
- if (!moduleNode) return
183
- result[i + minId] = getModuleLocation(moduleNode)
184
- }, {})
185
- }
186
-
187
- return {}
188
- }
189
-
190
- function getModuleLocation (node) {
191
- return {
192
- start: node.start,
193
- end: node.end
194
- }
195
- }