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