解決vite構(gòu)建庫模式和 es 格式中css樣式加載問題(也可單獨(dú)在組件下引入)
1.當(dāng)使用vite構(gòu)建庫模式或es格式組件,組件樣式需單獨(dú)引入否則組件是沒有css樣式的
<style>
@import "/package/subassembly/css/style.css";
//掛載組件樣式
//掛載組件樣式
</style>
注:如果同一個項目使用多個組件,引入的CSS樣式名相同會導(dǎo)致CSS樣式來回覆蓋導(dǎo)致錯誤文章來源地址http://www.zghlxwxcb.cn/news/detail-777554.html
2.可以使用vite-plugin-libcss插件(推薦)鏈接:
3. 安裝
//裝置
npm i vite-plugin-libcss -D
4. 用法
// vite.config.js
import libCss from 'vite-plugin-libcss';
// https://vitejs.dev/config/
export default defineConfig({
plugins: [
// any other plugins
libCss()
],
build: {
cssCodeSplit:true,
}
});
文章來源:http://www.zghlxwxcb.cn/news/detail-777554.html
到了這里,關(guān)于解決vite構(gòu)建庫模式和 es 格式中css樣式加載問題(也可單獨(dú)在組件下引入)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!