mirror of https://github.com/webpack/webpack.git
Compare commits
8 Commits
010b90de2a
...
e9ad240233
Author | SHA1 | Date |
---|---|---|
|
e9ad240233 | |
|
0020eb88b0 | |
|
3f486d2162 | |
|
a88a269d3a | |
|
077eea1a50 | |
|
595f13fd70 | |
|
3405021731 | |
|
6f986b86f6 |
|
@ -354,20 +354,18 @@ class DefinePlugin {
|
|||
* @returns {void}
|
||||
*/
|
||||
apply(compiler) {
|
||||
const definitions = this.definitions;
|
||||
|
||||
/**
|
||||
* @type {Map<string, Set<string>>}
|
||||
*/
|
||||
const finalByNestedKey = new Map();
|
||||
/**
|
||||
* @type {Map<string, Set<string>>}
|
||||
*/
|
||||
const nestedByFinalKey = new Map();
|
||||
|
||||
compiler.hooks.compilation.tap(
|
||||
PLUGIN_NAME,
|
||||
(compilation, { normalModuleFactory }) => {
|
||||
/**
|
||||
* @type {Map<string, Set<string>>}
|
||||
*/
|
||||
const finalByNestedKey = new Map();
|
||||
/**
|
||||
* @type {Map<string, Set<string>>}
|
||||
*/
|
||||
const nestedByFinalKey = new Map();
|
||||
|
||||
const logger = compilation.getLogger("webpack.DefinePlugin");
|
||||
compilation.dependencyTemplates.set(
|
||||
ConstDependency,
|
||||
|
@ -512,11 +510,11 @@ class DefinePlugin {
|
|||
if (
|
||||
!finalSet ||
|
||||
!finalSet.has(id) ||
|
||||
!definitions[fullKey]
|
||||
!this.definitions[fullKey]
|
||||
) {
|
||||
return;
|
||||
}
|
||||
obj[id] = definitions[fullKey];
|
||||
obj[id] = this.definitions[fullKey];
|
||||
}
|
||||
let strCode = stringifyObj(
|
||||
obj,
|
||||
|
@ -736,7 +734,7 @@ class DefinePlugin {
|
|||
);
|
||||
};
|
||||
|
||||
walkDefinitions(definitions, "");
|
||||
walkDefinitions(this.definitions, "");
|
||||
};
|
||||
|
||||
normalModuleFactory.hooks.parser
|
||||
|
@ -825,8 +823,8 @@ class DefinePlugin {
|
|||
}
|
||||
};
|
||||
|
||||
walkDefinitionsForKeys(definitions);
|
||||
walkDefinitionsForValues(definitions, "");
|
||||
walkDefinitionsForKeys(this.definitions);
|
||||
walkDefinitionsForValues(this.definitions, "");
|
||||
|
||||
compilation.valueCacheVersions.set(
|
||||
VALUE_DEP_MAIN,
|
||||
|
|
|
@ -251,7 +251,7 @@ const getEnvFilesForMode = (inputFileSystem, dir, mode) => {
|
|||
* @param {Record<string, string>} env environment variables
|
||||
* @returns {Record<string, string>} formatted definitions
|
||||
*/
|
||||
const formatDefinitions = (env) => {
|
||||
const envToDefinitions = (env) => {
|
||||
const definitions = /** @type {Record<string, string>} */ ({});
|
||||
|
||||
for (const [key, value] of Object.entries(env)) {
|
||||
|
@ -278,8 +278,10 @@ class DotenvPlugin {
|
|||
apply(compiler) {
|
||||
/** @type {string[] | undefined} */
|
||||
let fileDependenciesCache;
|
||||
const definePlugin = new compiler.webpack.DefinePlugin({});
|
||||
definePlugin.apply(compiler);
|
||||
|
||||
compiler.hooks.beforeCompile.tapAsync(PLUGIN_NAME, (_params, callback) => {
|
||||
compiler.hooks.beforeRun.tapAsync(PLUGIN_NAME, (_params, callback) => {
|
||||
const inputFileSystem = /** @type {InputFileSystem} */ (
|
||||
compiler.inputFileSystem
|
||||
);
|
||||
|
@ -296,10 +298,8 @@ class DotenvPlugin {
|
|||
(err, env, fileDependencies) => {
|
||||
if (err) return callback(err);
|
||||
|
||||
const definitions = formatDefinitions(env || {});
|
||||
const DefinePlugin = compiler.webpack.DefinePlugin;
|
||||
|
||||
new DefinePlugin(definitions).apply(compiler);
|
||||
const definitions = envToDefinitions(env || {});
|
||||
definePlugin.definitions = definitions;
|
||||
fileDependenciesCache = fileDependencies;
|
||||
|
||||
callback();
|
||||
|
|
Loading…
Reference in New Issue