ソースを参照

fix: vite dev read scss source bug

richard1015 3 年 前
コミット
c03d94fd0b

+ 7 - 1
jd/generate-themes-dev.js

@@ -10,7 +10,7 @@ config.nav.map((item) => {
       fs
         .copy(
           path.resolve(__dirname, `../src/packages/__VUE/${folderName}/index.scss`),
-          path.resolve(__dirname, `../dist/theme/source/packages/${folderName}/index.scss`)
+          path.resolve(__dirname, `../dist/theme/source/packages/${folderName}/index.scss_source`)
         )
         .then((success) => {
           fileStr += `@import '../../packages/${folderName}/index.scss';\n`;
@@ -23,6 +23,12 @@ config.nav.map((item) => {
 tasks.push(
   fs.copy(path.resolve(__dirname, '../src/packages/styles'), path.resolve(__dirname, '../dist/theme/source/styles'))
 );
+tasks.push(
+  fs.copy(
+    path.resolve(__dirname, '../src/packages/styles/variables.scss'),
+    path.resolve(__dirname, '../dist/theme/source/styles/variables.scss_source')
+  )
+);
 
 Promise.all(tasks).then((res) => {
   fs.outputFile(

+ 2 - 2
src/sites/doc/components/ThemeSetting/helper.ts

@@ -130,7 +130,7 @@ const store: Store = reactive({
 
 const getSassVariables = async () => {
   // vite 启动模式 bug 待修复
-  const rawVariablesText = await getRawFileText(`${config.themeUrl}/styles/variables.scss`);
+  const rawVariablesText = await getRawFileText(`${config.themeUrl}/styles/variables.scss_source`);
   const rawVariables = parseSassVariables(rawVariablesText, components);
 
   // 固定自定义主题的访问链接: https://nutui.jd.com/theme/?theme=自定义变量的文件地址#/
@@ -161,7 +161,7 @@ const getSassVariables = async () => {
 
 export const getRawSassStyle = async (name: string): Promise<void> => {
   if (!store.rawStyles[name]) {
-    const style = await getRawFileText(`${config.themeUrl}/packages/${name}/index.scss`);
+    const style = await getRawFileText(`${config.themeUrl}/packages/${name}/index.scss_source`);
     store.rawStyles[name] = style;
   }
 };