123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- "use strict";
- const RuntimeGlobals = require("../RuntimeGlobals");
- const RawDataUrlModule = require("../asset/RawDataUrlModule");
- const {
- getDependencyUsedByExportsCondition
- } = require("../optimize/InnerGraph");
- const makeSerializable = require("../util/makeSerializable");
- const memoize = require("../util/memoize");
- const ModuleDependency = require("./ModuleDependency");
- const getIgnoredRawDataUrlModule = memoize(() => {
- return new RawDataUrlModule("data:,", `ignored-asset`, `(ignored asset)`);
- });
- class URLDependency extends ModuleDependency {
-
- constructor(request, range, outerRange, relative) {
- super(request);
- this.range = range;
- this.outerRange = outerRange;
- this.relative = relative || false;
-
- this.usedByExports = undefined;
- }
- get type() {
- return "new URL()";
- }
- get category() {
- return "url";
- }
-
- getCondition(moduleGraph) {
- return getDependencyUsedByExportsCondition(
- this,
- this.usedByExports,
- moduleGraph
- );
- }
-
- createIgnoredModule(context) {
- return getIgnoredRawDataUrlModule();
- }
-
- serialize(context) {
- const { write } = context;
- write(this.outerRange);
- write(this.relative);
- write(this.usedByExports);
- super.serialize(context);
- }
-
- deserialize(context) {
- const { read } = context;
- this.outerRange = read();
- this.relative = read();
- this.usedByExports = read();
- super.deserialize(context);
- }
- }
- URLDependency.Template = class URLDependencyTemplate extends (
- ModuleDependency.Template
- ) {
-
- apply(dependency, source, templateContext) {
- const {
- chunkGraph,
- moduleGraph,
- runtimeRequirements,
- runtimeTemplate,
- runtime
- } = templateContext;
- const dep = (dependency);
- const connection = moduleGraph.getConnection(dep);
-
- if (connection && !connection.isTargetActive(runtime)) {
- source.replace(
- dep.outerRange[0],
- dep.outerRange[1] - 1,
- "/* unused asset import */ undefined"
- );
- return;
- }
- runtimeRequirements.add(RuntimeGlobals.require);
- if (dep.relative) {
- runtimeRequirements.add(RuntimeGlobals.relativeUrl);
- source.replace(
- dep.outerRange[0],
- dep.outerRange[1] - 1,
- `/* asset import */ new ${
- RuntimeGlobals.relativeUrl
- }(${runtimeTemplate.moduleRaw({
- chunkGraph,
- module: moduleGraph.getModule(dep),
- request: dep.request,
- runtimeRequirements,
- weak: false
- })})`
- );
- } else {
- runtimeRequirements.add(RuntimeGlobals.baseURI);
- source.replace(
- dep.range[0],
- dep.range[1] - 1,
- `/* asset import */ ${runtimeTemplate.moduleRaw({
- chunkGraph,
- module: moduleGraph.getModule(dep),
- request: dep.request,
- runtimeRequirements,
- weak: false
- })}, ${RuntimeGlobals.baseURI}`
- );
- }
- }
- };
- makeSerializable(URLDependency, "webpack/lib/dependencies/URLDependency");
- module.exports = URLDependency;
|