2015-07-01 06:19:52 +08:00
|
|
|
/*
|
|
|
|
MIT License http://www.opensource.org/licenses/mit-license.php
|
|
|
|
Author Tobias Koppers @sokra
|
|
|
|
*/
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2017-01-06 23:16:12 +08:00
|
|
|
"use strict";
|
2018-07-30 23:08:51 +08:00
|
|
|
|
2018-10-11 22:30:07 +08:00
|
|
|
const makeSerializable = require("../util/makeSerializable");
|
2017-01-06 23:16:12 +08:00
|
|
|
const ModuleDependency = require("./ModuleDependency");
|
2015-07-01 06:19:52 +08:00
|
|
|
|
2018-07-23 23:33:29 +08:00
|
|
|
/** @typedef {import("webpack-sources").ReplaceSource} ReplaceSource */
|
2018-07-30 23:08:51 +08:00
|
|
|
/** @typedef {import("../Dependency")} Dependency */
|
2018-07-18 01:38:42 +08:00
|
|
|
/** @typedef {import("../DependencyTemplate").DependencyTemplateContext} DependencyTemplateContext */
|
2018-10-18 05:09:21 +08:00
|
|
|
/** @typedef {import("../dependencies/ImportDependenciesBlock")} ImportDependenciesBlock */
|
2018-07-23 23:33:29 +08:00
|
|
|
|
2017-01-06 23:16:12 +08:00
|
|
|
class ImportDependency extends ModuleDependency {
|
2018-10-18 05:09:21 +08:00
|
|
|
constructor(request) {
|
2017-01-06 23:16:12 +08:00
|
|
|
super(request);
|
|
|
|
}
|
|
|
|
|
|
|
|
get type() {
|
|
|
|
return "import()";
|
|
|
|
}
|
2020-05-31 17:48:45 +08:00
|
|
|
|
|
|
|
get category() {
|
|
|
|
return "esm";
|
|
|
|
}
|
2015-07-01 06:19:52 +08:00
|
|
|
}
|
|
|
|
|
2018-10-18 03:22:41 +08:00
|
|
|
makeSerializable(ImportDependency, "webpack/lib/dependencies/ImportDependency");
|
2018-10-11 22:30:07 +08:00
|
|
|
|
2018-07-23 23:33:29 +08:00
|
|
|
ImportDependency.Template = class ImportDependencyTemplate extends ModuleDependency.Template {
|
|
|
|
/**
|
|
|
|
* @param {Dependency} dependency the dependency for which the template should be applied
|
|
|
|
* @param {ReplaceSource} source the current replace source which can be modified
|
2018-07-18 01:38:42 +08:00
|
|
|
* @param {DependencyTemplateContext} templateContext the context object
|
2018-07-23 23:33:29 +08:00
|
|
|
* @returns {void}
|
|
|
|
*/
|
2018-08-23 02:17:49 +08:00
|
|
|
apply(
|
|
|
|
dependency,
|
|
|
|
source,
|
2018-11-17 01:18:44 +08:00
|
|
|
{ runtimeTemplate, module, moduleGraph, chunkGraph, runtimeRequirements }
|
2018-08-23 02:17:49 +08:00
|
|
|
) {
|
2018-07-23 23:33:29 +08:00
|
|
|
const dep = /** @type {ImportDependency} */ (dependency);
|
2018-10-18 05:09:21 +08:00
|
|
|
const block = /** @type {ImportDependenciesBlock} */ (moduleGraph.getParentBlock(
|
|
|
|
dep
|
|
|
|
));
|
2018-07-23 23:33:29 +08:00
|
|
|
const content = runtimeTemplate.moduleNamespacePromise({
|
2018-08-23 02:17:49 +08:00
|
|
|
chunkGraph,
|
2018-10-18 05:09:21 +08:00
|
|
|
block: block,
|
2018-07-24 21:30:37 +08:00
|
|
|
module: moduleGraph.getModule(dep),
|
2017-12-19 22:50:09 +08:00
|
|
|
request: dep.request,
|
2018-08-07 20:20:53 +08:00
|
|
|
strict: module.buildMeta.strictHarmonyModule,
|
2018-11-17 01:18:44 +08:00
|
|
|
message: "import()",
|
|
|
|
runtimeRequirements
|
2017-12-19 22:50:09 +08:00
|
|
|
});
|
|
|
|
|
2018-10-18 05:09:21 +08:00
|
|
|
source.replace(block.range[0], block.range[1] - 1, content);
|
2017-01-06 23:16:12 +08:00
|
|
|
}
|
2017-01-11 17:51:58 +08:00
|
|
|
};
|
2017-01-06 23:16:12 +08:00
|
|
|
|
|
|
|
module.exports = ImportDependency;
|