Comments (7)
Please create reproducible test repo, because I can't reproduce it, also webpack-plugin-serve
is deprecated, please don't use it
from webpack.
Oh, the problem is here - https://github.com/shellscape/webpack-plugin-serve/blob/master/lib/index.js#L168, it is always a unique value, so webpack invalidates caches between multiple serve
commands, we can't fix it here, sorry
from webpack.
Interesting, will dig in a bit more. That said the following patch does seem to fix my issue
diff --git a/lib/DefinePlugin.js b/lib/DefinePlugin.js
index ed02a3cbd2d5d2c49aa2d49bc1732ab6b47ea004..27a49fa9e649f7111118031fd54185373c169766 100644
--- a/lib/DefinePlugin.js
+++ b/lib/DefinePlugin.js
@@ -306,11 +306,12 @@ const toCacheVersion = code => {
const PLUGIN_NAME = "DefinePlugin";
const VALUE_DEP_PREFIX = `webpack/${PLUGIN_NAME} `;
-const VALUE_DEP_MAIN = `webpack/${PLUGIN_NAME}_hash`;
const TYPEOF_OPERATOR_REGEXP = /^typeof\s+/;
const WEBPACK_REQUIRE_FUNCTION_REGEXP = /__webpack_require__\s*(!?\.)/;
const WEBPACK_REQUIRE_IDENTIFIER_REGEXP = /__webpack_require__/;
+let instanceCount = 1;
+
class DefinePlugin {
/**
* Create a new define plugin
@@ -318,6 +319,10 @@ class DefinePlugin {
*/
constructor(definitions) {
this.definitions = definitions;
+ // patch support multiple instances
+ this.value_dep_prefix = `webpack/${PLUGIN_NAME}-${instanceCount} `;
+ this.value_dep_main = `webpack/${PLUGIN_NAME}-${instanceCount}_hash`;
+ instanceCount += 1;
}
/**
@@ -349,7 +354,7 @@ class DefinePlugin {
const mainHash = createHash(compilation.outputOptions.hashFunction);
mainHash.update(
/** @type {string} */ (
- compilation.valueCacheVersions.get(VALUE_DEP_MAIN)
+ compilation.valueCacheVersions.get(this.value_dep_main)
) || ""
);
@@ -359,14 +364,14 @@ class DefinePlugin {
* @returns {void}
*/
const handler = parser => {
- const mainValue = compilation.valueCacheVersions.get(VALUE_DEP_MAIN);
+ const mainValue = compilation.valueCacheVersions.get(this.value_dep_main);
parser.hooks.program.tap(PLUGIN_NAME, () => {
const buildInfo = /** @type {BuildInfo} */ (
parser.state.module.buildInfo
);
if (!buildInfo.valueDependencies)
buildInfo.valueDependencies = new Map();
- buildInfo.valueDependencies.set(VALUE_DEP_MAIN, mainValue);
+ buildInfo.valueDependencies.set(this.value_dep_main, mainValue);
});
/**
@@ -377,8 +382,8 @@ class DefinePlugin {
parser.state.module.buildInfo
);
buildInfo.valueDependencies.set(
- VALUE_DEP_PREFIX + key,
- compilation.valueCacheVersions.get(VALUE_DEP_PREFIX + key)
+ this.value_dep_prefix + key,
+ compilation.valueCacheVersions.get(this.value_dep_prefix + key)
);
};
@@ -648,7 +653,7 @@ class DefinePlugin {
Object.keys(definitions).forEach(key => {
const code = definitions[key];
const version = toCacheVersion(code);
- const name = VALUE_DEP_PREFIX + prefix + key;
+ const name = this.value_dep_prefix + prefix + key;
mainHash.update("|" + prefix + key);
const oldVersion = compilation.valueCacheVersions.get(name);
if (oldVersion === undefined) {
@@ -678,7 +683,7 @@ class DefinePlugin {
walkDefinitionsForValues(definitions, "");
compilation.valueCacheVersions.set(
- VALUE_DEP_MAIN,
+ this.value_dep_main,
/** @type {string} */ (mainHash.digest("hex").slice(0, 8))
);
}
from webpack.
hm, we use mainHash.update("|" + prefix + key);
, so each value should be uniuq, can you use console.log()
for https://github.com/webpack/webpack/blob/main/lib/DefinePlugin.js#L322 and run build, so we will get all values and I will look, if you have something secret just change it for ***
for me
from webpack.
Will do. I believe the issue was the value is stash into a map (on compiler I believe) that uses only the DefinePlugin_hash key (which has no uniqueness)
from webpack.
webpack-plugin-serve
uses a stringified json that is stable across invocations. The {stable json}
value below is the same string (of length 9593
)
// invocation one
{
__TOKEN_ONE__: undefined,
__TOKEN_TWO__: undefined,
__CACHE_KEY__: '"string"',
'process.env': { NODE_ENV: '"development"' }
}
// invocation two
{ 'process.env.NODE_ENV': '"development"' }
// invocation three
{
'ʎɐɹɔosǝʌɹǝs': '{stable json}'
}
// invocation four (on incremental change)
{
'ʎɐɹɔosǝʌɹǝs': '{stable json}'
}
from webpack.
Can you try to remove 'process.env': { NODE_ENV: '"development"' }
from the first invocation
?
from webpack.
Related Issues (20)
- there are confusing JDocs code
- Potential bug issues
- Webpack is not resolving node_modules specified in `resolve.modules` property.
- Dynamically loading chunks
- [Code implementation issues] ArrayQueue
- [feature] create cli HOT 3
- Not able to build node script
- bootstrap:27 Uncaught TypeError: __webpack_require__.nmd is not a function
- Self-reference dependency has unused export name when imported inside of a web worker
- support `import.meta.dirname` and `import.meta.filename` HOT 2
- <!-- identifier: admin-actions -->
- Remote into Web Component from React giving an error saying " Module does not exist in container"
- import .scss build to js, the exported mapping is inconsistent with the usage【Urgent!!】
- Unused code elimination and deduplication is not applied when using sass's api: 'legacy' setting
- In cli, why no option named "--output-file-name" ?
- Need help with migrating a custom middleware from v3 to v5 of webpack-dev-server HOT 1
- Module federation: the usage of "dynamic remotes" will cause blank screen when working with `runtimeChunk`
- Failed build succeeds on rerun using cache
- MinChunkSizePlugin build very slow
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 webpack.