Skip to content

Commit 4ecd231

Browse files
committed
fix: workaround assets ordering by providing a manully ordering array
1 parent 5aba200 commit 4ecd231

File tree

3 files changed

+46
-9
lines changed

3 files changed

+46
-9
lines changed

Diff for: lib/vite-helpers.js

+37
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ const path = require('path')
33

44
let manifest = null
55

6+
// Configuration for manual CSS ordering
7+
const CSS_ORDER_CONFIG = {
8+
cover: [
9+
'bootstrap',
10+
'site',
11+
'cover'
12+
],
13+
// Add other entry points and their CSS orders as needed
14+
index: [
15+
'bootstrap',
16+
'slide-preview',
17+
'extra',
18+
'site',
19+
'index'
20+
]
21+
};
22+
623
// Read manifest in production
724
// In development, Vite handles asset injection via its dev server middleware
825
function readManifest () {
@@ -47,6 +64,26 @@ function getViteAssets(entryName) {
4764
assets.js.push(`/.vite/public/js/${entryName}.js`);
4865
}
4966

67+
// Apply manual CSS ordering if configured
68+
if (CSS_ORDER_CONFIG[entryName]) {
69+
const orderedCss = [];
70+
CSS_ORDER_CONFIG[entryName].forEach(cssChunkName => {
71+
const matchingCss = assets.css.find(css => css.includes(cssChunkName));
72+
if (matchingCss) {
73+
orderedCss.push(matchingCss);
74+
} else {
75+
console.warn(`Configured CSS chunk not found: ${cssChunkName} for entry: ${entryName}`);
76+
}
77+
});
78+
// Add any remaining CSS assets not specified in the config
79+
assets.css.forEach(css => {
80+
if (!orderedCss.includes(css)) {
81+
orderedCss.push(css);
82+
}
83+
});
84+
assets.css = orderedCss;
85+
}
86+
5087
return assets;
5188
}
5289

Diff for: public/js/cover.js

+8-8
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33

44
import 'bootstrap'
55

6+
import 'fork-awesome/css/fork-awesome.min.css'
7+
import 'bootstrap/dist/css/bootstrap.min.css'
8+
import 'select2/select2.css'
9+
import 'select2/select2-bootstrap.css'
10+
11+
import '@css/cover.css'
12+
import '@css/site.css'
13+
614
import {
715
checkIfAuth,
816
clearLoginState,
@@ -30,16 +38,8 @@ import List from 'list.js'
3038
import { unescape as unescapeHTML } from 'lodash'
3139
import 'select2/select2.js'
3240

33-
import 'fork-awesome/css/fork-awesome.min.css'
34-
import 'bootstrap/dist/css/bootstrap.min.css'
35-
import 'select2/select2.css'
36-
import 'select2/select2-bootstrap.css'
37-
3841
import './locale'
3942

40-
import '@css/cover.css'
41-
import '@css/site.css'
42-
4343
const options = {
4444
valueNames: ['id', 'text', 'timestamp', 'fromNow', 'time', 'tags', 'pinned'],
4545
item: `<li class="col-xs-12 col-sm-6 col-md-6 col-lg-4">

Diff for: vite.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ export default defineConfig({
140140
pretty: path.resolve(__dirname, 'public/js/pretty.js'),
141141
slide: path.resolve(__dirname, 'public/js/slide.js')
142142
},
143-
external: [/\.html$/]
143+
external: [/\.html$/],
144144
}
145145
},
146146
// Define global constants like webpack DefinePlugin (if needed)

0 commit comments

Comments
 (0)