How to use source-map-to-comment - 5 common examples

To help you get started, we’ve selected a few source-map-to-comment examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github steelbrain / pundle / packages / pundle / src / cli.js View on Github external
async write(generated: Object) {
    let contents = generated.contents
    let writeSourceMap = false
    if (generated.sourceMap) {
      if (this.config.cli.sourceMapInline) {
        contents += `\n${sourceMapToComment(generated.sourceMap)}`
      } else if (this.config.cli.sourceMapOutputFile) {
        contents += `\n//# sourceMappingURL=${Path.relative(Path.dirname(this.config.cli.outputFile), this.config.cli.sourceMapOutputFile)}`
        writeSourceMap = true
      }
    }

    await writeFile(this.config.cli.outputFile, contents)
    debugWrite(this.config.cli.outputFile)
    if (writeSourceMap) {
      await writeFile(this.config.cli.sourceMapOutputFile, JSON.stringify(generated.sourceMap, null, 2))
      debugWrite(this.config.cli.sourceMapOutputFile)
    }
  }
  dispose() {
github steelbrain / pundle / packages / generator-default / src / index.js View on Github external
const mappings = Object.assign({}, config.mappings, {
    files: Object.assign({}, Helpers.getFileMappings(context, chunk, config), config.mappings.files),
  })
  chunks.push(`__sbPundle.registerMappings(${JSON.stringify(mappings)})`)
  chunks.push(`__sbPundle.registerLoaded(${JSON.stringify(config.label)})`)
  for (let i = 0, length = entries.length; i < length; i++) {
    invariant(entries[i].resolved, `Entry file '${entries[i].request}' was not resolved`)
    chunks.push(`__sbPundle.require('${Helpers.getFilePath(context, config, entries[i].resolved)}')`)
  }
  chunks.push('})();\n')

  const sourceMap = chunksMap.toJSON()
  if (config.sourceMap) {
    if (config.sourceMapPath === 'inline') {
      chunks.push(sourceMapToComment(sourceMap))
    }
  }

  return {
    chunk,
    contents: chunks.join('\n'),
    sourceMap,
    filesGenerated,
  }
}, {
  label: '',
github steelbrain / pundle / packages / pundle-core / src / compilation.js View on Github external
? Helpers.getChunkFilePath(entry.chunk, outputConfig.sourceMapTemplate)
        : null

      const resolved = path.resolve(outputConfig.rootDirectory, outputPath)
      let resolvedSourceMapPath = sourceMapPath
      if (resolvedSourceMapPath && resolvedSourceMapPath !== 'inline') {
        resolvedSourceMapPath = path.resolve(outputConfig.rootDirectory, resolvedSourceMapPath)
      }

      let contentsToWrite = Buffer.from(entry.generated.contents)
      if (resolvedSourceMapPath && entry.generated.sourceMap) {
        const type = entry.chunk.format === '.css' ? 'css' : 'js'
        let bottomLine

        if (resolvedSourceMapPath === 'inline') {
          bottomLine = sourceMapToComment(entry.generated.sourceMap, { type })
        } else {
          const bottomContents = `sourceMappingURL=${path.relative(path.dirname(resolved), resolvedSourceMapPath)}`
          bottomLine = type === 'css' ? `/*# ${bottomContents} */` : `//# ${bottomContents}`
        }
        bottomLine = `\n${bottomLine}`

        contentsToWrite = Buffer.concat([contentsToWrite, Buffer.from(bottomLine, 'utf8')])
      }
      invariant(
        !outputPaths[entry.chunk.label],
        'More than one outputs would use the same path. Try using some variables in output templates',
      )
      outputPaths[entry.chunk.label] = {
        outputPath: resolved,
        sourceMapPath: resolvedSourceMapPath,
      }
github steelbrain / pundle / packages / pundle-loader-css / src / index.js View on Github external
if (options.scoped) {
        aggregatedRoot.nodes.forEach(node => {
          node.selector = `${node.selector}.${randomId}`
        })
      }

      const results = aggregatedRoot.toResult({
        map: options.sourceMap ? { inline: false, annotation: false } : false,
      })
      let css = results.css

      if (results.map) {
        const currentSourceMap = results.map.toJSON()
        const sourceMap = file.sourceMap ? mergeSourceMap(file.sourceMap, currentSourceMap) : currentSourceMap
        css += `\n${sourceMapToComment(sourceMap, { type: 'css' })}`
      }

      const processModule = await context.resolveSimple('process', file.filePath)
      const ast = template.ast`
        ${file.imports.map(i => `require(${JSON.stringify(i)})`).join('\n')}
        var style = document.createElement('style')
        style.type = 'text/css'
        if (require(${JSON.stringify(processModule)}).env.NODE_ENV === "development" && module.hot && module.hot.dispose) {
          module.hot.dispose(function() {
            style.remove()
          })
        }
        style.textContent = ${JSON.stringify(css)}
        document.head.appendChild(style)
        module.exports = ${JSON.stringify(options.scoped ? randomId : null)}
      `
github steelbrain / pundle / packages / pundle / src / compilation / generator.js View on Github external
generateSourceMap(options: ?ProcessorConfig, asComment: boolean = false): string {
    if (!options) {
      options = this.getProcessorOptions()
    }
    const sourceMap = generateSourceMap(this.compilation.pundle, options, this.gatherAllImports())
    if (asComment) {
      return sourceMapToComment(sourceMap)
    }
    return JSON.stringify(sourceMap)
  }
  getProcessorOptions(): ProcessorConfig {

source-map-to-comment

Convert a Source Map object to a comment

MIT
Latest version published 3 years ago

Package Health Score

48 / 100
Full package analysis

Popular source-map-to-comment functions