소스 검색

移除自定义文件工具并替换为外部库

移除了 `src/utils/file.js` 文件,并在 `webpack_config_*` 配置文件中将自定义文件工具替换为 `huan-file-tool` 库,以简化项目依赖和代码维护。同时更新了 `package.json` 以添加新依赖并升级版本号。
SongZihuan 3 달 전
부모
커밋
f17bf7fb14
5개의 변경된 파일11개의 추가작업 그리고 55개의 파일을 삭제
  1. 2 1
      package.json
  2. 0 45
      src/utils/file.js
  3. 3 3
      webpack_config_dev.js
  4. 3 3
      webpack_config_github.js
  5. 3 3
      webpack_config_prod.js

+ 2 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "huan-simple-html",
-  "version": "1.1.0",
+  "version": "1.1.1",
   "description": "一个简单的HTML项目,通过Webpack进行打包。请尽量使用pnpm处理此包。更多细节请查看\"README.md\"",
   "keywords": [
     "html",
@@ -55,6 +55,7 @@
     "file-loader": "^6.2.0",
     "html-loader": "^5.1.0",
     "html-webpack-plugin": "^5.6.3",
+    "huan-file-tool": "^1.0.5",
     "jquery": "^3.7.1",
     "mini-css-extract-plugin": "^2.9.2",
     "normalize.css": "^8.0.1",

+ 0 - 45
src/utils/file.js

@@ -1,45 +0,0 @@
-import path from 'path'
-import fs from 'fs'
-
-export default {
-  getAllFilePaths
-}
-
-export function getAllFilePaths(dir) {
-  return _getAllFilePaths(dir, './', 5)
-}
-
-function _getAllFilePaths(filePath, localpath, deep) {
-  if (deep === 0) {
-    return [], []
-  }
-
-  let filePathResult = []
-  let localPathResult = []
-
-  // 读取目录中的所有文件和子目录
-  fs.readdirSync(filePath).forEach(function (file) {
-    const newFilePath = path.join(filePath, file)
-    const newLocalPath = path.join(localpath, file)
-
-    // 如果是目录,则递归读取该目录下的文件
-    if (fs.statSync(newFilePath).isDirectory()) {
-      const { filePathResult: _filrPath, localPathResult: _localPath } = _getAllFilePaths(
-        newFilePath,
-        newLocalPath,
-        deep - 1
-      )
-      filePathResult = filePathResult.concat(_filrPath)
-      localPathResult = localPathResult.concat(_localPath)
-    } else {
-      // 如果是文件,则直接加入结果数组
-      filePathResult.push(newFilePath)
-      localPathResult.push(newLocalPath)
-    }
-  })
-
-  return {
-    filePathResult,
-    localPathResult
-  }
-}

+ 3 - 3
webpack_config_dev.js

@@ -2,7 +2,7 @@ import path from 'path'
 import HtmlWebpackPlugin from 'html-webpack-plugin'
 import MiniCssExtractPlugin from 'mini-css-extract-plugin'
 import CopyWebpackPlugin from 'copy-webpack-plugin'
-import filetool from './src/utils/file.js'
+import filetool from 'huan-file-tool'
 import { fileURLToPath } from 'url'
 
 const __filename = fileURLToPath(import.meta.url)
@@ -13,7 +13,7 @@ const dist_name = 'dist-dev'
 
 const HTMMLPlugin = []
 
-const { localPathResult: AllHTMLLocalFile4xx } = filetool.getAllFilePaths(path.resolve(__dirname, 'src/html/error/4xx'))
+const { localPathResult: AllHTMLLocalFile4xx } = filetool.filewaalk.getAllFilePaths(path.resolve(__dirname, 'src/html/error/4xx'))
 AllHTMLLocalFile4xx.forEach((filePath) => {
   if (!filePath.endsWith('.html')) {
     return
@@ -56,7 +56,7 @@ AllHTMLLocalFile4xx.forEach((filePath) => {
   )
 })
 
-const { localPathResult: AllHTMLLocalFile5xx } = filetool.getAllFilePaths(path.resolve(__dirname, 'src/html/error/5xx'))
+const { localPathResult: AllHTMLLocalFile5xx } = filetool.filewaalk.getAllFilePaths(path.resolve(__dirname, 'src/html/error/5xx'))
 AllHTMLLocalFile5xx.forEach((filePath) => {
   if (!filePath.endsWith('.html')) {
     return

+ 3 - 3
webpack_config_github.js

@@ -3,7 +3,7 @@ import HtmlWebpackPlugin from 'html-webpack-plugin'
 import MiniCssExtractPlugin from 'mini-css-extract-plugin'
 import CopyWebpackPlugin from 'copy-webpack-plugin'
 import TerserPlugin from 'terser-webpack-plugin'
-import filetool from './src/utils/file.js'
+import filetool from 'huan-file-tool'
 import { fileURLToPath } from 'url'
 
 const __filename = fileURLToPath(import.meta.url)
@@ -27,7 +27,7 @@ const html_minify = {
 
 const HTMMLPlugin = []
 
-const { localPathResult: AllHTMLLocalFile4xx } = filetool.getAllFilePaths(path.resolve(__dirname, 'src/html/error/4xx'))
+const { localPathResult: AllHTMLLocalFile4xx } = filetool.filewaalk.getAllFilePaths(path.resolve(__dirname, 'src/html/error/4xx'))
 AllHTMLLocalFile4xx.forEach((filePath) => {
   if (!filePath.endsWith('.html')) {
     return
@@ -70,7 +70,7 @@ AllHTMLLocalFile4xx.forEach((filePath) => {
   )
 })
 
-const { localPathResult: AllHTMLLocalFile5xx } = filetool.getAllFilePaths(path.resolve(__dirname, 'src/html/error/5xx'))
+const { localPathResult: AllHTMLLocalFile5xx } = filetool.filewaalk.getAllFilePaths(path.resolve(__dirname, 'src/html/error/5xx'))
 AllHTMLLocalFile5xx.forEach((filePath) => {
   if (!filePath.endsWith('.html')) {
     return

+ 3 - 3
webpack_config_prod.js

@@ -2,7 +2,7 @@ import path from 'path'
 import HtmlWebpackPlugin from 'html-webpack-plugin'
 import MiniCssExtractPlugin from 'mini-css-extract-plugin'
 import CopyWebpackPlugin from 'copy-webpack-plugin'
-import filetool from './src/utils/file.js'
+import filetool from 'huan-file-tool'
 import { fileURLToPath } from 'url'
 
 const __filename = fileURLToPath(import.meta.url)
@@ -26,7 +26,7 @@ const html_minify = {
 
 const HTMMLPlugin = []
 
-const { localPathResult: AllHTMLLocalFile4xx } = filetool.getAllFilePaths(path.resolve(__dirname, 'src/html/error/4xx'))
+const { localPathResult: AllHTMLLocalFile4xx } = filetool.filewaalk.getAllFilePaths(path.resolve(__dirname, 'src/html/error/4xx'))
 AllHTMLLocalFile4xx.forEach((filePath) => {
   if (!filePath.endsWith('.html')) {
     return
@@ -69,7 +69,7 @@ AllHTMLLocalFile4xx.forEach((filePath) => {
   )
 })
 
-const { localPathResult: AllHTMLLocalFile5xx } = filetool.getAllFilePaths(path.resolve(__dirname, 'src/html/error/5xx'))
+const { localPathResult: AllHTMLLocalFile5xx } = filetool.filewaalk.getAllFilePaths(path.resolve(__dirname, 'src/html/error/5xx'))
 AllHTMLLocalFile5xx.forEach((filePath) => {
   if (!filePath.endsWith('.html')) {
     return