From acb8280115f7e127e3d5d510050fa9cd703d7f73 Mon Sep 17 00:00:00 2001 From: cap-Bernardito Date: Tue, 20 Jul 2021 18:45:07 +0300 Subject: [PATCH] fix: styletagtransform function path added to builddependensies --- src/utils.js | 2 ++ .../styleTagTransform-option.test.js.snap | 26 +++++++++++++++++++ test/styleTagTransform-option.test.js | 19 ++++++++++++++ 3 files changed, 47 insertions(+) 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"); + }); });