How to use the webpack-sources.ReplaceSource 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 weixin / Miaow / node_modules / webpack / lib / optimize / ConcatenatedModule.js View on Github external
lines
								.slice(Math.max(0, lineNumber - 3), lineNumber + 2)
								.join("\n| ");
					}
					throw err;
				}
				const scopeManager = eslintScope.analyze(ast, {
					ecmaVersion: 6,
					sourceType: "module",
					optimistic: true,
					ignoreEval: true,
					impliedStrict: true
				});
				const globalScope = scopeManager.acquire(ast);
				const moduleScope = globalScope.childScopes[0];
				const resultSource = new ReplaceSource(source);
				info.ast = ast;
				info.internalSource = source;
				info.source = resultSource;
				info.globalScope = globalScope;
				info.moduleScope = moduleScope;
			}
		}

		// List of all used names to avoid conflicts
		const allUsedNames = new Set([
			"__WEBPACK_MODULE_DEFAULT_EXPORT__", // avoid using this internal name

			"abstract",
			"arguments",
			"async",
			"await",
github SebastianS90 / webpack-polyfill-injector / src / index.js View on Github external
function buildInjector(polyfills, src) {
    const injectorRaw = loadFileAsSource('./injector.js');
    const injector = new ReplaceSource(injectorRaw);

    // Replace __TEST__
    const testPosition = injectorRaw.source().indexOf('__TEST__');
    injector.replace(testPosition, testPosition + 7,
        polyfills.map(polyfill =>
            `/* ${polyfill.replace(/\//g, '.')} */!(` +
            loadFileAsString(`polyfill-service/polyfills/${polyfill}/detect.js`) +
            ')'
        ).join('\n    || ')
    );

    // Replace __SRC__
    const srcPosition = injectorRaw.source().indexOf('__SRC__');
    injector.replace(srcPosition, srcPosition + 6, JSON.stringify(src));

    return injector;
github nrwl / nx / packages / web / src / utils / third-party / cli-files / utilities / index-file / augment-index-html.ts View on Github external
// Less accurate fallback
    // parse5 4.x does not provide locations if malformed html is present
    scriptInsertionPoint = params.inputContent.indexOf('');
  }

  let styleInsertionPoint;
  if (headElement.__location && headElement.__location.endTag) {
    styleInsertionPoint = headElement.__location.endTag.startOffset;
  } else {
    // Less accurate fallback
    // parse5 4.x does not provide locations if malformed html is present
    styleInsertionPoint = params.inputContent.indexOf('');
  }

  // Inject into the html
  const indexSource = new ReplaceSource(
    new RawSource(params.inputContent),
    params.input
  );

  let scriptElements = '';
  for (const script of scripts) {
    const attrs: { name: string; value: string | null }[] = [
      { name: 'src', value: (params.deployUrl || '') + script }
    ];

    if (crossOrigin !== 'none') {
      attrs.push({ name: 'crossorigin', value: crossOrigin });
    }

    // We want to include nomodule or module when a file is not common amongs all
    // such as runtime.js
github makuga01 / dnsFookup / FE / node_modules / webpack / lib / DependenciesBlockVariable.js View on Github external
expressionSource(dependencyTemplates, runtimeTemplate) {
		const source = new ReplaceSource(new RawSource(this.expression));
		for (const dep of this.dependencies) {
			const template = dependencyTemplates.get(dep.constructor);
			if (!template) {
				throw new Error(`No template for dependency: ${dep.constructor.name}`);
			}
			template.apply(dep, source, runtimeTemplate, dependencyTemplates);
		}
		return source;
	}
github weixin / Miaow / node_modules / webpack / lib / JavascriptGenerator.js View on Github external
generate(module, dependencyTemplates, runtimeTemplate) {
		const originalSource = module.originalSource();
		if (!originalSource) {
			return new RawSource("throw new Error('No source available');");
		}

		const source = new ReplaceSource(originalSource);

		this.sourceBlock(
			module,
			module,
			[],
			dependencyTemplates,
			source,
			runtimeTemplate
		);

		return source;
	}
github TodayTix / svg-sprite-webpack-plugin / src / plugin.js View on Github external
function replaceAll(source, name, oldStr, newStr) {
  const transformedSource = new ReplaceSource(source, name);
  const reTester = new RegExp(oldStr, 'g');
  let reResult = reTester.exec(source.source());

  if (reResult == null) {
    return source;
  }

  while (reResult != null) {
    transformedSource.replace(
      reResult.index,
      reTester.lastIndex - 1,
      newStr
    );

    reResult = reTester.exec(source.source());
  }
github fossasia / susper.com / node_modules / webpack / lib / DependenciesBlockVariable.js View on Github external
expressionSource(dependencyTemplates, outputOptions, requestShortener) {
		const source = new ReplaceSource(new RawSource(this.expression));
		this.dependencies.forEach(dep => {
			const template = dependencyTemplates.get(dep.constructor);
			if(!template) throw new Error(`No template for dependency: ${dep.constructor.name}`);
			template.apply(dep, source, outputOptions, requestShortener, dependencyTemplates);
		});
		return source;
	}
github wix / stylable / packages / webpack-plugin / src / stylable-generator.ts View on Github external
module.buildInfo.optimize.minify
              )
            : `""`;

        this.reportDiagnostics(meta);

        const depth = module.buildInfo.runtimeInfo.depth;
        const id =
            this.options.runtimeStylesheetId === 'namespace'
                ? JSON.stringify(module.buildInfo.stylableMeta.namespace)
                : runtimeTemplate.moduleId({
                      module,
                      request: module.request
                  });

        return new ReplaceSource(
            this.createModuleSource(
                module,
                id,
                stylableResult,
                css,
                depth,
                !isImportedByNonStylable
            )
        );
    }
    public transform(module: StylableModule) {
github fossasia / susper.com / node_modules / @angular-devkit / build-optimizer / src / purify / purify.js View on Github external
function purify(content) {
    const rawSource = new webpack_sources_1.RawSource(content);
    const replaceSource = new webpack_sources_1.ReplaceSource(rawSource, 'file.js');
    const inserts = purifyReplacements(content);
    inserts.forEach((insert) => {
        replaceSource.insert(insert.pos, insert.content);
    });
    return replaceSource.source();
}
exports.purify = purify;