Hướng dẫn vite css modules typescript - vite css mô-đun bản thảo
j1ngzoue Đăng vào ngày 15 tháng 10 năm 2021 • Cập nhật vào ngày 21 tháng 5 Giới thiệuBạn có thể kiểm tra ví dụ được giới thiệu ở đây. Khi phát triển với các mô-đun React và CSS, bạn có thể thấy rằng phần kiểu dáng không an toàn. Giới thiệu một phương pháp kiểu dáng an toàn hơn. Với mục đích đó, tôi đã tạo hai thư viện, vì vậy tôi sẽ giới thiệu chúng.
Cài đặt
Nhập chế độ FullScreenen EXIT Mode FullScreen Đặt plugin trong tệp vite.config.tsimport { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import sassDts from "vite-plugin-sass-dts";
import path from "path";
export default defineConfig({
css: {
preprocessorOptions: {
scss: {
additionalData: `@use "@/styles" as common;`,
importer(...args) {
if (args[0] !== "@/styles") {
return;
}
return {
file: `${path.resolve(
__dirname,
"./src/assets/styles"
)}`,
};
},
},
},
},
plugins: [
react(),
sassDts({
allGenerate: true,
global: {
generate: true,
outFile: path.resolve(__dirname, "./src/style.d.ts"),
},
}),
],
});
|