build(vscode-ide-companion): 添加 SCSS 支持

- 在 esbuild.js 中添加 SCSS 文件处理逻辑
- 在 package.json 中添加 sass 依赖
- 新增代码使用 sass 编译 SCSS 文件,并将其注入到页面中
This commit is contained in:
yiliang114
2025-11-19 23:34:05 +08:00
parent bc2b503e8d
commit 018990b7f6
6 changed files with 595 additions and 13 deletions

View File

@@ -37,6 +37,7 @@ const esbuildProblemMatcherPlugin = {
const cssInjectPlugin = {
name: 'css-inject',
setup(build) {
// Handle CSS files
build.onLoad({ filter: /\.css$/ }, async (args) => {
const fs = await import('fs');
const css = await fs.promises.readFile(args.path, 'utf8');
@@ -49,6 +50,23 @@ const cssInjectPlugin = {
loader: 'js',
};
});
// Handle SCSS files
build.onLoad({ filter: /\.scss$/ }, async (args) => {
const sass = await import('sass');
const result = sass.compile(args.path, {
loadPaths: [args.path.substring(0, args.path.lastIndexOf('/'))],
});
const css = result.css;
return {
contents: `
const style = document.createElement('style');
style.textContent = ${JSON.stringify(css)};
document.head.appendChild(style);
`,
loader: 'js',
};
});
},
};