How to use webpack-sources - 10 common examples

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 gdborton / webpack-parallel-uglify-plugin / test / lib / worker.js View on Github external
import test from 'ava';
import uglify from 'uglify-js';
import sinon from 'sinon';
import tmpFile from '../../lib/tmp-file';
import cache from '../../lib/cache';
import { RawSource, OriginalSource } from 'webpack-sources';

const codeSource = 'function  test   ()    {   void(0); }';
const rawSource = new RawSource(codeSource);
const originalSource = new OriginalSource(codeSource);
const sourceAndMap = rawSource.sourceAndMap();
const options = {
  uglifyJS: { },
};
const originalContent = JSON.stringify({
  source: sourceAndMap.source,
  map: sourceAndMap.map,
  options,
});
const minifiedContent = uglify.minify(codeSource, { });

// ava is multi process and uses process.on,
// so we stub it to be sure it doesn't get in the way.
const stubbedOn = sinon.stub(process, 'on');
const worker = require('../../lib/worker');
const { minify, processMessage } = worker;
github alibaba / rax / packages / miniapp-webpack-plugin / src / plugins / WebpackAssetsPlugin.js View on Github external
${SCHEMA_VAR} = ${JSON.stringify(mockData)};
            } catch(err) { 
              console.warn('Inject schema data with error', err); 
            }
          `;
          } catch (err) {
            throw new Error('Please check schema/mock-data.json is a valid JSON string.');
          }
        }

        if (injectSchemaMockData) {
          args.unshift(injectSchemaMockData);
        }

        args.unshift(ConcatSource); // firstArg for apply
        const app = new (ConcatSource.bind.apply(ConcatSource, args))();
        compilation.assets['app.js'] = app;
        global.AppJSContent = app.source();
      });
    });
github flaviuse / mern-authentication / client / node_modules / webpack / lib / wasm / WebAssemblyJavascriptGenerator.js View on Github external
Array.from(
				importedModules,
				([module, { importVar, request, reexports }]) => {
					const importStatement = runtimeTemplate.importStatement({
						module,
						request,
						importVar,
						originModule: module
					});
					return importStatement + reexports.join("\n");
				}
			)
		);

		// create source
		const source = new RawSource(
			[
				'"use strict";',
				"// Instantiate WebAssembly module",
				"var wasmExports = __webpack_require__.w[module.i];",

				!Array.isArray(module.usedExports)
					? `__webpack_require__.r(${module.exportsArgument});`
					: "",

				// this must be before import for circular dependencies
				"// export exports from WebAssembly module",
				Array.isArray(module.usedExports) && !needExportsCopy
					? `${module.moduleArgument}.exports = wasmExports;`
					: "for(var name in wasmExports) " +
					  `if(name != ${JSON.stringify(initIdentifer)}) ` +
					  `${module.exportsArgument}[name] = wasmExports[name];`,
github realywithoutname / mini-program-webpack-loader / src / MiniProgram.js View on Github external
if (this.options.target === 'ali') {
      ext = '.acss'
      wxssCode += `
        /* polyfill */
        ${readFileSync(join(__dirname, './ali/lib/base.acss'), 'utf8')}
      `
    }

    entryNames.forEach((name) => {
      let code = compilation.assets[name + ext]
      if (code) {
        wxssCode += `/************ ${name + ext} *************/\n`
        wxssCode += code.source().toString()
      }
    })
    return new RawSource(wxssCode)
  }
github angular / angular-cli / packages / angular_devkit / build_angular / src / angular-cli-files / plugins / cleancss-webpack-plugin.ts View on Github external
if (hasWarnings && output.stats.minifiedSize === 0) {
            return;
          }

          let newSource;
          if (output.sourceMap) {
            newSource = new SourceMapSource(
              output.styles,
              file,
              // tslint:disable-next-line: no-any
              output.sourceMap.toString() as any,
              content,
              map,
            );
          } else {
            newSource = new RawSource(output.styles);
          }

          compilation.assets[file] = newSource;
        });
github fossasia / susper.com / node_modules / webpack / lib / MainTemplate.js View on Github external
this.plugin("render", (bootstrapSource, chunk, hash, moduleTemplate, dependencyTemplates) => {
			const source = new ConcatSource();
			source.add("/******/ (function(modules) { // webpackBootstrap\n");
			source.add(new PrefixSource("/******/", bootstrapSource));
			source.add("/******/ })\n");
			source.add("/************************************************************************/\n");
			source.add("/******/ (");
			const modules = this.renderChunkModules(chunk, moduleTemplate, dependencyTemplates, "/******/ ");
			source.add(this.applyPluginsWaterfall("modules", modules, chunk, hash, moduleTemplate, dependencyTemplates));
			source.add(")");
			return source;
		});
		this.plugin("local-vars", (source, chunk, hash) => {
github kaliberjs / build / library / webpack-plugins / source-map-plugin.js View on Github external
Object.keys(assets).forEach(name => {
            const asset = assets[name]
            const map = asset.map()
            if (map) {

              // make sure sources in the source map are timestamped, this helps with hot reloading
              const now = Date.now()
              map.sources = map.sources.map(source => source + (source.includes('?') ? '&' : '?') + now)

              const [startComment, endComment] = name.endsWith('.css') ? ['/*', ' */'] : ['//', '']
              assets[name] = new ConcatSource(asset, `\n${startComment}# sourceMappingURL=${path.basename(name)}.map${endComment}\n`)
              assets[name + '.map'] = new RawSource(JSON.stringify(map))
            }
          })
        })
