Commit 04bdbfd4 authored by Mike Greiling's avatar Mike Greiling

Automatically create DLL when it does not exist

parent e58b7bda
......@@ -117,23 +117,18 @@ if (IS_EE) {
});
}
// if there is a compiled DLL with a matching hash string, use it
let dll;
if (VENDOR_DLL && !IS_PRODUCTION) {
const dllHash = vendorDllHash();
const dllCachePath = path.join(ROOT_PATH, `tmp/cache/webpack-dlls/${dllHash}`);
if (fs.existsSync(dllCachePath)) {
console.log(`Using vendor DLL found at: ${dllCachePath}`);
dll = {
manifestPath: path.join(dllCachePath, 'vendor.dll.manifest.json'),
cacheFrom: dllCachePath,
cacheTo: path.join(ROOT_PATH, `public/assets/webpack/dll.${dllHash}/`),
publicPath: `dll.${dllHash}/vendor.dll.bundle.js`,
exists: null,
};
} else {
console.log(`Warning: No vendor DLL found at: ${dllCachePath}. DllPlugin disabled.`);
}
}
module.exports = {
......@@ -314,6 +309,48 @@ module.exports = {
jQuery: 'jquery',
}),
// if DLLs are enabled, detect whether the DLL exists and create it automatically if necessary
dll && {
apply(compiler) {
compiler.hooks.beforeCompile.tapAsync('DllAutoCompilePlugin', (params, callback) => {
if (dll.exists) {
callback();
} else if (fs.existsSync(dll.manifestPath)) {
console.log(`Using vendor DLL found at: ${dll.cacheFrom}`);
dll.exists = true;
callback();
} else {
console.log(
`Warning: No vendor DLL found at: ${dll.cacheFrom}. Compiling DLL automatically.`,
);
const dllConfig = require('./webpack.vendor.config.js');
const dllCompiler = webpack(dllConfig);
dllCompiler.run((err, stats) => {
if (err) {
return callback(err);
}
const info = stats.toJson();
if (stats.hasErrors()) {
console.error(info.errors.join('\n\n'));
}
if (stats.hasWarnings()) {
console.warn(info.warnings.join('\n\n'));
}
console.log('DLL compiled successfully.');
dll.exists = true;
callback();
});
}
});
},
},
// reference our compiled DLL modules
dll &&
new webpack.DllReferencePlugin({
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment