Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: styleTagTransform function path added to buildDependencies #528

Merged
merged 1 commit into from Jul 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/utils.js
Expand Up @@ -314,6 +314,8 @@ function getStyleTagTransformFnCode(
`${options.styleTagTransform}`
);

loaderContext.addBuildDependency(options.styleTagTransform);

return esModule
? `import styleTagTransformFn from ${modulePath};`
: `var styleTagTransformFn = require(${modulePath});`;
Expand Down
26 changes: 26 additions & 0 deletions 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`] = `
"<!DOCTYPE html><html><head>
<title>style-loader test</title>
<style id=\\"existing-style\\">.existing { color: yellow }</style>
<style>body {
color: red;
}
.modify{}
</style><style>h1 {
color: blue;
}
.modify{}
</style></head>
<body>
<h1>Body</h1>
<div class=\\"target\\"></div>
<iframe class=\\"iframeTarget\\"></iframe>


</body></html>"
`;

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`] = `
"<!DOCTYPE html><html><head>
<title>style-loader test</title>
Expand Down
19 changes: 19 additions & 0 deletions test/styleTagTransform-option.test.js
Expand Up @@ -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");
});
});