@mpxjs/webpack-plugin 2.8.1 → 2.8.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.
package/lib/index.js CHANGED
@@ -45,7 +45,7 @@ const { matchCondition } = require('./utils/match-condition')
45
45
  const processDefs = require('./utils/process-defs')
46
46
  const config = require('./config')
47
47
  const hash = require('hash-sum')
48
- const wxssLoaderPath = normalize.lib('wxss/loader')
48
+ const wxssLoaderPath = normalize.lib('wxss/index')
49
49
  const wxmlLoaderPath = normalize.lib('wxml/loader')
50
50
  const wxsLoaderPath = normalize.lib('wxs/loader')
51
51
  const styleCompilerPath = normalize.lib('style-compiler/index')
@@ -197,7 +197,7 @@ class MpxWebpackPlugin {
197
197
 
198
198
  static wxssLoader (options) {
199
199
  return {
200
- loader: normalize.lib('wxss/loader'),
200
+ loader: normalize.lib('wxss/index'),
201
201
  options
202
202
  }
203
203
  }
@@ -274,7 +274,7 @@ module.exports = function (content) {
274
274
  })
275
275
  // 对于通过.mpx文件声明的独立分包,默认将其自身的script block视为init module
276
276
  if (queryObj.independent === true) queryObj.independent = result
277
- getJSONContent(parts.json || {}, this, (err, content) => {
277
+ getJSONContent(parts.json || {}, result, this, (err, content) => {
278
278
  callback(err, result, content)
279
279
  })
280
280
  } else {
package/lib/loader.js CHANGED
@@ -65,6 +65,10 @@ module.exports = function (content) {
65
65
  this._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, ctorType, entryName, packageRoot))
66
66
  }
67
67
 
68
+ if (ctorType === 'app') {
69
+ const appName = getEntryName(this)
70
+ this._module.addPresentationalDependency(new AppEntryDependency(resourcePath, appName))
71
+ }
68
72
  const loaderContext = this
69
73
  const stringifyRequest = r => loaderUtils.stringifyRequest(loaderContext, r)
70
74
  const isProduction = this.minimize || process.env.NODE_ENV === 'production'
