I have simple scss file in my project directory and I wanna get it's content on the piling stage so I could transform in on vite.config.js but how can I get it's content? I mean I'm able to get content using
import test from "./src/extensions/sites/noscript/test.css";
console.log(test);
in App.vue but that doesn't work in vite.config.js (that works with webpack) Is there any ways to get file content? test == {} when I'm debugging... vite.config.js and works well in App.vue
I have simple scss file in my project directory and I wanna get it's content on the piling stage so I could transform in on vite.config.js but how can I get it's content? I mean I'm able to get content using
import test from "./src/extensions/sites/noscript/test.css";
console.log(test);
in App.vue but that doesn't work in vite.config.js (that works with webpack) Is there any ways to get file content? test == {} when I'm debugging... vite.config.js and works well in App.vue
Share Improve this question edited Aug 14, 2022 at 0:26 tony19 139k23 gold badges277 silver badges347 bronze badges asked Aug 14, 2022 at 0:20 GorilkaGorilka 5146 silver badges21 bronze badges1 Answer
Reset to default 6vite.config.js
is run as a Node script, so you could use fs.readFileSync()
to read the file from disk into a string:
// vite.config.js
import fs from 'fs'
const styleRaw = fs.readFileSync('./src/extensions/sites/noscript/test.css', 'utf-8')
console.log(styleRaw)
demo