diff --git a/src/utils.js b/src/utils.js
index 8d08259f..4c26b512 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -314,6 +314,8 @@ function getStyleTagTransformFnCode(
`${options.styleTagTransform}`
);
+ loaderContext.addBuildDependency(options.styleTagTransform);
+
return esModule
? `import styleTagTransformFn from ${modulePath};`
: `var styleTagTransformFn = require(${modulePath});`;
diff --git a/test/__snapshots__/styleTagTransform-option.test.js.snap b/test/__snapshots__/styleTagTransform-option.test.js.snap
index bdbaebd2..13b953cd 100644
--- a/test/__snapshots__/styleTagTransform-option.test.js.snap
+++ b/test/__snapshots__/styleTagTransform-option.test.js.snap
@@ -1,5 +1,31 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`"styleTagTransform" option should "styleTagTransform" function path added to buildDependencies when injectType lazyStyleTag: DOM 1`] = `
+"
+ style-loader test
+
+
+
+ Body
+
+
+
+
+"
+`;
+
+exports[`"styleTagTransform" option should "styleTagTransform" function path added to buildDependencies when injectType lazyStyleTag: errors 1`] = `Array []`;
+
+exports[`"styleTagTransform" option should "styleTagTransform" function path added to buildDependencies when injectType lazyStyleTag: warnings 1`] = `Array []`;
+
exports[`"styleTagTransform" option should work when the "styleTagTransform" option is not specify and injectType lazyStyleTag: DOM 1`] = `
"
style-loader test
diff --git a/test/styleTagTransform-option.test.js b/test/styleTagTransform-option.test.js
index 4938032a..2474d0f5 100644
--- a/test/styleTagTransform-option.test.js
+++ b/test/styleTagTransform-option.test.js
@@ -99,4 +99,23 @@ describe('"styleTagTransform" option', () => {
expect(getWarnings(stats)).toMatchSnapshot("warnings");
expect(getErrors(stats)).toMatchSnapshot("errors");
});
+
+ it(`should "styleTagTransform" function path added to buildDependencies when injectType lazyStyleTag`, async () => {
+ const styleTagTransformFn = require.resolve("./fixtures/styleTagTransform");
+ const entry = getEntryByInjectType("simple.js", "lazyStyleTag");
+ const compiler = getCompiler(entry, {
+ injectType: "lazyStyleTag",
+ styleTagTransform: styleTagTransformFn,
+ });
+ const stats = await compile(compiler);
+ const { buildDependencies } = stats.compilation;
+
+ runInJsDom("main.bundle.js", compiler, stats, (dom) => {
+ expect(dom.serialize()).toMatchSnapshot("DOM");
+ });
+
+ expect(buildDependencies.has(styleTagTransformFn)).toBe(true);
+ expect(getWarnings(stats)).toMatchSnapshot("warnings");
+ expect(getErrors(stats)).toMatchSnapshot("errors");
+ });
});