Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
let vendorHashesJson, vendorSourceListMap, vendorSource, vendorMap;
if (settings.webpackDll && dll) {
const name = `vendor_${platform}`;
const jsonPath = path.join('..', settings.dllBuildDir, `${name}_dll.json`);
config.plugins.push(new webpack.DllReferencePlugin({
context: process.cwd(),
manifest: require(jsonPath) // eslint-disable-line import/no-dynamic-require
}));
vendorHashesJson = JSON.parse(fs.readFileSync(path.join(settings.dllBuildDir, `${name}_dll_hashes.json`)));
vendorSource = new RawSource(fs.readFileSync(path.join(settings.dllBuildDir, vendorHashesJson.name)).toString() + "\n");
vendorMap = new RawSource(fs.readFileSync(path.join(settings.dllBuildDir, vendorHashesJson.name + ".map")).toString());
if (platform !== 'web') {
const vendorAssets = JSON.parse(fs.readFileSync(path.join(settings.dllBuildDir, vendorHashesJson.name + ".assets")).toString());
config.plugins.push(new MobileAssetsPlugin(vendorAssets));
}
vendorSourceListMap = fromStringWithSourceMap(
vendorSource.source(),
JSON.parse(vendorMap.source())
);
}
let compiler = webpack(config);
compiler.plugin('after-emit', (compilation, callback) => {
if (backendFirstStart) {
if (settings.backend) {
logger.debug("Webpack dev server is waiting for backend to start...");
const { host } = url.parse(settings.backendUrl.replace('{ip}', ip.address()));
waitOn({ resources: [`tcp:${host}`] }, err => {
if (err) {
logger.error(err);
callback();
chunk.files.forEach(file => {
if (file.endsWith('.bundle')) {
if (builder.sourceMap) {
const sourceListMap = new SourceListMap();
sourceListMap.add(vendorSourceListMap);
sourceListMap.add(
fromStringWithSourceMap(
compilation.assets[file].source(),
JSON.parse(compilation.assets[file + '.map'].source())
)
);
const sourceAndMap = sourceListMap.toStringWithSourceMap({ file });
compilation.assets[file] = new RawSource(sourceAndMap.source);
compilation.assets[file + '.map'] = new RawSource(JSON.stringify(sourceAndMap.map));
} else {
compilation.assets[file] = new ConcatSource(vendorSource, compilation.assets[file]);
}
}
});
});
listMap(options) {
options = options || {};
if(options.module === false)
return new SourceListMap(this._value, this._name, this._value);
return fromStringWithSourceMap(this._value, typeof this._sourceMap === "string" ? JSON.parse(this._sourceMap) : this._sourceMap);
}
listMap(options) {
this._ensureValueString();
this._ensureSourceMapObject();
options = options || {};
if (options.module === false)
return new SourceListMap(
this._valueAsString,
this._name,
this._valueAsString
);
return fromStringWithSourceMap(
this._valueAsString,
this._sourceMapAsObject
);
}
chunk.files.forEach(file => {
if (file.endsWith('.bundle')) {
if (builder.sourceMap) {
const sourceListMap = new SourceListMap();
sourceListMap.add(vendorSourceListMap);
sourceListMap.add(
fromStringWithSourceMap(
compilation.assets[file].source(),
JSON.parse(compilation.assets[file + '.map'].source())
)
);
const sourceAndMap = sourceListMap.toStringWithSourceMap({ file });
compilation.assets[file] = new RawSource(sourceAndMap.source);
compilation.assets[file + '.map'] = new RawSource(JSON.stringify(sourceAndMap.map));
} else {
compilation.assets[file] = new ConcatSource(vendorSource, compilation.assets[file]);
}
}
});
});
listMap(options) {
options = options || {};
if(options.module === false)
return new SourceListMap(this._value, this._name, this._value);
return fromStringWithSourceMap(this._value, typeof this._sourceMap === "string" ? JSON.parse(this._sourceMap) : this._sourceMap);
}
listMap(options) {
options = options || {};
if(options.module === false)
return new SourceListMap(this._value, this._name, this._value);
return fromStringWithSourceMap(this._value, typeof this._sourceMap === "string" ? JSON.parse(this._sourceMap) : this._sourceMap);
}
fs.readFileSync(path.join(builder.dllBuildDir, `${name}_dll_hashes.json`)).toString()
);
vendorSource = new RawSource(
fs.readFileSync(path.join(builder.dllBuildDir, vendorHashesJson.name)).toString() + '\n'
);
if (platform !== 'web') {
const vendorAssets = JSON.parse(
fs.readFileSync(path.join(builder.dllBuildDir, vendorHashesJson.name + '.assets')).toString()
);
config.plugins.push(new MobileAssetsPlugin(vendorAssets));
}
if (builder.sourceMap) {
vendorMap = new RawSource(
fs.readFileSync(path.join(builder.dllBuildDir, vendorHashesJson.name + '.map')).toString()
);
vendorSourceListMap = fromStringWithSourceMap(vendorSource.source(), JSON.parse(vendorMap.source()));
}
}
const compiler = webpack(config);
let awaitedAlready = false;
hookAsync(compiler, 'after-emit', (compilation, callback) => {
if (!awaitedAlready) {
if (hasBackend || builder.waitOn) {
let waitOnUrls;
const backendOption = builder.backendUrl || builder.backendUrl;
if (backendOption) {
const { protocol, hostname, port } = url.parse(backendOption.replace('{ip}', ip.address()));
waitOnUrls = [`tcp:${hostname}:${port || (protocol === 'https:' ? 443 : 80)}`];
} else {
waitOnUrls = builder.waitOn ? [].concat(builder.waitOn) : undefined;
HardSource.prototype.listMap = function(options) {
var mapId = JSON.stringify(options);
if (!this._cachedListMap) {
this._cachedListMap = {};
}
if (!this._cachedListMap[mapId]) {
this._cachedListMap[mapId] = fromStringWithSourceMap(
this.cacheItem.source,
this.map(options)
);
}
return this._cachedListMap[mapId];
};
chunk.files.forEach(file => {
if (file.endsWith('.bundle')) {
if (builder.sourceMap) {
const sourceListMap = new SourceListMap();
sourceListMap.add(vendorSourceListMap);
sourceListMap.add(
fromStringWithSourceMap(
compilation.assets[file].source(),
JSON.parse(compilation.assets[file + '.map'].source())
)
);
const sourceAndMap = sourceListMap.toStringWithSourceMap({ file });
compilation.assets[file] = new RawSource(sourceAndMap.source);
compilation.assets[file + '.map'] = new RawSource(JSON.stringify(sourceAndMap.map));
} else {
compilation.assets[file] = new ConcatSource(vendorSource, compilation.assets[file]);
}
}
});
});