Skip to content

Commit cbc47ca

Browse files
chohongmbang9
andauthored
fix: Move import statements to the top of extracted index.css file. (#1085)
Fixes: [CLNP-3084](https://sendbird.atlassian.net/browse/CLNP-3084) ### Changelogs - Fixed a bug where import statements are not located at the top of the extracted index.css file [CLNP-3084]: https://sendbird.atlassian.net/browse/CLNP-3084?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ --------- Co-authored-by: Hyungu Kang | Airen <gusrn1423@naver.com>
1 parent 9979c4c commit cbc47ca

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

rollup.config.mjs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import ts2 from "rollup-plugin-typescript2"
1414
// config from package.json
1515
import pkg from "./package.json" assert {type: "json"};
1616
import inputs from "./rollup.module-exports.mjs";
17+
import { readFileSync, writeFileSync } from 'fs';
1718

1819
const APP_VERSION_STRING = "__react_dev_mode__";
1920

@@ -57,10 +58,45 @@ export default {
5758
resolvecss({ code: result.css.toString() });
5859
}),
5960
plugins: [autoprefixer],
60-
sourceMap: true,
61+
sourceMap: false,
6162
extract: "dist/index.css",
6263
extensions: [".sass", ".scss", ".css"],
6364
}),
65+
{
66+
name: 'postcss-single-file',
67+
async writeBundle(outputOptions, bundle) {
68+
// Path to your CSS file
69+
const cssFilePath = './dist/dist/index.css';
70+
71+
try {
72+
// Read the content of the CSS file
73+
const cssContent = readFileSync(cssFilePath, 'utf-8');
74+
75+
// Split the content into lines
76+
const lines = cssContent.split('\n');
77+
78+
// Find lines starting with @import
79+
const importLines = [];
80+
const otherLines = [];
81+
lines.forEach(line => {
82+
if (line.trim().startsWith('@import')) {
83+
importLines.push(line);
84+
} else {
85+
otherLines.push(line);
86+
}
87+
});
88+
// Combine import lines and other lines
89+
const modifiedContent = importLines.join('\n') + '\n' + otherLines.join('\n');
90+
91+
// Write the modified content back to the file
92+
writeFileSync(cssFilePath, modifiedContent);
93+
94+
console.log('Moved @import lines to the top of the CSS file successfully.');
95+
} catch (error) {
96+
console.error('Error occurred while moving @import lines to the top of the CSS file:', error);
97+
}
98+
},
99+
},
64100
replace({
65101
preventAssignment: false,
66102
exclude: "node_modules/**",

0 commit comments

Comments
 (0)