Quellcode durchsuchen

Fix scss charset warning in vite (#411)

* fix: disable charset auto inject

* chore: format code
代强 vor 3 Jahren
Ursprung
Commit
1966eb0c3e

+ 21 - 15
packages/semi-scss-compile/src/bin.ts

@@ -1,27 +1,33 @@
 #!/usr/bin/env node
 
-import arg from "arg";
-import { compile } from "./index";
+import arg from 'arg';
+import { compile } from './index';
 
 const main = () => {
     const userArgs = arg({
-        "--foundation": String,
-        "--theme": String,
-        "--output": String,
-        "--icon":String,
-        "--min": Boolean,
+        '--foundation': String,
+        '--theme': String,
+        '--output': String,
+        '--icon': String,
+        '--min': Boolean,
 
-        "-f": "--foundation",
-        "-t": "--theme",
-        "-i":"--icon",
-        "-o": "--output",
-        "-m": "--min"
-    }, {permissive: true});
-    const {"--foundation": foundationPath, '--theme': themePath, '--output': outputPath,'--icon':iconPath,'--min': isMin} = userArgs;
+        '-f': '--foundation',
+        '-t': '--theme',
+        '-i': '--icon',
+        '-o': '--output',
+        '-m': '--min'
+    }, { permissive: true });
+    const {
+        '--foundation': foundationPath,
+        '--theme': themePath,
+        '--output': outputPath,
+        '--icon': iconPath,
+        '--min': isMin
+    } = userArgs;
     console.log(`foundationPath: ${foundationPath},\nthemePath: ${themePath},\noutputPath: ${outputPath}\n`);
     if (foundationPath && themePath && iconPath && outputPath) {
         compile({
-            foundationPath,themePath,iconPath,outputPath,isMin
+            foundationPath, themePath, iconPath, outputPath, isMin
         });
     } else {
         console.error('Error: lack of args.');

+ 6 - 6
packages/semi-scss-compile/src/index.ts

@@ -1,7 +1,7 @@
-import generateScssMap from "./utils/generateSCSSMap";
-import writeFile from "./utils/writeFile";
-import compilerFromScssMap from "./utils/compiler";
-import path from "path";
+import generateScssMap from './utils/generateSCSSMap';
+import writeFile from './utils/writeFile';
+import compilerFromScssMap from './utils/compiler';
+import path from 'path';
 import fs from 'fs-extra';
 
 
@@ -13,9 +13,9 @@ export interface Options {
     isMin?: boolean,
 }
 
-const compile = ({foundationPath, themePath, iconPath, outputPath, isMin = false}: Options) => {
+const compile = ({ foundationPath, themePath, iconPath, outputPath, isMin = false }: Options) => {
     const scssMap = generateScssMap(foundationPath, themePath, iconPath);
-    const tempDir = writeFile(scssMap)
+    const tempDir = writeFile(scssMap);
     const result = compilerFromScssMap(path.join(tempDir, 'index.scss'), isMin);
     fs.outputFileSync(outputPath, result.css);
 };

+ 5 - 1
packages/semi-scss-compile/src/utils/compiler.ts

@@ -2,7 +2,11 @@ import sass from 'sass';
 
 
 const compile = (entryScssPath: string, isMin: boolean = false) => {
-    const result = sass.renderSync({ file: entryScssPath, outputStyle: isMin ? 'compressed' : 'expanded' });
+    const result = sass.renderSync({
+        file: entryScssPath,
+        outputStyle: isMin ? 'compressed' : 'expanded',
+        charset: false
+    });
     return result;
 };
 

+ 2 - 2
packages/semi-scss-compile/src/utils/generateSCSSMap.ts

@@ -1,5 +1,5 @@
 import path from 'path';
-import fs from "fs-extra";
+import fs from 'fs-extra';
 import { set } from 'lodash';
 
 const lodash = { set };
@@ -44,7 +44,7 @@ const generateThemeScssMap = (themePath: string) => {
         const scssAbsolutePath = path.join(themePath, 'scss', fileName);
         if (fs.existsSync(scssAbsolutePath)) {
             //in theme folder
-            themeScssMap[fileName] = fs.readFileSync(scssAbsolutePath, { encoding: "utf8" });
+            themeScssMap[fileName] = fs.readFileSync(scssAbsolutePath, { encoding: 'utf8' });
         }
     }
     // console.log(themeScssMap)

+ 9 - 9
packages/semi-scss-compile/src/utils/writeFile.ts

@@ -1,8 +1,8 @@
 import fs from 'fs-extra';
 import path from 'path';
 import os from 'os';
-import generateScssMap from "./generateSCSSMap";
-import { cloneDeep, omit } from "lodash";
+import generateScssMap from './generateSCSSMap';
+import { cloneDeep, omit } from 'lodash';
 
 const lodash = { cloneDeep, omit };
 
@@ -22,7 +22,7 @@ const writeThemeScss = (scssMap: (ReturnType<typeof generateScssMap>)['theme'],
     fs.emptyDirSync(themeDirPath);
 
     for (const scssFileName of Object.keys(scssMap)) {
-        fs.writeFileSync(path.join(themeDirPath, scssFileName), scssMap[scssFileName as keyof typeof scssMap] as string, { encoding: "utf8" });
+        fs.writeFileSync(path.join(themeDirPath, scssFileName), scssMap[scssFileName as keyof typeof scssMap] as string, { encoding: 'utf8' });
     }
     return;
 };
@@ -52,11 +52,11 @@ const preProcessScssMap = (scssMapOrigin: ReturnType<typeof generateScssMap>) =>
 
 
     //----- inject component token file local.scss to component's variables.scss -----
-    const themeLocalRaw = scssMap.theme["local.scss"];
+    const themeLocalRaw = scssMap.theme['local.scss'];
     if (themeLocalRaw) {
         for (const componentName of Object.keys(scssMap['components'])) {
-            if (scssMap["components"][componentName]['variables.scss']) {
-                scssMap["components"][componentName]['variables.scss'] += `\n\n\n\n//inject custom theme variables\n${themeLocalRaw}`;
+            if (scssMap['components'][componentName]['variables.scss']) {
+                scssMap['components'][componentName]['variables.scss'] += `\n\n\n\n//inject custom theme variables\n${themeLocalRaw}`;
             }
         }
     }
@@ -64,7 +64,7 @@ const preProcessScssMap = (scssMapOrigin: ReturnType<typeof generateScssMap>) =>
 
     return {
         ...{
-            components: scssMap["components"],
+            components: scssMap['components'],
             theme: lodash.omit(scssMap['theme'], 'local.scss')
         },
         index: compilerEntryContent
@@ -76,10 +76,10 @@ const writeFile = (scssMap: ReturnType<typeof generateScssMap>, tempDir: string
     fs.emptyDirSync(tempDir);
 
     const finalScssMapWaitForCompiling = preProcessScssMap(scssMap);
-    writeComponentScss(finalScssMapWaitForCompiling["components"], tempDir);
+    writeComponentScss(finalScssMapWaitForCompiling['components'], tempDir);
     writeThemeScss(finalScssMapWaitForCompiling['theme'], tempDir);
     //write compile entry
-    fs.writeFileSync(path.join(tempDir, 'index.scss'), finalScssMapWaitForCompiling['index'], { encoding: "utf8" });
+    fs.writeFileSync(path.join(tempDir, 'index.scss'), finalScssMapWaitForCompiling['index'], { encoding: 'utf8' });
     return tempDir;
 };