Skip to content

Commit f6574d5

Browse files
committed
initial support for fetching rtl based on window variable
1 parent 50434b5 commit f6574d5

File tree

5 files changed

+15
-5
lines changed

5 files changed

+15
-5
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"test:only": "cross-env NODE_ENV=test jest",
2828
"test:watch": "cross-env NODE_ENV=test jest --watch",
2929
"test:coverage": "cross-env NODE_ENV=test jest --collectCoverageFrom=\"src/**/*.js\" --coverage",
30-
"test:manual": "webpack-dev-server test/manual/src/index.js --open --config test/manual/webpack.config.js",
30+
"test:manual": "webpack-dev-server test/manual/src/index.js --config test/manual/webpack.config.js",
3131
"pretest": "npm run lint",
3232
"test": "cross-env NODE_ENV=test npm run test:coverage",
3333
"defaults": "webpack-defaults"

src/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ class MiniCssExtractPlugin {
325325
source,
326326
'',
327327
`// ${pluginName} CSS loading`,
328+
`var fetchRTL = !!window['${this.options.globalRTLFlag}'];`,
328329
`var cssChunks = ${JSON.stringify(chunkMap)};`,
329330
'if(installedCssChunks[chunkId]) promises.push(installedCssChunks[chunkId]);',
330331
'else if(installedCssChunks[chunkId] !== 0 && cssChunks[chunkId]) {',
@@ -333,6 +334,11 @@ class MiniCssExtractPlugin {
333334
Template.indent([
334335
`var href = ${linkHrefPath};`,
335336
`var fullhref = ${mainTemplate.requireFn}.p + href;`,
337+
'if (fetchRTL) {',
338+
Template.indent([
339+
`fullhref = fullhref.replace(/\\.css/i, '.rtl.css');`,
340+
]),
341+
'}',
336342
'var existingLinkTags = document.getElementsByTagName("link");',
337343
'for(var i = 0; i < existingLinkTags.length; i++) {',
338344
Template.indent([

src/options.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
"instanceof": "Function"
1111
}
1212
]
13+
},
14+
"globalRTLFlag": {
15+
"type": "string"
1316
}
1417
},
1518
"errorMessages": {

test/manual/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<meta http-equiv="X-UA-Compatible" content="IE=edge">
66
<title>mini-css-extract-plugin testcase</title>
77
<meta name="viewport" content="width=device-width, initial-scale=1">
8-
<link rel="stylesheet" type="text/css" href="/dist/preloaded1.css" />
8+
<link rel="stylesheet" type="text/css" href="/dist/preloaded1.client.css" />
99
<style>
1010
.test {
1111
background: lightcoral;
@@ -23,7 +23,7 @@
2323
background: lightgreen;
2424
}
2525
</style>
26-
<link rel="stylesheet" type="text/css" href="/dist/main.css" />
26+
<link rel="stylesheet" type="text/css" href="/dist/main.client.css" />
2727
</head>
2828
<body>
2929
<div class="test initial-css">

test/manual/webpack.config.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ module.exports = {
1717
},
1818
plugins: [
1919
new Self({
20-
filename: '[name].css',
21-
chunkFilename: '[contenthash].css',
20+
filename: '[name].client.css',
21+
chunkFilename: '[name].chunk.client.css',
22+
globalRTLFlag: 'rtlLanguageEnabled',
2223
}),
2324
],
2425
devServer: {

0 commit comments

Comments
 (0)