How to use the webpack-sources/lib/SourceMapSource function in webpack-sources

To help you get started, we’ve selected a few webpack-sources 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 zinserjan / mocha-webpack / src / webpack / InjectChangedFilesPlugin.js View on Github external
const regex = /__webpackManifest__\s*=\s*\[\s*\]/g; // eslint-disable-line
    const files = this.hotFiles.concat(this.failedFiles);
    const changedFiles = `['${files.join("', '")}']`;
    const replacement = `__webpackManifest__ = ${changedFiles}`;

    let match;
    while ((match = regex.exec(originalSource)) !== null) { // eslint-disable-line no-cond-assign
      const start = match.index;
      const end = match.index + (match[0].length - 1);
      result.replace(start, end, replacement);
    }

    const resultSource = result.source();
    const resultMap = result.map();

    compilation.assets[file] = new SourceMapSource( // eslint-disable-line no-param-reassign
      resultSource,
      file,
      resultMap,
      originalSource,
      originalMap
    );
  }
github zoobestik / csso-webpack-plugin / src / index.js View on Github external
...options,
                                filename: fileOutput,
                                sourceMap: Boolean(compiler.options.devtool),
                            });

                            if (map && sourceMap) {
                                const consumerMap = await new SourceMapConsumer(sourceMap);
                                map.applySourceMap(consumerMap, fileOutput);
                            }

                            if (!map) {
                                map = sourceMap;
                            }

                            compilation.assets[fileOutput] = map
                                ? new SourceMapSource(css, fileOutput, map.toJSON ? map.toJSON() : map)
                                : new RawSource(css);
                        } catch (err) {
                            const prefix = `${file} from CssoWebpackPlugin\n`;
                            const { message, parseError, stack } = err;
                            let error = `${message} ${stack}`;

                            if (parseError) {
                                error = `${message} [${file}:${parseError.line}:${parseError.column}]`;
                            }

                            compilation.errors.push(new Error(`${prefix}${error}`));
                        }
                    }),
                )),