@zohodesk/client_build_tool 0.0.6-exp.18 → 0.0.6-exp.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -39,7 +39,7 @@ class CdnChangePlugin {
|
|
|
39
39
|
constructor(options) {
|
|
40
40
|
this.createSeparateSMap = options.createSeparateSMap;
|
|
41
41
|
this.i18nTemplate = options.i18nTemplate || '{{__I18N_CDN__}}';
|
|
42
|
-
this.variableName = options.variableName || 'window.
|
|
42
|
+
this.variableName = options.variableName || 'window.__SMAP_PATH__';
|
|
43
43
|
this.cssTemplate = options.cssTemplate || '{{__CSS_CDN__}}';
|
|
44
44
|
this.jsTemplate = options.jsTemplate || '{{__JS_CDN__}}';
|
|
45
45
|
this.mode = options.mode || 'prod';
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _htmlWebpackPlugin = _interopRequireDefault(require("html-webpack-plugin"));
|
|
9
|
+
|
|
10
|
+
var _nameTemplates = require("../common/nameTemplates");
|
|
11
|
+
|
|
12
|
+
var _modeUtils = require("../common/modeUtils");
|
|
13
|
+
|
|
14
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
15
|
+
|
|
16
|
+
// import { RuntimeGlobals, RuntimeModule } from 'webpack';
|
|
17
|
+
// import { Template } from 'webpack';
|
|
18
|
+
const pluginName = 'CdnChangePlugin'; // const MODULE_TYPE = 'css/mini-extract';
|
|
19
|
+
// class CdnChangeRuntimePlugin extends RuntimeModule {
|
|
20
|
+
// constructor(compiler, { variableName }) {
|
|
21
|
+
// super('cdn loading', 10);
|
|
22
|
+
// this.variableName = variableName;
|
|
23
|
+
// }
|
|
24
|
+
// generate() {
|
|
25
|
+
// return `${RuntimeGlobals.getChunkCssFilename} = function(chunkId) {
|
|
26
|
+
// const cssCdnUrl = window[${this.variableName}] || chunkId;
|
|
27
|
+
// return cssCdnUrl;
|
|
28
|
+
// }`;
|
|
29
|
+
// }
|
|
30
|
+
// }
|
|
31
|
+
|
|
32
|
+
class CdnChangePlugin {
|
|
33
|
+
constructor(options) {
|
|
34
|
+
this.createSeparateSMap = options.createSeparateSMap;
|
|
35
|
+
this.i18nTemplate = options.i18nTemplate || '{{__I18N_CDN__}}';
|
|
36
|
+
this.variableName = options.variableName || '__CSS_CDN__';
|
|
37
|
+
this.cssTemplate = options.cssTemplate || '{{__CSS_CDN__}}';
|
|
38
|
+
this.jsTemplate = options.jsTemplate || '{{__JS_CDN__}}';
|
|
39
|
+
this.mode = options.mode || 'prod';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
apply(compiler) {
|
|
43
|
+
// compiler.hooks.thisCompilation.tap(pluginName, compilation => {
|
|
44
|
+
// const enabledChunks = new WeakSet();
|
|
45
|
+
// const handler = (entryRuntimeChunk, set) => {
|
|
46
|
+
// if (enabledChunks.has(entryRuntimeChunk)) {
|
|
47
|
+
// return;
|
|
48
|
+
// }
|
|
49
|
+
// enabledChunks.add(entryRuntimeChunk);
|
|
50
|
+
// set.add(RuntimeGlobals.getFullHash);
|
|
51
|
+
// set.add(RuntimeGlobals.getChunkCssFilename);
|
|
52
|
+
// compilation.addRuntimeModule(
|
|
53
|
+
// entryRuntimeChunk,
|
|
54
|
+
// new CdnChangeRuntimePlugin(set, {
|
|
55
|
+
// compiler,
|
|
56
|
+
// variableName: this.variableName
|
|
57
|
+
// })
|
|
58
|
+
// );
|
|
59
|
+
// };
|
|
60
|
+
// compilation.hooks.runtimeRequirementInTree
|
|
61
|
+
// .for(RuntimeGlobals.ensureChunkHandlers)
|
|
62
|
+
// .tap(pluginName, handler);
|
|
63
|
+
// });
|
|
64
|
+
compiler.hooks.compilation.tap(pluginName, compilation => {
|
|
65
|
+
_htmlWebpackPlugin.default.getHooks(compilation).beforeAssetTagGeneration.tap(pluginName, (data, cb) => {
|
|
66
|
+
const {
|
|
67
|
+
createSeparateSMap,
|
|
68
|
+
mode
|
|
69
|
+
} = this; // eslint-disable-next-line no-param-reassign
|
|
70
|
+
|
|
71
|
+
data.assets = { ...data.assets,
|
|
72
|
+
css: data.assets.css.map(css => `${this.cssTemplate}${css}`),
|
|
73
|
+
js: data.assets.js.map(js => {
|
|
74
|
+
if (((0, _modeUtils.isProductionMode)(mode) || createSeparateSMap) && !(0, _nameTemplates.isI18nFile)(js)) {
|
|
75
|
+
js = js.replace('js/', `{{--js-smap}}js/`); //eslint-disable-line
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return `${(0, _nameTemplates.isI18nFile)(js) ? this.i18nTemplate : this.jsTemplate}${js}`;
|
|
79
|
+
})
|
|
80
|
+
};
|
|
81
|
+
cb && cb(null, data);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
var _default = CdnChangePlugin; // Cdn Change Plugin for runtime chunks???
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* the filename of the script part of the chunk
|
|
92
|
+
*/
|
|
93
|
+
// exports.getChunkScriptFilename = "__webpack_require__.u";
|
|
94
|
+
// /**
|
|
95
|
+
// * the filename of the css part of the chunk
|
|
96
|
+
// */
|
|
97
|
+
// exports.getChunkCssFilename = "__webpack_require__.k";
|
|
98
|
+
|
|
99
|
+
exports.default = _default;
|