Comments (3)
Here is some code I tried in the resolver to replace existing built modules at a later point for when modules depending on old resolutions need to be busted.
var walkDependencyBlock = function(block, callback) {
console.log(block);
block.dependencies.forEach(callback);
block.variables.forEach(function(variable) {
variable.dependencies.forEach(callback);
});
block.blocks.forEach(function(block) {
walkDependencyBlock(block, callback);
});
};
// Invalidate any dependencies that request this resolution. For
// normal modules nothing needs to be done. But cached modules
// depending on this need to be busted, removed from the
// compilation, reasons for it re-processed, and the cache entry
// removed.
var willBust = [];
compilation.modules.forEach(function(module) {
if (module instanceof CacheModule) {
var dependsOnRequest = true;
walkDependencyBlock(module, function(dependency) {
dependsOnRequest = dependsOnRequest &&
module.context === request.context &&
dependency.request === request.request;
});
if (dependsOnRequest) {
willBust.push(module);
}
}
});
var addModuleDependencies = Promise.promisify(compilation.addModuleDependencies, {context: compilation});
var whenBusted = Promise.all(willBust.map(function(module) {
var reasons = module.reasons.slice();
module.disconnect();
compilation._modules[module.identifier()] = null;
compilation.modules.splice(compilation.modules.indexOf(module), 1);
return Promise.all(reasons.map(function(reason) {
reason.dependency.module = null;
return addModuleDependencies(reason.module, [[reason.dependency]], compilation.bail, null, true);
}));
}));
// Remove the out of date cache modules.
Object.keys(moduleCache).forEach(function(key) {
if (key === 'fileDependencies') {return;}
var module = moduleCache[key];
if (typeof module === 'string') {
module = JSON.parse(module);
moduleCache[key] = module;
}
var dependsOnRequest = true;
walkDependencyBlock(module, function(cacheDependency) {
dependsOnRequest = dependsOnRequest &&
module.context === request.context &&
cacheDependency.request === request.request;
});
if (dependsOnRequest) {
moduleCache[key] = null;
}
});
// Remove the out of date resolution.
resolveCache[cacheId] = null;
// Resolve normally.
whenBusted.then(next);
from hard-source-webpack-plugin.
Took a look at invalidating with the pre-compiling step idea. Current shot seems to work though a test for it doesn't seem to pick the file changes and a plugin eval-source-map test fails.
The main block is:
.then(function() {
var childCompiler = compiler.createChildCompiler();
var params = childCompiler.newCompilationParams();
childCompiler.applyPlugins("compile", params);
var compilation = childCompiler.newCompilation(params);
var entries = moduleCache.entries;
return Promise.all(entries.map(function(entry) {
return Promise.promisify(compilation.addEntry, {context: compilation})('', new SingleEntryDependency(entry), '');
}))
.then(function() {
return Promise.promisify(compilation.seal, {context: compilation})();
})
.then(function() {return compilation;});
})
.then(function(compilation) {
// console.log(compilation.modules);
compilation.modules.forEach(function(module) {
if (!(module instanceof HardModule)) {
return;
}
var cacheItem = moduleCache[module.request];
if (!cacheItem) {
return;
}
if (
!lodash.isEqual(cacheItem.used, module.used) ||
!lodash.isEqual(cacheItem.usedExports, module.usedExports)
) {
cacheItem.invalid = true;
moduleCache[module.request] = null;
}
});
})
from hard-source-webpack-plugin.
Closing with the merge of #15. #15 uses an improved version of the last above block. It runs a pre-emptive compiler pass and compares output to invalidate modules. This works and I don't think a more complex single pass would work as the work that builds up used
and usedExports
happens in a step of compilation.seal
so we'd need to wait to some point in seal
and replace invalid modules and then re-run necessary parts of seal for the newly built modules. This would make a single pass really really complicated.
from hard-source-webpack-plugin.
Related Issues (20)
- Error: Can't find options with ident 'vue-loader-options' HOT 1
- Not emitting CSS background images from package
- A problem when work with eslint
- Static assets are not generated on second build HOT 1
- This is a very good product
- exclude directory from all cache
- hard-source-webpack-plugin on Apple Silicon with M1 compatibility? HOT 1
- TypeError: Cannot read property 'call' of undefined HOT 1
- Should not use entire package.json as a hash. Should only use packageJson.dependencies HOT 1
- can not run with hard-source with cache.
- Failed to read cache during the second build HOT 3
- If I modify only one variable, do I have to cache it again?
- Webpack 5.x not supportted, because `compiler.hooks` can not add property HOT 5
- building new cache every time HOT 4
- https://github.com/mzgoddard/hard-source-webpack-plugin/issues/461#issuecomment-439177290
- Could not freeze HOT 6
- TypeError: Cannot read properties of undefined (reading 'tap') HOT 15
- Q: Should the property be cache set to true or it doesn't depend
- switch different mode to build application but no effect HOT 1
- The application runs incorrectly at the second packaging HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hard-source-webpack-plugin.