@@ -87,7 +91,7 @@ module.exports = function (content) {
87
91
 
88
92
  async.waterfall([
89
93
  (callback) => {
90
- getJSONContent(parts.json || {}, loaderContext, (err, content) => {
94
+ getJSONContent(parts.json || {}, null, loaderContext, (err, content) => {
91
95
  if (err) return callback(err)
92
96
  if (parts.json) parts.json.content = content
93
97
  callback()
@@ -221,11 +225,6 @@ module.exports = function (content) {
221
225
  return callback(new Error(`Current ${ctorType} [${this.resourcePath}] is issued by [${issuer.resource}], which is not allowed!`))
222
226
  }
223
227
 
224
- if (ctorType === 'app') {
225
- const appName = getEntryName(this)
226
- this._module.addPresentationalDependency(new AppEntryDependency(resourcePath, appName))
227
- }
228
-
229
228
  // 注入模块id及资源路径
230
229
  output += `global.currentModuleId = ${JSON.stringify(moduleId)}\n`
231
230
  if (!isProduction) {
@@ -117,7 +117,7 @@ module.exports = function (content) {
117
117
  getJSONContent({
118
118
  src: typeResourceMap.json,
119
119
  useJSONJS
120
- }, this, callback)
120
+ }, null, this, callback)
121
121
  }, (content, callback) => {
122
122
  let json
123
123
  try {
@@ -3,7 +3,7 @@ const TAG_NAME = 'map'
3
3
  module.exports = function ({ print }) {
4
4
  const aliPropLog = print({ platform: 'ali', tag: TAG_NAME, isError: false })
5
5
  const aliEventLogError = print({ platform: 'ali', tag: TAG_NAME, isError: true, type: 'event' })
6
- const aliPropValueWarningLog = print({ platform: 'ali', tag: TAG_NAME, isError: true, type: 'value-attr-uniform' })
6
+ const aliPropValueWarningLog = print({ platform: 'ali', tag: TAG_NAME, isError: false, type: 'value-attr-uniform' })
7
7
  const baiduPropLog = print({ platform: 'baidu', tag: TAG_NAME, isError: false })
8
8
  const baiduEventLogError = print({ platform: 'baidu', tag: TAG_NAME, isError: true, type: 'event' })
9
9
  const jdPropLog = print({ platform: 'jd', tag: TAG_NAME, isError: false })
@@ -4,6 +4,7 @@ module.exports = class FixDescriptionInfoPlugin {
4
4
  apply (resolver) {
5
5
  resolver.hooks.result.tap('FixDescriptionInfoPlugin', (request) => {
6
6
  const { path: resourcePath } = request
7
+ if (!resourcePath) return
7
8
  const segments = resourcePath.split(path.sep)
8
9
  let rootIndex = -1
9
10
  for (let i = segments.length - 1; i >= 0; i--) {
@@ -0,0 +1,60 @@
1
+ module.exports = function (el, binding) {
2
+ const newActions = binding && binding.value && binding.value.actions
3
+ if (el.actions === newActions) {
4
+ Promise.resolve().then(() => {
5
+ Object.assign(el.style, el.lastDynamicStyle)
6
+ })
7
+ return
8
+ }
9
+ el.actions = newActions
10
+ if (typeof el.setAnimation === 'function') {
11
+ el.removeEventListener('transitionend', el.setAnimation, false)
12
+ el.setAnimation = undefined
13
+ }
14
+ el.dynamicStyleQueue = []
15
+ el.lastDynamicStyle = undefined
16
+ if (Array.isArray(newActions) && newActions.length) {
17
+ newActions.forEach((item) => {
18
+ const property = []
19
+ const { animates, option } = item
20
+ // 存储动画需要改变的样式属性
21
+ const dynamicStyle = {
22
+ transform: ''
23
+ }
24
+ animates.forEach((itemAnimation) => {
25
+ switch (itemAnimation.type) {
26
+ case 'style': {
27
+ const [key, value] = itemAnimation.args
28
+ dynamicStyle[key] = value
29
+ property.push(key)
30
+ break
31
+ }
32
+ default:
33
+ dynamicStyle.transform += `${itemAnimation.type}(${itemAnimation.args}) `
34
+ if (!property.includes('transform')) {
35
+ property.push('transform')
36
+ }
37
+ }
38
+ })
39
+ Object.assign(dynamicStyle, {
40
+ transition: `${parseInt(option.duration)}ms ${option.timingFunction} ${parseInt(option.delay)}ms`,
41
+ transitionProperty: `${property}`,
42
+ transformOrigin: option.transformOrigin
43
+ })
44
+ el.dynamicStyleQueue.push(dynamicStyle)
45
+ })
46
+ el.setAnimation = function () {
47
+ if (!el.dynamicStyleQueue.length) {
48
+ el.removeEventListener('transitionend', el.setAnimation, false)
49
+ return
50
+ }
51
+ const dynamicStyle = el.dynamicStyleQueue.shift()
52
+ Object.assign(el.style, dynamicStyle)
53
+ el.lastDynamicStyle = dynamicStyle
54
+ }
55
+ // 首次动画属性设置
56
+ setTimeout(el.setAnimation, 0)
57
+ // 在transitionend事件内设置动画样式
58
+ el.addEventListener('transitionend', el.setAnimation, false)
59
+ }
60
+ }
@@ -1,5 +1,7 @@
1
1
  import { isBrowser } from './env'
2
2
  import { hasOwn } from './utils'
3
+ import transRpxStyle from './transRpxStyle'
4
+ import animation from './animation'
3
5
 
4
6
  export default function processOption (
5
7
  option,
@@ -13,6 +15,7 @@ export default function processOption (
13
15
  componentGenerics,
14
16
  genericsInfo,
15
17
  mixin,
18
+ hasApp,
16
19
  Vue,
17
20
  VueRouter
18
21
  ) {
@@ -25,111 +28,9 @@ export default function processOption (
25
28
  }
26
29
  }
27
30
 
28
- Vue.directive('animation', (el, binding) => {
29
- const newActions = binding && binding.value && binding.value.actions
30
- if (el.actions === newActions) {
31
- Promise.resolve().then(() => {
32
- Object.assign(el.style, el.lastDynamicStyle)
33
- })
34
- return
35
- }
36
- el.actions = newActions
37
- if (typeof el.setAnimation === 'function') {
38
- el.removeEventListener('transitionend', el.setAnimation, false)
39
- el.setAnimation = undefined
40
- }
41
- el.dynamicStyleQueue = []
42
- el.lastDynamicStyle = undefined
43
- if (Array.isArray(newActions) && newActions.length) {
44
- newActions.forEach((item) => {
45
- const property = []
46
- const { animates, option } = item
47
- // 存储动画需要改变的样式属性
48
- const dynamicStyle = {
49
- transform: ''
50
- }
51
- animates.forEach((itemAnimation) => {
52
- switch (itemAnimation.type) {
53
- case 'style': {
54
- const [key, value] = itemAnimation.args
55
- dynamicStyle[key] = value
56
- property.push(key)
57
- break
58
- }
59
- default:
60
- dynamicStyle.transform += `${itemAnimation.type}(${itemAnimation.args}) `
61
- if (!property.includes('transform')) {
62
- property.push('transform')
63
- }
64
- }
65
- })
66
- Object.assign(dynamicStyle, {
67
- transition: `${parseInt(option.duration)}ms ${option.timingFunction} ${parseInt(option.delay)}ms`,
68
- transitionProperty: `${property}`,
69
- transformOrigin: option.transformOrigin
70
- })
71
- el.dynamicStyleQueue.push(dynamicStyle)
72
- })
73
- el.setAnimation = function () {
74
- if (!el.dynamicStyleQueue.length) {
75
- el.removeEventListener('transitionend', el.setAnimation, false)
76
- return
77
- }
78
- const dynamicStyle = el.dynamicStyleQueue.shift()
79
- Object.assign(el.style, dynamicStyle)
80
- el.lastDynamicStyle = dynamicStyle
81
- }
82
- // 首次动画属性设置
83
- setTimeout(el.setAnimation, 0)
84
- // 在transitionend事件内设置动画样式
85
- el.addEventListener('transitionend', el.setAnimation, false)
86
- }
87
- })
31
+ Vue.directive('animation', animation)
88
32
 
89
- Vue.filter('transRpxStyle', style => {
90
- const defaultTransRpxFn = function (match, $1) {
91
- const rpx2vwRatio = +(100 / 750).toFixed(8)
92
- return '' + ($1 * rpx2vwRatio) + 'vw'
93
- }
94
- const transRpxFn = global.__mpxTransRpxFn || defaultTransRpxFn
95
- const parsedStyleObj = {}
96
- const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
97
- const parseStyleText = (cssText) => {
98
- const listDelimiter = /;(?![^(]*\))/g
99
- const propertyDelimiter = /:(.+)/
100
- if (typeof cssText === 'string') {
101
- cssText.split(listDelimiter).forEach((item) => {
102
- if (item) {
103
- const tmp = item.split(propertyDelimiter)
104
- tmp.length > 1 && (parsedStyleObj[tmp[0].trim()] = tmp[1].trim())
105
- }
106
- })
107
- } else if (typeof cssText === 'object') {
108
- if (Array.isArray(cssText)) {
109
- cssText.forEach(cssItem => {
110
- parseStyleText(cssItem)
111
- })
112
- } else {
113
- Object.assign(parsedStyleObj, cssText)
114
- }
115
- }
116
- }
117
- const transRpxStyleFn = (val) => {
118
- if (typeof val === 'string' && val.indexOf('rpx') > 0) {
119
- return val.replace(rpxRegExpG, transRpxFn).replace(/"/g, '')
120
- }
121
- return val
122
- }
123
- if (style) {
124
- style.forEach(item => {
125
- parseStyleText(item)
126
- for (const key in parsedStyleObj) {
127
- parsedStyleObj[key] = transRpxStyleFn(parsedStyleObj[key])
128
- }
129
- })
130
- }
131
- return parsedStyleObj
132
- })
33
+ Vue.filter('transRpxStyle', transRpxStyle)
133
34
 
134
35
  const routes = []
135
36
 
@@ -308,7 +209,6 @@ export default function processOption (
308
209
  }
309
210
  if (currentPage) {
310
211
  currentPage.mpxPageStatus = 'hide'
311
- currentPage.onHide && currentPage.onHide()
312
212
  }
313
213
  } else {
314
214
  if (global.__mpxAppCbs && global.__mpxAppCbs.show) {
@@ -320,7 +220,6 @@ export default function processOption (
320
220
  }
321
221
  if (currentPage) {
322
222
  currentPage.mpxPageStatus = 'show'
323
- currentPage.onShow && currentPage.onShow()
324
223
  }
325
224
  }
326
225
  }
@@ -378,6 +277,10 @@ registered in parent context!`)
378
277
  if (ctorType === 'page') {
379
278
  option.__mpxPageConfig = Object.assign({}, global.__mpxPageConfig, pageConfig)
380
279
  }
280
+ if (!hasApp) {
281
+ option.directives = { animation }
282
+ option.filters = { transRpxStyle }
283
+ }
381
284
  }
382
285
 
383
286
  if (option.mixins) {
@@ -389,7 +292,6 @@ registered in parent context!`)
389
292
  if (outputPath) {
390
293
  option.componentPath = '/' + outputPath
391
294
  }
392
-
393
295
  return option
394
296
  }
395
297
 
@@ -0,0 +1,44 @@
1
+ module.exports = function (style) {
2
+ const defaultTransRpxFn = function (match, $1) {
3
+ const rpx2vwRatio = +(100 / 750).toFixed(8)
4
+ return '' + ($1 * rpx2vwRatio) + 'vw'
5
+ }
6
+ const transRpxFn = global.__mpxTransRpxFn || defaultTransRpxFn
7
+ const parsedStyleObj = {}
8
+ const rpxRegExpG = /\b(\d+(\.\d+)?)rpx\b/g
9
+ const parseStyleText = (cssText) => {
10
+ const listDelimiter = /;(?![^(]*\))/g
11
+ const propertyDelimiter = /:(.+)/
12
+ if (typeof cssText === 'string') {
13
+ cssText.split(listDelimiter).forEach((item) => {
14
+ if (item) {
15
+ const tmp = item.split(propertyDelimiter)
16
+ tmp.length > 1 && (parsedStyleObj[tmp[0].trim()] = tmp[1].trim())
17
+ }
18
+ })
19
+ } else if (typeof cssText === 'object') {
20
+ if (Array.isArray(cssText)) {
21
+ cssText.forEach(cssItem => {
22
+ parseStyleText(cssItem)
23
+ })
24
+ } else {
25
+ Object.assign(parsedStyleObj, cssText)
26
+ }
27
+ }
28
+ }
29
+ const transRpxStyleFn = (val) => {
30
+ if (typeof val === 'string' && val.indexOf('rpx') > 0) {
31
+ return val.replace(rpxRegExpG, transRpxFn).replace(/"/g, '')
32
+ }
33
+ return val
34
+ }
35
+ if (style) {
36
+ style.forEach(item => {
37
+ parseStyleText(item)
38
+ for (const key in parsedStyleObj) {
39
+ parsedStyleObj[key] = transRpxStyleFn(parsedStyleObj[key])
40
+ }
41
+ })
42
+ }
43
+ return parsedStyleObj
44
+ }
@@ -361,7 +361,7 @@ function compileScriptSetup (
361
361
  if (node.trailingComments && node.trailingComments.length > 0) {
362
362
  const lastCommentNode =
363
363
  node.trailingComments[node.trailingComments.length - 1]
364
- end = lastCommentNode.end + startOffset
364
+ end = lastCommentNode.end
365
365
  }
366
366
 
367
367
  // locate the end of whitespace between this statement and the next
@@ -3,14 +3,18 @@ const evalJSONJS = require('./eval-json-js')
3
3
  const resolve = require('./resolve')
4
4
  const async = require('async')
5
5
  const { JSON_JS_EXT } = require('./const')
6
+ const path = require('path')
6
7
 
7
- module.exports = function getJSONContent (json, loaderContext, callback) {
8
+ module.exports = function getJSONContent (json, filename, loaderContext, callback) {
8
9
  if (!loaderContext._compiler) return callback(null, '{}')
9
10
  const fs = loaderContext._compiler.inputFileSystem
11
+ filename = filename || loaderContext.resourcePath
12
+ const context = path.dirname(filename)
13
+
10
14
  async.waterfall([
11
15
  (callback) => {
12
16
  if (json.src) {
13
- resolve(loaderContext.context, json.src, loaderContext, (err, result) => {
17
+ resolve(context, json.src, loaderContext, (err, result) => {
14
18
  if (err) return callback(err)
15
19
  const { rawResourcePath: resourcePath } = parseRequest(result)
16
20
  fs.readFile(resourcePath, (err, content) => {
@@ -27,7 +31,7 @@ module.exports = function getJSONContent (json, loaderContext, callback) {
27
31
  callback(null, {
28
32
  content: json.content,
29
33
  useJSONJS: json.useJSONJS,
30
- filename: loaderContext.resourcePath
34
+ filename
31
35
  })
32
36
  }
33
37
  },
@@ -139,7 +139,7 @@ module.exports = function (json, {
139
139
  mode,
140
140
  env
141
141
  })
142
- getJSONContent(parts.json || {}, loaderContext, (err, content) => {
142
+ getJSONContent(parts.json || {}, result, loaderContext, (err, content) => {
143
143
  callback(err, result, content)
144
144
  })
145
145
  } else {
@@ -263,9 +263,7 @@ module.exports = function (json, {
263
263
  if (components) {
264
264
  async.eachOf(components, (component, name, callback) => {
265
265
  processComponent(component, context, {}, (err, { resource, outputPath } = {}) => {
266
- if (err === RESOLVE_IGNORED_ERR) {
267
- return callback()
268
- }
266
+ if (err) return callback(err === RESOLVE_IGNORED_ERR ? null : err)
269
267
  const { resourcePath, queryObj } = parseRequest(resource)
270
268
  componentsMap[resourcePath] = outputPath
271
269
  loaderContext._module && loaderContext._module.addPresentationalDependency(new RecordResourceMapDependency(resourcePath, 'component', outputPath))
@@ -49,9 +49,9 @@ module.exports = function (script, {
49
49
  const {
50
50
  i18n,
51
51
  projectRoot,
52
- webConfig
52
+ webConfig,
53
+ appInfo
53
54
  } = loaderContext.getMpx()
54
-
55
55
  const { getRequire } = createHelpers(loaderContext)
56
56
  const tabBar = jsonConfig.tabBar
57
57
 
@@ -153,6 +153,10 @@ module.exports = function (script, {
153
153
  \n`
154
154
  }
155
155
  }
156
+ let hasApp = true
157
+ if (!appInfo.name) {
158
+ hasApp = false
159
+ }
156
160
  // 注入wxs模块
157
161
  content += ' const wxsModules = {}\n'
158
162
  if (wxsModuleMap) {
@@ -239,7 +243,6 @@ module.exports = function (script, {
239
243
  // @ts-ignore
240
244
  global.__tabBarPagesMap = ${shallowStringify(tabBarPagesMap)}\n`
241
245
  }
242
-
243
246
  // 配置平台转换通过createFactory在core中convertor中定义和进行
244
247
  // 通过processOption进行组件注册和路由注入
245
248
  content += ` export default processOption(
@@ -255,7 +258,8 @@ module.exports = function (script, {
255
258
  ${JSON.stringify(tabBarMap)},
256
259
  ${JSON.stringify(componentGenerics)},
257
260
  ${JSON.stringify(genericsInfo)},
258
- getWxsMixin(wxsModules)`
261
+ getWxsMixin(wxsModules),
262
+ ${hasApp}`
259
263
  if (ctorType === 'app') {
260
264
  content += `,
261
265
  Vue,
@@ -0,0 +1,29 @@
1
+ module.exports = class CssSyntaxError extends Error {
2
+ constructor (error) {
3
+ super(error)
4
+
5
+ const { reason, line, column, file } = error
6
+
7
+ this.name = 'CssSyntaxError'
8
+
9
+ // Based on https://github.com/postcss/postcss/blob/master/lib/css-syntax-error.es6#L132
10
+ // We don't need `plugin` and `file` properties.
11
+ this.message = `${this.name}\n\n`
12
+
13
+ if (typeof line !== 'undefined') {
14
+ this.message += `(${line}:${column}) `
15
+ }
16
+
17
+ this.message += file ? `${file} ` : '<css input> '
18
+ this.message += `${reason}`
19
+
20
+ const code = error.showSourceCode()
21
+
22
+ if (code) {
23
+ this.message += `\n\n${code}\n`
24
+ }
25
+
26
+ // We don't need stack https://github.com/postcss/postcss/blob/master/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
27
+ this.stack = false
28
+ }
29
+ }
@@ -0,0 +1,22 @@
1
+ module.exports = class Warning extends Error {
2
+ constructor (warning) {
3
+ super(warning)
4
+
5
+ const { text, line, column } = warning
6
+
7
+ this.name = 'Warning'
8
+
9
+ // Based on https://github.com/postcss/postcss/blob/master/lib/warning.es6#L74
10
+ // We don't need `plugin` properties.
11
+ this.message = `${this.name}\n\n`
12
+
13
+ if (typeof line !== 'undefined') {
14
+ this.message += `(${line}:${column}) `
15
+ }
16
+
17
+ this.message += `${text}`
18
+
19
+ // We don't need stack https://github.com/postcss/postcss/blob/master/docs/guidelines/runner.md#31-dont-show-js-stack-for-csssyntaxerror
20
+ this.stack = false
21
+ }
22
+ }
@@ -0,0 +1,5 @@
1
+ const loader = require('./loader')
2
+
3
+ module.exports = loader
4
+
5
+ module.exports.defaultGetLocalIdent = require('./utils').defaultGetLocalIdent