@mpxjs/webpack-plugin 2.8.13 → 2.8.16

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.
@@ -86,13 +86,42 @@ module.exports = function (css, map) {
86
86
  if (mode === 'ali' && isApp) {
87
87
  result.css += `\n.${MPX_ROOT_VIEW} { display: initial }\n.${MPX_APP_MODULE_ID} { line-height: normal }`
88
88
  }
89
- if (result.messages) {
90
- result.messages.forEach(({ type, file }) => {
91
- if (type === 'dependency') {
92
- this.addDependency(file)
93
- }
94
- })
89
+
90
+ for (const warning of result.warnings()) {
91
+ this.emitWarning(warning)
95
92
  }
93
+
94
+ // todo 后续考虑直接使用postcss-loader来处理postcss
95
+ for (const message of result.messages) {
96
+ // eslint-disable-next-line default-case
97
+ switch (message.type) {
98
+ case 'dependency':
99
+ this.addDependency(message.file)
100
+ break
101
+
102
+ case 'build-dependency':
103
+ this.addBuildDependency(message.file)
104
+ break
105
+
106
+ case 'missing-dependency':
107
+ this.addMissingDependency(message.file)
108
+ break
109
+
110
+ case 'context-dependency':
111
+ this.addContextDependency(message.file)
112
+ break
113
+
114
+ case 'dir-dependency':
115
+ this.addContextDependency(message.dir)
116
+ break
117
+
118
+ case 'asset':
119
+ if (message.content && message.file) {
120
+ this.emitFile(message.file, message.content, message.sourceMap, message.info)
121
+ }
122
+ }
123
+ }
124
+
96
125
  const map = result.map && result.map.toJSON()
97
126
  cb(null, result.css, map)
98
127
  return null // silence bluebird warning
@@ -45,8 +45,7 @@ module.exports = async function loader (content, map, meta) {
45
45
  let options
46
46
 
47
47
  try {
48
- options = normalizeOptions(rawOptions, this)
49
- options = Object.assign({}, options, { sourceMap, root, externals })
48
+ options = normalizeOptions(Object.assign({}, rawOptions, { sourceMap }), this)
50
49
  } catch (error) {
51
50
  callback(error)
52
51
 
@@ -60,7 +59,7 @@ module.exports = async function loader (content, map, meta) {
60
59
  plugins.push(...getModulesPlugins(options, this))
61
60
  }
62
61
 
63
- let importPluginImports = []
62
+ const importPluginImports = []
64
63
  const importPluginApi = []
65
64
 
66
65
  let isSupportAbsoluteURL = false
@@ -78,22 +77,26 @@ module.exports = async function loader (content, map, meta) {
78
77
  options.esModule && Boolean('fsStartTime' in this._compiler)
79
78
 
80
79
  if (shouldUseImportPlugin(options)) {
80
+ const { getRequestString } = createHelpers(this)
81
81
  plugins.push(
82
82
  importParser({
83
83
  isSupportAbsoluteURL: false,
84
84
  isSupportDataURL: false,
85
+ externals,
86
+ root,
85
87
  isCSSStyleSheet: options.exportType === 'css-style-sheet',
86
88
  loaderContext: this,
87
89
  imports: importPluginImports,
88
90
  api: importPluginApi,
89
91
  filter: options.import.filter,
90
- urlHandler: (url) =>
91
- stringifyRequest(
92
- this,
93
- combineRequests(getPreRequester(this)(options.importLoaders), url)
94
- ),
95
- externals: options.externals,
96
- root: options.root
92
+ urlHandler: (url) => {
93
+ url = combineRequests(getPreRequester(this)(options.importLoaders), url)
94
+ return getRequestString('styles', { src: url }, {
95
+ isStatic: true,
96
+ issuerResource: this.resource,
97
+ fromImport: true
98
+ })
99
+ }
97
100
  })
98
101
  )
99
102
  }
@@ -107,6 +110,8 @@ module.exports = async function loader (content, map, meta) {
107
110
  urlParser({
108
111
  isSupportAbsoluteURL,
109
112
  isSupportDataURL,
113
+ externals,
114
+ root,
110
115
  imports: urlPluginImports,
111
116
  replacements,
112
117
  context: this.context,
@@ -205,22 +210,6 @@ module.exports = async function loader (content, map, meta) {
205
210
  this.emitWarning(new Warning(warning))
206
211
  }
207
212
 
208
- const { getRequestString } = createHelpers(this)
209
-
210
- // 符合css后缀名的文件经过mpx处理后会带上相应的后缀防止 WebPack 的默认解析规则,后续 require/import 相应路径时,导出的不是一段 css 代码了,事实上是一个文件路径。
211
- importPluginImports = importPluginImports.map((importItem, index) => {
212
- const splittedUrl = importItem.url.slice(1, -1)
213
- const requestString = getRequestString('styles', { src: splittedUrl }, {
214
- isStatic: true,
215
- issuerResource: this.resource,
216
- fromImport: true
217
- }, index)
218
- return {
219
- ...importItem,
220
- url: requestString
221
- }
222
- })
223
-
224
213
  const imports = []
225
214
  .concat(icssPluginImports.sort(sort))
226
215
  .concat(importPluginImports.sort())
@@ -46,7 +46,7 @@ function parseNode (atRule, key, options) {
46
46
  // Nodes do not exists - `@import url('http://') :root {}`
47
47
  if (atRule.nodes) {
48
48
  const error = new Error(
49
- "It looks like you didn't end your @import statement correctly. Child nodes are attached to it."
49
+ 'It looks like you didn\'t end your @import statement correctly. Child nodes are attached to it.'
50
50
  )
51
51
 
52
52
  error.node = atRule
@@ -215,7 +215,7 @@ const plugin = (options = {}) => {
215
215
  options.loaderContext.emitError(
216
216
  new Error(
217
217
  atRule.error(
218
- "'@import' rules are not allowed here and will not be processed"
218
+ '\'@import\' rules are not allowed here and will not be processed'
219
219
  ).message
220
220
  )
221
221
  )
@@ -223,7 +223,7 @@ const plugin = (options = {}) => {
223
223
  return
224
224
  }
225
225
 
226
- const { isSupportDataURL, isSupportAbsoluteURL } = options
226
+ const { isSupportDataURL, isSupportAbsoluteURL, externals, root } = options
227
227
 
228
228
  let parsedAtRule
229
229
 
@@ -231,7 +231,8 @@ const plugin = (options = {}) => {
231
231
  parsedAtRule = parseNode(atRule, 'params', {
232
232
  isSupportAbsoluteURL,
233
233
  isSupportDataURL,
234
- externals: options.externals
234
+ externals,
235
+ root
235
236
  })
236
237
  } catch (error) {
237
238
  result.warn(error.message, { node: error.node })
@@ -296,10 +296,12 @@ const plugin = (options = {}) => {
296
296
 
297
297
  return {
298
298
  Declaration (declaration) {
299
- const { isSupportDataURL, isSupportAbsoluteURL } = options
299
+ const { isSupportDataURL, isSupportAbsoluteURL, externals, root } = options
300
300
  const parsedURL = parseDeclaration(declaration, 'value', result, {
301
301
  isSupportDataURL,
302
- isSupportAbsoluteURL
302
+ isSupportAbsoluteURL,
303
+ externals,
304
+ root
303
305
  })
304
306
 
305
307
  if (!parsedURL) {
package/lib/wxss/utils.js CHANGED
@@ -317,7 +317,7 @@ function escapeLocalIdent (localident) {
317
317
  // TODO simplify in the next major release
318
318
  return escape(
319
319
  localident
320
- // For `[hash]` placeholder
320
+ // For `[hash]` placeholder
321
321
  .replace(/^((-?[0-9])|--)/, '_$1')
322
322
  .replace(filenameReservedRegex, '-')
323
323
  .replace(reControlChars, '-')
@@ -389,7 +389,7 @@ function defaultGetLocalIdent (
389
389
  hash.update(Buffer.from(options.content, 'utf8'))
390
390
 
391
391
  localIdentHash = (localIdentHash + hash.digest(hashDigest))
392
- // Remove all leading digits
392
+ // Remove all leading digits
393
393
  .replace(/^\d+/, '')
394
394
  // Replace all slashes with underscores (same as in base64url)
395
395
  .replace(/\//g, '_')
@@ -652,13 +652,13 @@ function getModulesOptions (rawOptions, exportType, loaderContext) {
652
652
  if (needNamedExport) {
653
653
  if (rawOptions.esModule === false) {
654
654
  throw new Error(
655
- "The 'exportType' option with the 'css-style-sheet' or 'string' value requires the 'esModules' option to be enabled"
655
+ 'The \'exportType\' option with the \'css-style-sheet\' or \'string\' value requires the \'esModules\' option to be enabled'
656
656
  )
657
657
  }
658
658
 
659
659
  if (modulesOptions.namedExport === false) {
660
660
  throw new Error(
661
- "The 'exportType' option with the 'css-style-sheet' or 'string' value requires the 'modules.namedExport' option to be enabled"
661
+ 'The \'exportType\' option with the \'css-style-sheet\' or \'string\' value requires the \'modules.namedExport\' option to be enabled'
662
662
  )
663
663
  }
664
664
  }
@@ -666,7 +666,7 @@ function getModulesOptions (rawOptions, exportType, loaderContext) {
666
666
  if (modulesOptions.namedExport === true) {
667
667
  if (rawOptions.esModule === false) {
668
668
  throw new Error(
669
- "The 'modules.namedExport' option requires the 'esModules' option to be enabled"
669
+ 'The \'modules.namedExport\' option requires the \'esModules\' option to be enabled'
670
670
  )
671
671
  }
672
672
 
@@ -896,18 +896,18 @@ function getPreRequester ({ loaders, loaderIndex }) {
896
896
  return cache[number]
897
897
  }
898
898
 
899
- if (number === false) {
900
- cache[number] = ''
901
- } else {
899
+ if (typeof number === 'number') {
902
900
  const loadersRequest = loaders
903
901
  .slice(
904
902
  loaderIndex,
905
- loaderIndex + 1 + (typeof number !== 'number' ? 0 : number + 1) // 与css-loader 不同,需要增加 1,因为 css 文件会经过 style-compiler loader 进行处理。
903
+ loaderIndex + 1 + number
906
904
  )
907
905
  .map((x) => x.request)
908
906
  .join('!')
909
907
 
910
908
  cache[number] = `-!${loadersRequest}!`
909
+ } else {
910
+ cache[number] = ''
911
911
  }
912
912
 
913
913
  return cache[number]
@@ -924,7 +924,7 @@ function getImportCode (imports, options) {
924
924
  if (icss && options.modules.namedExport) {
925
925
  code += `import ${
926
926
  options.modules.exportOnlyLocals ? '' : `${importName}, `
927
- }* as ${importName}_NAMED___ from ${url};\n`
927
+ }* as ${importName}_NAMED___ from ${url};\n`
928
928
  } else {
929
929
  code +=
930
930
  type === 'url'
@@ -1039,7 +1039,7 @@ function getModuleCode (
1039
1039
  options.sourceMap
1040
1040
  ? '___CSS_LOADER_API_SOURCEMAP_IMPORT___'
1041
1041
  : '___CSS_LOADER_API_NO_SOURCEMAP_IMPORT___'
1042
- });\n`
1042
+ });\n`
1043
1043
 
1044
1044
  for (const item of api) {
1045
1045
  const { url, layer, supports, media, dedupe } = item
@@ -1066,10 +1066,10 @@ function getModuleCode (
1066
1066
  code = code.replace(new RegExp(replacementName, 'g'), () =>
1067
1067
  options.modules.namedExport
1068
1068
  ? `" + ${importName}_NAMED___[${JSON.stringify(
1069
- getValidLocalName(
1070
- localName,
1071
- options.modules.exportLocalsConvention
1072
- )
1069
+ getValidLocalName(
1070
+ localName,
1071
+ options.modules.exportLocalsConvention
1072
+ )
1073
1073
  )}] + "`
1074
1074
  : `" + ${importName}.locals[${JSON.stringify(localName)}] + "`
1075
1075
  )
@@ -1172,7 +1172,7 @@ function getExportCode (exports, replacements, icssPluginUsed, options) {
1172
1172
  ? localsCode
1173
1173
  : `${
1174
1174
  options.esModule ? 'export default' : 'module.exports ='
1175
- } {\n${localsCode}\n};\n`
1175
+ } {\n${localsCode}\n};\n`
1176
1176
 
1177
1177
  return code
1178
1178
  }
@@ -1181,7 +1181,7 @@ function getExportCode (exports, replacements, icssPluginUsed, options) {
1181
1181
  ? localsCode
1182
1182
  : `___CSS_LOADER_EXPORT___.locals = {${
1183
1183
  localsCode ? `\n${localsCode}\n` : ''
1184
- }};\n`
1184
+ }};\n`
1185
1185
  }
1186
1186
 
1187
1187
  const isCSSStyleSheetExport = options.exportType === 'css-style-sheet'
@@ -1210,7 +1210,7 @@ function getExportCode (exports, replacements, icssPluginUsed, options) {
1210
1210
 
1211
1211
  code += `${
1212
1212
  options.esModule ? 'export default ' : 'module.exports ='
1213
- } ${finalExport};\n`
1213
+ } ${finalExport};\n`
1214
1214
 
1215
1215
  return code
1216
1216
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.8.13",
3
+ "version": "2.8.16",
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": "257b5bd882d6344be8ce36a99715c87f9d8adb51"
85
+ "gitHead": "79e2edd884ef6b27593952950f72343b98849bd7"
86
86
  }