@mpxjs/webpack-plugin 2.8.43 → 2.8.45

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
@@ -1453,8 +1453,8 @@ try {
1453
1453
  })
1454
1454
 
1455
1455
  const typeLoaderProcessInfo = {
1456
- styles: ['css-loader', wxssLoaderPath, styleCompilerPath],
1457
- template: ['html-loader', wxmlLoaderPath, templateCompilerPath]
1456
+ styles: ['node_modules/css-loader', wxssLoaderPath, styleCompilerPath],
1457
+ template: ['node_modules/html-loader', wxmlLoaderPath, templateCompilerPath]
1458
1458
  }
1459
1459
 
1460
1460
  // 应用过rules后,注入mpx相关资源编译loader
@@ -1517,15 +1517,15 @@ try {
1517
1517
  if (mpx.mode === 'web') {
1518
1518
  const mpxStyleOptions = queryObj.mpxStyleOptions
1519
1519
  const firstLoader = loaders[0] ? toPosix(loaders[0].loader) : ''
1520
- const isPitcherRequest = firstLoader.includes('vue-loader/lib/loaders/pitcher')
1520
+ const isPitcherRequest = firstLoader.includes('node_modules/vue-loader/lib/loaders/pitcher')
1521
1521
  let cssLoaderIndex = -1
1522
1522
  let vueStyleLoaderIndex = -1
1523
1523
  let mpxStyleLoaderIndex = -1
1524
1524
  loaders.forEach((loader, index) => {
1525
1525
  const currentLoader = toPosix(loader.loader)
1526
- if (currentLoader.includes('css-loader') && cssLoaderIndex === -1) {
1526
+ if (currentLoader.includes('node_modules/css-loader') && cssLoaderIndex === -1) {
1527
1527
  cssLoaderIndex = index
1528
- } else if (currentLoader.includes('vue-loader/lib/loaders/stylePostLoader') && vueStyleLoaderIndex === -1) {
1528
+ } else if (currentLoader.includes('node_modules/vue-loader/lib/loaders/stylePostLoader') && vueStyleLoaderIndex === -1) {
1529
1529
  vueStyleLoaderIndex = index
1530
1530
  } else if (currentLoader.includes(styleCompilerPath) && mpxStyleLoaderIndex === -1) {
1531
1531
  mpxStyleLoaderIndex = index
@@ -59,6 +59,7 @@ export default function processOption (
59
59
  global.__mpxRouter.stack = []
60
60
  global.__mpxRouter.needCache = null
61
61
  global.__mpxRouter.needRemove = []
62
+ global.__mpxRouter.eventChannelMap = {}
62
63
  // 处理reLaunch中传递的url并非首页时的replace逻辑
63
64
  global.__mpxRouter.beforeEach(function (to, from, next) {
64
65
  let action = global.__mpxRouter.__mpxAction
@@ -97,24 +98,15 @@ export default function processOption (
97
98
  })
98
99
  }
99
100
  } else {
100
- let methods = ''
101
- switch (action.type) {
102
- case 'to':
103
- methods = 'navigateTo'
104
- break
105
- case 'redirect':
106
- methods = 'redirectTo'
107
- break
108
- case 'back':
109
- methods = 'navigateBack'
110
- break
111
- case 'reLaunch':
112
- methods = 'reLaunch'
113
- break
114
- default:
115
- methods = 'navigateTo'
101
+ const typeMethodMap = {
102
+ to: 'navigateTo',
103
+ redirect: 'redirectTo',
104
+ back: 'navigateBack',
105
+ switch: 'switchTab',
106
+ reLaunch: 'reLaunch'
116
107
  }
117
- throw new Error(`${methods}:fail page "${to.path}" is not found`)
108
+ const method = typeMethodMap[action.type]
109
+ throw new Error(`${method}:fail page "${to.path}" is not found`)
118
110
  }
119
111
  }
120
112
 
@@ -126,6 +118,7 @@ export default function processOption (
126
118
  case 'to':
127
119
  stack.push(insertItem)
128
120
  global.__mpxRouter.needCache = insertItem
121
+ if (action.eventChannel) global.__mpxRouter.eventChannelMap[to.path.slice(1)] = action.eventChannel
129
122
  break
130
123
  case 'back':
131
124
  global.__mpxRouter.needRemove = stack.splice(stack.length - action.delta, action.delta)
@@ -1,7 +1,7 @@
1
1
  module.exports = (loaders, loaderIndex) => {
2
2
  for (let i = loaderIndex; i >= 0; i--) {
3
3
  const currentLoader = loaders[i]
4
- if (currentLoader.path.endsWith('ts-loader/dist/stringify-loader.js')) {
4
+ if (currentLoader.path.endsWith('node_modules/ts-loader/dist/stringify-loader.js')) {
5
5
  return i
6
6
  }
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.43",
3
+ "version": "2.8.45",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"
@@ -82,5 +82,5 @@
82
82
  "engines": {
83
83
  "node": ">=14.14.0"
84
84
  },
85
- "gitHead": "f1066822d83e958f6266218c51c21b2ebb2ad04b"
85
+ "gitHead": "b60613d3d5bfd85c7c7b28b81afbf4494c8b2c6f"
86
86
  }
@@ -1,52 +0,0 @@
1
- const camelCase = require('lodash.camelcase')
2
-
3
- function dashesCamelCase (str) {
4
- return str.replace(/-+(\w)/g, function (match, firstLetter) {
5
- return firstLetter.toUpperCase()
6
- })
7
- }
8
-
9
- module.exports = function compileExports (result, importItemMatcher, camelCaseKeys) {
10
- if (!Object.keys(result.exports).length) {
11
- return ''
12
- }
13
-
14
- const exportJs = Object.keys(result.exports).reduce(function (res, key) {
15
- let valueAsString = JSON.stringify(result.exports[key])
16
- valueAsString = valueAsString.replace(result.importItemRegExpG, importItemMatcher)
17
-
18
- function addEntry (k) {
19
- res.push('\t' + JSON.stringify(k) + ': ' + valueAsString)
20
- }
21
-
22
- let targetKey
23
- switch (camelCaseKeys) {
24
- case true:
25
- addEntry(key)
26
- targetKey = camelCase(key)
27
- if (targetKey !== key) {
28
- addEntry(targetKey)
29
- }
30
- break
31
- case 'dashes':
32
- addEntry(key)
33
- targetKey = dashesCamelCase(key)
34
- if (targetKey !== key) {
35
- addEntry(targetKey)
36
- }
37
- break
38
- case 'only':
39
- addEntry(camelCase(key))
40
- break
41
- case 'dashesOnly':
42
- addEntry(dashesCamelCase(key))
43
- break
44
- default:
45
- addEntry(key)
46
- break
47
- }
48
- return res
49
- }, []).join(',\n')
50
-
51
- return '{\n' + exportJs + '\n}'
52
- }
@@ -1,36 +0,0 @@
1
- module.exports = function createResolver (alias) {
2
- if (typeof alias !== 'object' || Array.isArray(alias)) {
3
- return function (url) {
4
- return url
5
- }
6
- }
7
-
8
- alias = Object.keys(alias).map(function (key) {
9
- let onlyModule = false
10
- let obj = alias[key]
11
- if (/\$$/.test(key)) {
12
- onlyModule = true
13
- key = key.substr(0, key.length - 1)
14
- }
15
- if (typeof obj === 'string') {
16
- obj = {
17
- alias: obj
18
- }
19
- }
20
- obj = Object.assign({
21
- name: key,
22
- onlyModule: onlyModule
23
- }, obj)
24
- return obj
25
- })
26
-
27
- return function (url) {
28
- alias.forEach(function (obj) {
29
- const name = obj.name
30
- if (url === name || (!obj.onlyModule && url.startsWith(name + '/'))) {
31
- url = obj.alias + url.substr(name.length)
32
- }
33
- })
34
- return url
35
- }
36
- }
@@ -1,79 +0,0 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- Modified by @hiyuki
5
- */
6
- // css base code, injected by the css-loader
7
- module.exports = function (useSourceMap) {
8
- const list = []
9
-
10
- // return the list of modules as css string
11
- list.toString = function toString () {
12
- return this.map(function (item) {
13
- const content = cssWithMappingToString(item, useSourceMap)
14
- if (item[2]) {
15
- return '@media ' + item[2] + '{' + content + '}'
16
- } else {
17
- return content
18
- }
19
- }).join('')
20
- }
21
-
22
- // import a list of modules into the list
23
- list.i = function (modules, mediaQuery) {
24
- if (typeof modules === 'string') {
25
- modules = [[null, modules, '']]
26
- }
27
- const alreadyImportedModules = {}
28
- for (let i = 0; i < this.length; i++) {
29
- const id = this[i][0]
30
- if (typeof id === 'number') {
31
- alreadyImportedModules[id] = true
32
- }
33
- }
34
- for (let i = 0; i < modules.length; i++) {
35
- const item = modules[i]
36
- // skip already imported module
37
- // this implementation is not 100% perfect for weird media query combinations
38
- // when a module is imported multiple times with different media queries.
39
- // I hope this will never occur (Hey this way we have smaller bundles)
40
- if (typeof item[0] !== 'number' || !alreadyImportedModules[item[0]]) {
41
- if (mediaQuery && !item[2]) {
42
- item[2] = mediaQuery
43
- } else if (mediaQuery) {
44
- item[2] = '(' + item[2] + ') and (' + mediaQuery + ')'
45
- }
46
- list.push(item)
47
- }
48
- }
49
- }
50
- return list
51
- }
52
-
53
- function cssWithMappingToString (item, useSourceMap) {
54
- const content = item[1] || ''
55
- const cssMapping = item[3]
56
- if (!cssMapping) {
57
- return content
58
- }
59
-
60
- if (useSourceMap && typeof btoa === 'function') {
61
- const sourceMapping = toComment(cssMapping)
62
- const sourceURLs = cssMapping.sources.map(function (source) {
63
- return '/*# sourceURL=' + cssMapping.sourceRoot + source + ' */'
64
- })
65
-
66
- return [content].concat(sourceURLs).concat([sourceMapping]).join('\n')
67
- }
68
-
69
- return [content].join('\n')
70
- }
71
-
72
- // Adapted from convert-source-map (MIT)
73
- function toComment (sourceMap) {
74
- // eslint-disable-next-line no-undef
75
- const base64 = btoa(unescape(encodeURIComponent(JSON.stringify(sourceMap))))
76
- const data = 'sourceMappingURL=data:application/json;charset=utf-8;base64,' + base64
77
-
78
- return '/*# ' + data + ' */'
79
- }
@@ -1,25 +0,0 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- Modified by @hiyuki
5
- */
6
- const loaderUtils = require('loader-utils')
7
- const path = require('path')
8
-
9
- module.exports = function getLocalIdent (loaderContext, localIdentName, localName, options) {
10
- if (!options.context) {
11
- if (loaderContext.rootContext) {
12
- options.context = loaderContext.rootContext
13
- } else if (loaderContext.options && typeof loaderContext.options.context === 'string') {
14
- options.context = loaderContext.options.context
15
- } else {
16
- options.context = loaderContext.context
17
- }
18
- }
19
- const request = path.relative(options.context, loaderContext.resourcePath)
20
- options.content = options.hashPrefix + request + '+' + localName
21
- localIdentName = localIdentName.replace(/\[local\]/gi, localName)
22
- const hash = loaderUtils.interpolateName(loaderContext, localIdentName, options)
23
- /* eslint-disable prefer-regex-literals */
24
- return hash.replace(new RegExp('[^a-zA-Z0-9\\-_\u00A0-\uFFFF]', 'g'), '-').replace(/^((-?[0-9])|--)/, '_$1')
25
- }
@@ -1,44 +0,0 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- Modified by @hiyuki
5
- */
6
- const loaderUtils = require('loader-utils')
7
- const processCss = require('./processCss')
8
- const compileExports = require('./compile-exports')
9
- const createResolver = require('./createResolver')
10
-
11
- module.exports = function (content) {
12
- if (this.cacheable) this.cacheable()
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
-
19
- processCss(content, null, {
20
- mode: moduleMode ? 'local' : 'global',
21
- query: query,
22
- minimize: this.minimize,
23
- loaderContext: this,
24
- resolve: resolve
25
- }, function (err, result) {
26
- if (err) return callback(err)
27
-
28
- function importItemMatcher (item) {
29
- const match = result.importItemRegExp.exec(item)
30
- const idx = +match[1]
31
- const importItem = result.importItems[idx]
32
- const importUrl = importItem.url
33
- return '" + require(' + loaderUtils.stringifyRequest(this, importUrl) + ')' +
34
- '[' + JSON.stringify(importItem.export) + '] + "'
35
- }
36
-
37
- let exportJs = compileExports(result, importItemMatcher.bind(this), camelCaseKeys)
38
- if (exportJs) {
39
- exportJs = 'module.exports = ' + exportJs + ';'
40
- }
41
-
42
- callback(null, exportJs)
43
- }.bind(this))
44
- }
@@ -1,274 +0,0 @@
1
- /*
2
- MIT License http://www.opensource.org/licenses/mit-license.php
3
- Author Tobias Koppers @sokra
4
- Modified by @hiyuki
5
- */
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
-
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
21
-
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
- }
48
-
49
- if (options.import) {
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) {
59
- return
60
- }
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)
66
- }
67
-
68
- importItems.push({
69
- url: url,
70
- mediaQuery: mediaQuery
71
- })
72
- rule.remove()
73
- })
74
- }
75
-
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
- })
86
- })
87
- })
88
-
89
- Object.keys(exports).forEach(function (exportName) {
90
- exports[exportName] = replaceImportsInString(exports[exportName])
91
- })
92
-
93
- function isAlias (url) {
94
- // Handle alias starting by / and root disabled
95
- return url !== options.resolve(url)
96
- }
97
-
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
- }
113
- case 'url':
114
- if (options.url && item.url.replace(/\s/g, '').length && !/^#/.test(item.url) && (isAlias(item.url) || isUrlRequest(item.url, options.root))) {
115
- // Strip quotes, they will be re-added if the module needs them
116
- item.stringType = ''
117
- delete item.innerSpacingBefore
118
- delete item.innerSpacingAfter
119
- const url = item.url
120
- item.url = '___CSS_LOADER_URL___' + urlItems.length + '___'
121
- urlItems.push({
122
- url: url
123
- })
124
- }
125
- break
126
- }
127
- }
128
-
129
- css.walkDecls(function (decl) {
130
- const values = Tokenizer.parseValues(decl.value)
131
- values.nodes.forEach(function (value) {
132
- value.nodes.forEach(processNode)
133
- })
134
- decl.value = Tokenizer.stringifyValues(values)
135
- })
136
- css.walkAtRules(function (atrule) {
137
- if (typeof atrule.params === 'string') {
138
- atrule.params = replaceImportsInString(atrule.params)
139
- }
140
- })
141
-
142
- options.importItems = importItems
143
- options.urlItems = urlItems
144
- options.exports = exports
145
- }
146
- }
147
- }
148
-
149
- module.exports = function processCss (inputSource, inputMap, options, callback) {
150
- const query = options.query
151
- const root = query.root && query.root.length > 0 ? query.root.replace(/\/$/, '') : query.root
152
- const context = query.context
153
- const localIdentName = query.localIdentName || '[hash:base64]'
154
- const localIdentRegExp = query.localIdentRegExp
155
- const forceMinimize = query.minimize
156
- const minimize = typeof forceMinimize !== 'undefined' ? !!forceMinimize : options.minimize
157
-
158
- const customGetLocalIdent = query.getLocalIdent || getLocalIdent
159
-
160
- const parserOptions = {
161
- root: root,
162
- mode: options.mode,
163
- url: query.url !== false,
164
- import: query.import !== false,
165
- resolve: options.resolve
166
- }
167
-
168
- const pipeline = postcss([
169
- modulesValues,
170
- localByDefault({
171
- mode: options.mode,
172
- rewriteUrl: function (global, url) {
173
- if (parserOptions.url) {
174
- url = url.trim()
175
-
176
- if (!url.replace(/\s/g, '').length || !isUrlRequest(url, root)) {
177
- return url
178
- }
179
- if (global) {
180
- return loaderUtils.urlToRequest(url, root)
181
- }
182
- }
183
- return url
184
- }
185
- }),
186
- extractImports(),
187
- modulesScope({
188
- generateScopedName: function generateScopedName (exportName) {
189
- return customGetLocalIdent(options.loaderContext, localIdentName, exportName, {
190
- regExp: localIdentRegExp,
191
- hashPrefix: query.hashPrefix || '',
192
- context: context
193
- })
194
- }
195
- }),
196
- parserPlugin(parserOptions)
197
- ])
198
-
199
- if (minimize) {
200
- const cssnano = require('cssnano')
201
- const minimizeOptions = assign({}, query.minimize);
202
- ['zindex', 'normalizeUrl', 'discardUnused', 'mergeIdents', 'reduceIdents', 'autoprefixer', 'svgo'].forEach(function (name) {
203
- if (typeof minimizeOptions[name] === 'undefined') {
204
- minimizeOptions[name] = false
205
- }
206
- })
207
- pipeline.use(cssnano(minimizeOptions))
208
- }
209
-
210
- pipeline.process(inputSource, {
211
- // we need a prefix to avoid path rewriting of PostCSS
212
- from: '/css-loader!' + options.from,
213
- to: options.to,
214
- map: options.sourceMap
215
- ? {
216
- prev: inputMap,
217
- sourcesContent: true,
218
- inline: false,
219
- annotation: false
220
- }
221
- : null
222
- }).then(function (result) {
223
- callback(null, {
224
- source: result.css,
225
- map: result.map && result.map.toJSON(),
226
- exports: parserOptions.exports,
227
- importItems: parserOptions.importItems,
228
- importItemRegExpG: /___CSS_LOADER_IMPORT___([0-9]+)___/g,
229
- importItemRegExp: /___CSS_LOADER_IMPORT___([0-9]+)___/,
230
- urlItems: parserOptions.urlItems,
231
- urlItemRegExpG: /___CSS_LOADER_URL___([0-9]+)___/g,
232
- urlItemRegExp: /___CSS_LOADER_URL___([0-9]+)___/
233
- })
234
- }).catch(function (err) {
235
- if (err.name === 'CssSyntaxError') {
236
- const wrappedError = new CSSLoaderError(
237
- 'Syntax Error',
238
- err.reason,
239
- err.line != null && err.column != null
240
- ? { line: err.line, column: err.column }
241
- : null,
242
- err.input.source
243
- )
244
- callback(wrappedError)
245
- } else {
246
- callback(err)
247
- }
248
- })
249
- }
250
-
251
- function formatMessage (message, loc, source) {
252
- let formatted = message
253
- if (loc) {
254
- formatted = formatted +
255
- ' (' + loc.line + ':' + loc.column + ')'
256
- }
257
- if (loc && source) {
258
- formatted = formatted +
259
- '\n\n' + formatCodeFrame(source, loc.line, loc.column) + '\n'
260
- }
261
- return formatted
262
- }
263
-
264
- function CSSLoaderError (name, message, loc, source, error) {
265
- Error.call(this)
266
- Error.captureStackTrace(this, CSSLoaderError)
267
- this.name = name
268
- this.error = error
269
- this.message = formatMessage(message, loc, source)
270
- this.message = formatMessage(message, loc, source)
271
- }
272
-
273
- CSSLoaderError.prototype = Object.create(Error.prototype)
274
- CSSLoaderError.prototype.constructor = CSSLoaderError