How to use the webpack-sources/lib/RawSource 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 Klathmon / imagemin-webpack-plugin / index.js View on Github external
return Promise.all(map(compilation.assets, (asset, filename) => throttle(async () => {
    const assetSource = asset.source()
    // Skip the image if it's not a match for the regex
    if (testFile(filename, testRegexes) && testFileSize(assetSource, minFileSize, maxFileSize)) {
      // Optimize the asset's source
      const optimizedImageBuffer = await optimizeImage(assetSource, imageminOptions)
      // Then write the optimized version back to the asset object as a "raw source"
      compilation.assets[filename] = new RawSource(optimizedImageBuffer)
    }
  })))
}
github zoobestik / csso-webpack-plugin / src / index.js View on Github external
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}`));
                        }
                    }),
                )),