github myFace-KYC / Identity_Verification / node_modules / webpack / lib / MainTemplate.js View on Github external
render(hash, chunk, moduleTemplate, dependencyTemplates) {
		const buf = [];
		buf.push(this.applyPluginsWaterfall("bootstrap", "", chunk, hash, moduleTemplate, dependencyTemplates));
		buf.push(this.applyPluginsWaterfall("local-vars", "", chunk, hash));
		buf.push("");
		buf.push("// The require function");
		buf.push(`function ${this.requireFn}(moduleId) {`);
		buf.push(this.indent(this.applyPluginsWaterfall("require", "", chunk, hash)));
		buf.push("}");
		buf.push("");
		buf.push(this.asString(this.applyPluginsWaterfall("require-extensions", "", chunk, hash)));
		buf.push("");
		buf.push(this.asString(this.applyPluginsWaterfall("startup", "", chunk, hash)));
		let source = this.applyPluginsWaterfall("render", new OriginalSource(this.prefix(buf, " \t") + "\n", `webpack/bootstrap ${hash}`), chunk, hash, moduleTemplate, dependencyTemplates);
		if(chunk.hasEntryModule()) {
			source = this.applyPluginsWaterfall("render-with-entry", source, chunk, hash);
		}
		if(!source) throw new Error("Compiler error: MainTemplate plugin 'render' should return something");
		chunk.rendered = true;
		return new ConcatSource(source, ";");
	}
github rxweb / rxweb / rxweb.io / node_modules / @angular-devkit / build-angular / src / angular-cli-files / plugins / cleancss-webpack-plugin.js View on Github external
if (output.warnings && output.warnings.length > 0) {
                        compilation.warnings.push(...output.warnings);
                        hasWarnings = true;
                    }
                    if (output.errors && output.errors.length > 0) {
                        output.errors
                            .forEach((error) => compilation.errors.push(new Error(error)));
                        return;
                    }
                    // generally means invalid syntax so bail
                    if (hasWarnings && output.stats.minifiedSize === 0) {
                        return;
                    }
                    let newSource;
                    if (output.sourceMap) {
                        newSource = new webpack_sources_1.SourceMapSource(output.styles, file, output.sourceMap.toString(), content, map);
                    }
                    else {
                        newSource = new webpack_sources_1.RawSource(output.styles);
                    }
                    compilation.assets[file] = newSource;
                });
            });
github zeit / next.js / packages / next / build / webpack / plugins / terser-webpack-plugin / src / index.js View on Github external
compilation.errors.push(
              TerserPlugin.buildError(
                error,
                file,
                sourceMap,
                new RequestShortener(compiler.context)
              )
            )

            return
          }

          let outputSource

          if (map) {
            outputSource = new SourceMapSource(
              code,
              file,
              JSON.parse(map),
              input,
              inputSourceMap
            )
          } else {
            outputSource = new RawSource(code)
          }

          // Updating assets
          processedAssets.add((compilation.assets[file] = outputSource))

          // Handling warnings
          if (warnings && warnings.length > 0) {
            warnings.forEach(warning => {