1 | const ModuleDependency = require('webpack/lib/dependencies/ModuleDependency');
|
2 |
|
3 | class GoogLoaderPrefixDependency extends ModuleDependency {
|
4 | constructor(request, isModule, insertPosition) {
|
5 | super(request);
|
6 | this.insertPosition = insertPosition;
|
7 | this.isGoogModule = isModule;
|
8 | }
|
9 |
|
10 | get type() {
|
11 | return 'goog loader prefix';
|
12 | }
|
13 |
|
14 | updateHash(hash) {
|
15 | hash.update(this.insertPosition + '');
|
16 | hash.update(this.isGoogModule + '');
|
17 | }
|
18 | }
|
19 |
|
20 | class GoogLoaderPrefixDependencyTemplate {
|
21 | apply(dep, source) {
|
22 | if (dep.insertPosition === null) {
|
23 | return;
|
24 | }
|
25 |
|
26 | let content = `var googPreviousLoaderState__ = goog.moduleLoaderState_;\n`;
|
27 | if (dep.isGoogModule) {
|
28 | content += `goog.moduleLoaderState_ = {moduleName: '', declareLegacyNamespace: false};
|
29 | goog.loadModule(function() {\n`;
|
30 | } else {
|
31 | content += `goog.moduleLoaderState_ = null;\n`;
|
32 | }
|
33 | source.insert(dep.insertPosition, content);
|
34 | }
|
35 | }
|
36 |
|
37 | module.exports = GoogLoaderPrefixDependency;
|
38 | module.exports.Template = GoogLoaderPrefixDependencyTemplate;
|