Skip to content

Commit 770e559

Browse files
committed
test: refactor the test case hook-beforeEmit-rtlcss
1 parent 6f130e2 commit 770e559

1 file changed

Lines changed: 16 additions & 15 deletions

File tree

test/cases/hook-beforeEmit-rtlcss/webpack.config.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ module.exports = {
4141
// explain the structure of the `entry` object
4242
//console.dir({ hook: 'beforeEmit', entry }, { depth: 5 });
4343

44+
let linkTags = '';
45+
4446
entry.assets.forEach((asset) => {
4547
const { type, assetFile, inline } = asset;
4648

@@ -53,26 +55,25 @@ module.exports = {
5355
if (!inline) {
5456
// add new CSS file into compilation
5557
compilation.assets[rtlAssetFile] = new RawSource(rtlResult);
56-
57-
// find inject pos: after the last <link> tag
58-
// TODO: implement your logic to find an inject pos
59-
let pos = content.lastIndexOf('<link');
60-
if (pos > -1) {
61-
let injectPos = content.indexOf('>', pos);
62-
// inject the style tag with rtl CSS into HTML
63-
if (injectPos > -1) {
64-
injectPos++;
65-
content =
66-
content.slice(0, injectPos) +
67-
`<link href="${rtlAssetFile}" rel="stylesheet" />` +
68-
content.slice(injectPos);
69-
}
70-
}
58+
linkTags += `<link href="${rtlAssetFile}" rel="stylesheet" />`;
7159
} else {
7260
// TODO: if CSS asset is inlined inject the <style> tag into HTML
7361
}
7462
});
7563

64+
if (linkTags) {
65+
// find inject pos: after the last <link> tag
66+
// TODO: implement your logic to find an inject pos
67+
let pos = content.lastIndexOf('<link');
68+
if (pos > -1) {
69+
let injectPos = content.indexOf('>', pos) + 1;
70+
if (injectPos > 0) {
71+
// inject style tags with rtl CSS into HTML
72+
content = content.slice(0, injectPos) + linkTags + content.slice(injectPos);
73+
}
74+
}
75+
}
76+
7677
return content;
7778
});
7879
});

0 commit comments

Comments
 (0)