@mpxjs/webpack-plugin 2.10.4-beta.19 → 2.10.4-beta.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/parser.js CHANGED
@@ -14,7 +14,7 @@ module.exports = (content, { filePath, needMap, mode, env }) => {
14
14
  output = compiler.parseComponent(content, {
15
15
  mode,
16
16
  filePath,
17
- // pad: 'line', // stylus编译遇到大量空行时会出现栈溢出,故注释掉
17
+ pad: 'line',
18
18
  env
19
19
  })
20
20
  if (needMap) {
@@ -1,5 +1,6 @@
1
1
  const babylon = require('@babel/parser')
2
2
  const MagicString = require('magic-string')
3
+ const { SourceMapConsumer, SourceMapGenerator } = require('source-map')
3
4
  const traverse = require('@babel/traverse').default
4
5
  const t = require('@babel/types')
5
6
  const formatCodeFrame = require('@babel/code-frame')
@@ -625,7 +626,12 @@ function compileScriptSetup (
625
626
  _s.appendRight(endOffset, '})')
626
627
 
627
628
  return {
628
- content: _s.toString()
629
+ content: _s.toString(),
630
+ map: _s.generateMap({
631
+ source: filePath,
632
+ hires: true,
633
+ includeContent: true
634
+ })
629
635
  }
630
636
  }
631
637
 
@@ -1165,14 +1171,30 @@ function getCtor (ctorType) {
1165
1171
  return ctor
1166
1172
  }
1167
1173
 
1168
- module.exports = function (content) {
1174
+ module.exports = async function (content, sourceMap) {
1169
1175
  const { queryObj } = parseRequest(this.resource)
1170
1176
  const { ctorType, lang } = queryObj
1171
1177
  const filePath = this.resourcePath
1172
- const { content: callbackContent } = compileScriptSetup({
1178
+ const callback = this.async()
1179
+ let finalSourceMap = null
1180
+ const {
1181
+ content: callbackContent,
1182
+ map
1183
+ } = compileScriptSetup({
1173
1184
  content,
1174
1185
  lang
1175
1186
  }, ctorType, filePath)
1176
-
1177
- this.callback(null, callbackContent)
1187
+ finalSourceMap = map
1188
+ if (sourceMap) {
1189
+ const compiledMapConsumer = await new SourceMapConsumer(map)
1190
+ const compiledMapGenerator = SourceMapGenerator.fromSourceMap(compiledMapConsumer)
1191
+
1192
+ const originalConsumer = await new SourceMapConsumer(sourceMap)
1193
+ compiledMapGenerator.applySourceMap(
1194
+ originalConsumer,
1195
+ filePath // 需要确保与原始映射的source路径一致
1196
+ )
1197
+ finalSourceMap = compiledMapGenerator.toJSON()
1198
+ }
1199
+ callback(null, callbackContent, finalSourceMap)
1178
1200
  }
@@ -581,7 +581,8 @@ function parseComponent (content, options) {
581
581
  let text = content.slice(currentBlock.start, currentBlock.end)
582
582
  // pad content so that linters and pre-processors can output correct
583
583
  // line numbers in errors and warnings
584
- if (options.pad) {
584
+ // stylus编译遇到大量空行时会出现栈溢出,故针对stylus不走pad
585
+ if (options.pad && !(currentBlock.tag === 'style' && currentBlock.lang === 'stylus')) {
585
586
  text = padContent(currentBlock, options.pad) + text
586
587
  }
587
588
  currentBlock.content = text
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mpxjs/webpack-plugin",
3
- "version": "2.10.4-beta.19",
3
+ "version": "2.10.4-beta.20",
4
4
  "description": "mpx compile core",
5
5
  "keywords": [
6
6
  "mpx"