@regru/webpack-babel-multi-target-plugin
Version:
A Webpack plugin that works with Babel to allow deployment of ES2015 builds targeted to modern browsers, with an ES5 fallback for legacy browsers.
48 lines • 1.53 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const babel_target_1 = require("./babel-target");
class TargetedChunk {
get target() {
if (!this._target) {
this._target = babel_target_1.BabelTarget.findTarget(this.group) || babel_target_1.BabelTarget.findTarget(this.chunk);
}
return this._target;
}
constructor(group, chunk) {
this.chunk = chunk;
this.group = group;
}
}
exports.TargetedChunk = TargetedChunk;
class TargetedChunkMap {
constructor(publicPath) {
this.publicPath = publicPath;
this.innerMap = {};
this.targetedChunks = {};
if (typeof (this.publicPath) === 'undefined') {
this.publicPath = '';
}
}
get(key) {
return this.innerMap[key];
}
set(key, group, chunk) {
const pathKey = this.publicPath + key;
if (!this.innerMap[pathKey]) {
this.innerMap[pathKey] = [];
}
const targetedChunk = this.getTargetedChunk(group, chunk);
if (!this.innerMap[pathKey].includes(targetedChunk)) {
this.innerMap[pathKey].push(targetedChunk);
}
}
getTargetedChunk(group, chunk) {
const key = group.id + chunk.hash;
if (!this.targetedChunks[key]) {
this.targetedChunks[key] = new TargetedChunk(group, chunk);
}
return this.targetedChunks[key];
}
}
exports.TargetedChunkMap = TargetedChunkMap;
//# sourceMappingURL=targeted.chunk.js.map