@mpxjs/webpack-plugin 2.7.19 → 2.7.20

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/index.js CHANGED
@@ -951,6 +951,9 @@ class MpxWebpackPlugin {
951
951
  parser.state.current.addDependency(dep)
952
952
  }
953
953
  return true
954
+ } else {
955
+ compilation.errors.push(new Error(`The require async JS [${request}] need to declare subpackage name by root`))
956
+ return true
954
957
  }
955
958
  }
956
959
  }
@@ -12,7 +12,7 @@ module.exports = function createJSONHelper ({ loaderContext, emitWarning, custom
12
12
  const resolveMode = mpx.resolveMode
13
13
  const externals = mpx.externals
14
14
  const root = mpx.projectRoot
15
- const publicPath = loaderContext._compilation.outputOptions.publicPath || ''
15
+ const publicPath = loaderContext._compilation?.outputOptions.publicPath || ''
16
16
  const pathHash = mpx.pathHash
17
17
  const getOutputPath = mpx.getOutputPath
18
18
  const mode = mpx.mode
@@ -96,6 +96,7 @@ module.exports = function (content) {
96
96
  } else {
97
97
  fs.readFile(file, (err, content) => {
98
98
  if (err) return callback(err)
99
+ if (!this._compilation) return callback()
99
100
  let targetPath = path.relative(context, file)
100
101
  this._compilation.assets[targetPath] = {
101
102
  size: function size () {
@@ -350,7 +351,7 @@ module.exports = function (content) {
350
351
  }
351
352
 
352
353
  const recordIndependent = (root, request) => {
353
- this._module.addPresentationalDependency(new RecordIndependentDependency(root, request))
354
+ this._module && this._module.addPresentationalDependency(new RecordIndependentDependency(root, request))
354
355
  }
355
356
 
356
357
  const processIndependent = (otherConfig, context, tarRoot, callback) => {
@@ -181,9 +181,36 @@ module.exports = function getSpec ({ warn, error }) {
181
181
  }
182
182
  }
183
183
  },
184
+ {
185
+ // style样式绑定
186
+ test: /^(style|wx:style)$/,
187
+ web ({ value }, { el }) {
188
+ if (el.isStyleParsed) {
189
+ return false
190
+ }
191
+ let styleBinding = []
192
+ el.isStyleParsed = true
193
+ el.attrsList.map((item, index) => {
194
+ const parsed = parseMustache(item.value)
195
+ if (item.name === 'style') {
196
+ if (parsed.hasBinding || parsed.result.indexOf('rpx') > -1) {
197
+ styleBinding.push(parseMustache(item.value).result)
198
+ } else {
199
+ styleBinding.push(JSON.stringify(item.value))
200
+ }
201
+ } else if (item.name === 'wx:style') {
202
+ styleBinding.push(parseMustache(item.value).result)
203
+ }
204
+ })
205
+ return {
206
+ name: ':style',
207
+ value: `[${styleBinding}] | transRpxStyle`
208
+ }
209
+ }
210
+ },
184
211
  {
185
212
  // 样式类名绑定
186
- test: /^wx:(class|style)$/,
213
+ test: /^wx:class$/,
187
214
  web ({ name, value }) {
188
215
  const dir = this.test.exec(name)[1]
189
216
  const parsed = parseMustache(value)
@@ -85,6 +85,51 @@ export default function processOption (
85
85
  }
86
86
  })
87
87
 
88
+ Vue.filter('transRpxStyle', style => {
89
+ const defaultTransRpxFn = function (match, $1) {
90
+ const rpx2vwRatio = +(100 / 750).toFixed(8)
91
+ return '' + ($1 * rpx2vwRatio) + 'vw'
92
+ }
93
+ const transRpxFn = global.__mpxTransRpxFn || defaultTransRpxFn
94
+ const parsedStyleObj = {}
95
+ const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
96
+ const parseStyleText = (cssText) => {
97
+ const listDelimiter = /;(?![^(]*\))/g
98
+ const propertyDelimiter = /:(.+)/
99
+ if (typeof cssText === 'string') {
100
+ cssText.split(listDelimiter).forEach((item) => {
101
+ if (item) {
102
+ var tmp = item.split(propertyDelimiter)
103
+ tmp.length > 1 && (parsedStyleObj[tmp[0].trim()] = tmp[1].trim())
104
+ }
105
+ })
106
+ } else if (typeof cssText === 'object') {
107
+ if (Array.isArray(cssText)) {
108
+ cssText.forEach(cssItem => {
109
+ parseStyleText(cssItem)
110
+ })
111
+ } else {
112
+ Object.assign(parsedStyleObj, cssText)
113
+ }
114
+ }
115
+ }
116
+ const transRpxStyleFn = (val) => {
117
+ if (typeof val === 'string' && val.indexOf('rpx') > 0) {
118
+ return val.replace(rpxRegExpG, transRpxFn).replace(/"/g, '')
119
+ }
120
+ return val
121
+ }
122
+ if (style) {
123
+ style.forEach(item => {
124
+ parseStyleText(item)
125
+ for (let key in parsedStyleObj) {
126
+ parsedStyleObj[key] = transRpxStyleFn(parsedStyleObj[key])
127
+ }
128
+ })
129
+ }
130
+ return parsedStyleObj
131
+ })
132
+
88
133
  const routes = []
89
134
 
90
135
  for (const pagePath in pagesMap) {
@@ -1,6 +1,7 @@
1
1
  const path = require('path')
2
2
 
3
3
  module.exports = function evalJSONJS (source, filename, loaderContext) {
4
+ if (!loaderContext._compiler) return {}
4
5
  const fs = loaderContext._compiler.inputFileSystem
5
6
  const defs = loaderContext.getMpx().defs
6
7
  const defKeys = Object.keys(defs)
@@ -1,8 +1,8 @@
1
1
  module.exports = function (loaderContext) {
2
- const compilation = loaderContext._compilation
3
- const moduleGraph = compilation.moduleGraph
2
+ if (!loaderContext._compilation) return ''
3
+ const moduleGraph = loaderContext._compilation.moduleGraph
4
4
  let entryName = ''
5
- for (const [name, { dependencies }] of compilation.entries) {
5
+ for (const [name, { dependencies }] of loaderContext._compilation.entries) {
6
6
  const entryModule = moduleGraph.getModule(dependencies[0])
7
7
  if (entryModule.resource === loaderContext.resource) {
8
8
  entryName = name
@@ -5,7 +5,6 @@ const async = require('async')
5
5
  const { JSON_JS_EXT } = require('./const')
6
6
 
7
7
  module.exports = function getJSONContent (json, loaderContext, callback) {
8
- // error process
9
8
  if (!loaderContext._compiler) return callback(null, '{}')
10
9
  const fs = loaderContext._compiler.inputFileSystem
11
10
  async.waterfall([
@@ -219,8 +219,7 @@ module.exports = function (json, {
219
219
  }
220
220
 
221
221
  pagesMap[resourcePath] = outputPath
222
- loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'page', outputPath))
223
-
222
+ loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'page', outputPath))
224
223
  localPagesMap[outputPath] = {
225
224
  resource: addQuery(resource, { isPage: true }),
226
225
  async: tarRoot || queryObj.async,
@@ -269,8 +268,7 @@ module.exports = function (json, {
269
268
  }
270
269
  const { resourcePath, queryObj } = parseRequest(resource)
271
270
  componentsMap[resourcePath] = outputPath
272
- loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
273
-
271
+ loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
274
272
  localComponentsMap[name] = {
275
273
  resource: addQuery(resource, {
276
274
  isComponent: true,
@@ -129,8 +129,8 @@ module.exports = function (script, {
129
129
  global.__networkTimeout = ${JSON.stringify(jsonConfig.networkTimeout)}
130
130
  global.__mpxGenericsMap = {}
131
131
  global.__style = ${JSON.stringify(jsonConfig.style || 'v1')}
132
- global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}\n`
133
-
132
+ global.__mpxPageConfig = ${JSON.stringify(jsonConfig.window)}
133
+ global.__mpxTransRpxFn = ${mpx.webConfig.transRpxFn}\n`
134
134
  if (i18n) {
135
135
  const i18nObj = Object.assign({}, i18n)
136
136
  content += ` import VueI18n from 'vue-i18n'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.7.19",
3
+ "version": "2.7.20",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -80,5 +80,5 @@
80
80
  "engines": {
81
81
  "node": ">=14.14.0"
82
82
  },
83
- "gitHead": "adadff7f3e1c658678def33059e222ef053af4d6"
83
+ "gitHead": "b4a3fea64b6a0135989ce9b3b26ccb24318b8027"
84
84
  }