Skip to content

Commit 270513f

Browse files
authoredJul 20, 2021
fix: added the styletagtransform option when it is a module to addBuildDependency (#528)
1 parent a0ee2e0 commit 270513f

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed
 

‎src/utils.js

+2
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,8 @@ function getStyleTagTransformFnCode(
314314
`${options.styleTagTransform}`
315315
);
316316

317+
loaderContext.addBuildDependency(options.styleTagTransform);
318+
317319
return esModule
318320
? `import styleTagTransformFn from ${modulePath};`
319321
: `var styleTagTransformFn = require(${modulePath});`;

‎test/__snapshots__/styleTagTransform-option.test.js.snap

+26
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,31 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`"styleTagTransform" option should "styleTagTransform" function path added to buildDependencies when injectType lazyStyleTag: DOM 1`] = `
4+
"<!DOCTYPE html><html><head>
5+
<title>style-loader test</title>
6+
<style id=\\"existing-style\\">.existing { color: yellow }</style>
7+
<style>body {
8+
color: red;
9+
}
10+
.modify{}
11+
</style><style>h1 {
12+
color: blue;
13+
}
14+
.modify{}
15+
</style></head>
16+
<body>
17+
<h1>Body</h1>
18+
<div class=\\"target\\"></div>
19+
<iframe class=\\"iframeTarget\\"></iframe>
20+
21+
22+
</body></html>"
23+
`;
24+
25+
exports[`"styleTagTransform" option should "styleTagTransform" function path added to buildDependencies when injectType lazyStyleTag: errors 1`] = `Array []`;
26+
27+
exports[`"styleTagTransform" option should "styleTagTransform" function path added to buildDependencies when injectType lazyStyleTag: warnings 1`] = `Array []`;
28+
329
exports[`"styleTagTransform" option should work when the "styleTagTransform" option is not specify and injectType lazyStyleTag: DOM 1`] = `
430
"<!DOCTYPE html><html><head>
531
<title>style-loader test</title>

‎test/styleTagTransform-option.test.js

+19
Original file line numberDiff line numberDiff line change
@@ -99,4 +99,23 @@ describe('"styleTagTransform" option', () => {
9999
expect(getWarnings(stats)).toMatchSnapshot("warnings");
100100
expect(getErrors(stats)).toMatchSnapshot("errors");
101101
});
102+
103+
it(`should "styleTagTransform" function path added to buildDependencies when injectType lazyStyleTag`, async () => {
104+
const styleTagTransformFn = require.resolve("./fixtures/styleTagTransform");
105+
const entry = getEntryByInjectType("simple.js", "lazyStyleTag");
106+
const compiler = getCompiler(entry, {
107+
injectType: "lazyStyleTag",
108+
styleTagTransform: styleTagTransformFn,
109+
});
110+
const stats = await compile(compiler);
111+
const { buildDependencies } = stats.compilation;
112+
113+
runInJsDom("main.bundle.js", compiler, stats, (dom) => {
114+
expect(dom.serialize()).toMatchSnapshot("DOM");
115+
});
116+
117+
expect(buildDependencies.has(styleTagTransformFn)).toBe(true);
118+
expect(getWarnings(stats)).toMatchSnapshot("warnings");
119+
expect(getErrors(stats)).toMatchSnapshot("errors");
120+
});
102121
});

0 commit comments

Comments
 (0)
Please sign in to comment.