wuzj 2 weeks ago
parent
commit
b53da379e2
4 changed files with 131 additions and 218 deletions
  1. 96 173
      client/config/index.ts
  2. 30 41
      client/package.json
  3. 4 4
      client/src/app.ts
  4. 1 0
      client/src/styles/variables.scss

+ 96 - 173
client/config/index.ts

@@ -1,190 +1,113 @@
-import path from 'path'
 import { defineConfig } from '@tarojs/cli'
 import TsconfigPathsPlugin from 'tsconfig-paths-webpack-plugin'
+// 导入sass
+import * as sass from 'sass'
+
 import devConfig from './dev'
 import prodConfig from './prod'
 
 // https://taro-docs.jd.com/docs/next/config#defineconfig-辅助函数
-export default defineConfig({
-  projectName: 'line-for-fun',
-  date: '2023-10-22',
-  designWidth: 750,
-  deviceRatio: {
-    640: 2.34 / 2,
-    750: 1,
-    375: 2,
-    828: 1.81 / 2
-  },
-  sourceRoot: 'src',
-  outputRoot: 'dist',
-  plugins: [],
-  defineConstants: {
-    'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
-  },
-  copy: {
-    patterns: [
-    ],
-    options: {
-    }
-  },
-  framework: 'react',
-  compiler: {
-    type: 'webpack5',
-    prebundle: {
-      enable: false
-    }
-  },
-  sass: {
-    data: `@import "@nutui/nutui-react-taro/dist/styles/variables.scss";`
-  },
-  mini: {
-    postcss: {
-      pxtransform: {
-        enable: true,
-        config: {
-          selectorBlackList: [/nut-/]
+export default defineConfig(async (merge) => {
+  const baseConfig = {
+    projectName: 'miniprogram-lineforfun',
+    date: '2023-8-13',
+    designWidth: 750,
+    deviceRatio: {
+      640: 2.34 / 2,
+      750: 1,
+      375: 2,
+      828: 1.81 / 2
+    },
+    sourceRoot: 'src',
+    outputRoot: 'dist',
+    plugins: [],
+    defineConstants: {
+    },
+    copy: {
+      patterns: [
+      ],
+      options: {
+      }
+    },
+    framework: 'react',
+    compiler: 'webpack5',
+    cache: {
+      enable: false // Webpack 持久化缓存配置,建议开启。默认配置请参考:https://docs.taro.zone/docs/config-detail#cache
+    },
+    mini: {
+      postcss: {
+        pxtransform: {
+          enable: true,
+          config: {
+
+          }
+        },
+        url: {
+          enable: true,
+          config: {
+            limit: 1024 // 设定转换尺寸上限
+          }
+        },
+        cssModules: {
+          enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
+          config: {
+            namingPattern: 'module', // 转换模式,取值为 global/module
+            generateScopedName: '[name]__[local]___[hash:base64:5]'
+          }
         }
       },
-      url: {
-        enable: true,
-        config: {
-          limit: 1024 // 设定转换尺寸上限
+      sassLoaderOption: {
+        sassOptions: {
+          outputStyle: 'expanded'
         }
       },
-      cssModules: {
-        enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
-        config: {
-          namingPattern: 'module', // 转换模式,取值为 global/module
-          generateScopedName: '[name]__[local]___[hash:base64:5]'
-        }
-      }
-    },
-    webpackChain(chain) {
-      chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
-
-      // 添加Node.js核心模块的浏览器实现
-      chain.resolve.set('fallback', {
-        fs: false,
-        path: false,
-        process: require.resolve('process/browser'),
-        crypto: require.resolve('crypto-browserify'),
-        stream: require.resolve('stream-browserify'),
-        assert: require.resolve('assert'),
-        http: require.resolve('stream-http'),
-        https: require.resolve('https-browserify'),
-        os: require.resolve('os-browserify'),
-        url: require.resolve('url'),
-        buffer: require.resolve('buffer'),
-        zlib: require.resolve('browserify-zlib'),
-        querystring: require.resolve('querystring-es3'),
-        worker_threads: require.resolve('worker-polyfill'),
-        inspector: false,
-        net: false,
-        tls: false,
-        child_process: false,
-        dns: false,
-        dgram: false,
-        cluster: false,
-        module: false,
-        // SWC核心包二进制文件所有可能的平台
-        // Android相关
-        '@swc/core-android-arm64': false,
-        '@swc/core-android-arm-eabi': false,
-        // Windows相关
-        '@swc/core-win32-x64-msvc': false,
-        '@swc/core-win32-ia32-msvc': false,
-        '@swc/core-win32-arm64-msvc': false,
-        // Darwin (MacOS)相关
-        '@swc/core-darwin-universal': false,
-        '@swc/core-darwin-x64': false,
-        '@swc/core-darwin-arm64': false,
-        // FreeBSD相关
-        '@swc/core-freebsd-x64': false,
-        // Linux相关
-        '@swc/core-linux-x64-musl': false,
-        '@swc/core-linux-x64-gnu': false,
-        '@swc/core-linux-arm64-musl': false,
-        '@swc/core-linux-arm64-gnu': false,
-        '@swc/core-linux-arm-gnueabihf': false,
-      })
-
-      // 提供全局变量支持Buffer和process
-      chain.plugin('provide-plugin').use(require('webpack').ProvidePlugin, [{
-        process: 'process/browser',
-        Buffer: ['buffer', 'Buffer']
-      }])
-    }
-  },
-  h5: {
-    publicPath: '/',
-    staticDirectory: 'static',
-    output: {
-      filename: 'js/[name].[hash:8].js',
-      chunkFilename: 'js/[name].[chunkhash:8].js'
-    },
-    miniCssExtractPluginOption: {
-      ignoreOrder: true,
-      filename: 'css/[name].[hash:8].css',
-      chunkFilename: 'css/[name].[chunkhash:8].css'
+      miniCssExtractPluginOption: {
+        ignoreOrder: true,
+      },
     },
-    postcss: {
-      autoprefixer: {
-        enable: true,
-        config: {}
+    h5: {
+      publicPath: '/',
+      staticDirectory: 'static',
+      output: {
+        filename: 'js/[name].[hash:8].js',
+        chunkFilename: 'js/[name].[chunkhash:8].js'
+      },
+      miniCssExtractPluginOption: {
+        ignoreOrder: true,
+        filename: 'css/[name].[hash:8].css',
+        chunkFilename: 'css/[name].[chunkhash:8].css'
       },
-      cssModules: {
-        enable: true, // 默认为 false,如需使用 css modules 功能,则设为 true
-        config: {
-          namingPattern: 'module', // 转换模式,取值为 global/module
-          generateScopedName: '[name]__[local]___[hash:base64:5]'
+      postcss: {
+        autoprefixer: {
+          enable: true,
+          config: {}
+        },
+        cssModules: {
+          enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
+          config: {
+            namingPattern: 'module', // 转换模式,取值为 global/module
+            generateScopedName: '[name]__[local]___[hash:base64:5]'
+          }
         }
+      },
+      webpackChain(chain) {
+        chain.resolve.plugin('tsconfig-paths').use(TsconfigPathsPlugin)
       }
-    }
-  },
-  rn: {
-    appName: 'taroDemo',
-    postcss: {
-      cssModules: {
-        enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
+    },
+    rn: {
+      appName: 'taroDemo',
+      postcss: {
+        cssModules: {
+          enable: false, // 默认为 false,如需使用 css modules 功能,则设为 true
+        }
       }
     }
-  },
-  env: {
-    NODE_ENV: process.env.NODE_ENV
-  },
-  alias: {
-    '@/components': path.resolve(__dirname, '..', 'src/components'),
-    '@/hooks': path.resolve(__dirname, '..', 'src/hooks'),
-    '@/utils': path.resolve(__dirname, '..', 'src/utils'),
-    '@/constants': path.resolve(__dirname, '..', 'src/constants'),
-    '@/pages': path.resolve(__dirname, '..', 'src/pages'),
-    '@/services': path.resolve(__dirname, '..', 'src/services'),
-    '@/assets': path.resolve(__dirname, '..', 'src/assets'),
-    '@/types': path.resolve(__dirname, '..', 'src/types'),
-    '@/contexts': path.resolve(__dirname, '..', 'src/contexts'),
-    '@': path.resolve(__dirname, '..', 'src')
-  },
-  terser: {
-    enable: true,
-    config: {
-      // 配置项同 terser-webpack-plugin 的配置
-      compress: { drop_console: true }
-    }
-  },
-  csso: {
-    enable: true,
-    config: {
-      // 配置项同 csso 的配置
-    }
-  },
-})
-
-export const plugins = [];
+  }
 
-// 在文件末尾添加SWC配置
-try {
-  // 尝试配置SWC使用WASM版本
-  process.env.SWC_WASM = require.resolve('@swc/wasm')
-} catch (e) {
-  console.warn('Failed to configure SWC WASM fallback:', e)
-}
+  if (process.env.NODE_ENV === 'development') {
+    // 本地开发构建配置
+    return merge({}, baseConfig, devConfig)
+  }
+  // 生产构建配置
+  return merge({}, baseConfig, prodConfig)
+})

+ 30 - 41
client/package.json

@@ -11,7 +11,23 @@
   },
   "scripts": {
     "build:weapp": "taro build --type weapp",
-    "dev:weapp": "pnpm run build:weapp -- --watch"
+    "build:swan": "taro build --type swan",
+    "build:alipay": "taro build --type alipay",
+    "build:tt": "taro build --type tt",
+    "build:h5": "taro build --type h5",
+    "build:rn": "taro build --type rn",
+    "build:qq": "taro build --type qq",
+    "build:jd": "taro build --type jd",
+    "build:harmony-hybrid": "taro build --type harmony-hybrid",
+    "dev:weapp": "npm run build:weapp -- --watch",
+    "dev:swan": "npm run build:swan -- --watch",
+    "dev:alipay": "npm run build:alipay -- --watch",
+    "dev:tt": "npm run build:tt -- --watch",
+    "dev:h5": "npm run build:h5 -- --watch",
+    "dev:rn": "npm run build:rn -- --watch",
+    "dev:qq": "npm run build:qq -- --watch",
+    "dev:jd": "npm run build:jd -- --watch",
+    "dev:harmony-hybrid": "npm run build:harmony-hybrid -- --watch"
   },
   "browserslist": [
     "last 3 versions",
@@ -24,17 +40,21 @@
     "@tarojs/components": "4.0.9",
     "@tarojs/helper": "4.0.9",
     "@tarojs/plugin-framework-react": "4.0.9",
+    "@tarojs/plugin-platform-alipay": "4.0.9",
+    "@tarojs/plugin-platform-h5": "4.0.9",
+    "@tarojs/plugin-platform-harmony-hybrid": "4.0.9",
+    "@tarojs/plugin-platform-jd": "4.0.9",
+    "@tarojs/plugin-platform-qq": "4.0.9",
+    "@tarojs/plugin-platform-swan": "4.0.9",
+    "@tarojs/plugin-platform-tt": "4.0.9",
     "@tarojs/plugin-platform-weapp": "4.0.9",
     "@tarojs/react": "4.0.9",
-    "@tarojs/router": "4.0.9",
     "@tarojs/runtime": "4.0.9",
     "@tarojs/shared": "4.0.9",
     "@tarojs/taro": "4.0.9",
-    "@tarojs/taro-h5": "4.0.9",
     "@tarojs/webpack5-runner": "^4.0.9",
-    "react": "^18.3.1",
-    "react-dom": "^18.3.1",
-    "react-icons": "^5.5.0"
+    "react": "^18.0.0",
+    "react-dom": "^18.0.0"
   },
   "devDependencies": {
     "@babel/core": "^7.24.4",
@@ -42,52 +62,21 @@
     "@babel/plugin-syntax-flow": "^7.26.0",
     "@babel/preset-react": "^7.24.1",
     "@babel/preset-typescript": "^7.26.0",
-    "@pmmmwh/react-refresh-webpack-plugin": "^0.5.15",
-    "@swc/wasm": "^1.11.11",
     "@tarojs/cli": "4.0.9",
     "@tarojs/vite-runner": "4.0.9",
-    "@types/react": "^18.3.19",
+    "@types/react": "^18.0.0",
     "@vitejs/plugin-react": "^4.3.0",
-    "assert": "^2.1.0",
     "babel-preset-taro": "4.0.9",
-    "browser-worker": "^1.0.0",
-    "browserify-zlib": "^0.2.0",
-    "buffer": "^6.0.3",
-    "console-browserify": "^1.2.0",
-    "constants-browserify": "^1.0.0",
-    "crypto-browserify": "^3.12.1",
-    "domain-browser": "^5.7.0",
     "eslint": "^8.57.0",
     "eslint-config-taro": "4.0.9",
     "eslint-plugin-react": "^7.34.1",
     "eslint-plugin-react-hooks": "^4.4.0",
-    "events": "^3.3.0",
-    "file-loader": "^6.2.0",
-    "https-browserify": "^1.0.0",
-    "inspector-proxy": "^1.2.3",
-    "os-browserify": "^0.3.0",
-    "path-browserify": "^1.0.1",
     "postcss": "^8.4.38",
-    "process": "^0.11.10",
-    "punycode": "^2.3.1",
-    "querystring-es3": "^0.2.1",
     "react-refresh": "^0.14.0",
     "sass": "^1.75.0",
-    "stream-browserify": "^3.0.0",
-    "stream-http": "^3.2.0",
-    "string_decoder": "^1.3.0",
     "stylelint": "^16.4.0",
     "terser": "^5.30.4",
-    "timers-browserify": "^2.0.12",
-    "tsconfig-paths-webpack-plugin": "^4.2.0",
-    "tty-browserify": "^0.0.1",
-    "typescript": "^5.8.2",
-    "url": "^0.11.4",
-    "url-loader": "^4.1.1",
-    "util": "^0.12.5",
-    "vite": "^4.2.0",
-    "vm-browserify": "^1.1.2",
-    "webpack": "^5.98.0",
-    "worker-polyfill": "^1.0.0"
+    "typescript": "^5.4.5",
+    "vite": "^4.2.0"
   }
-}
+}

+ 4 - 4
client/src/app.ts

@@ -1,5 +1,5 @@
-import React, { useEffect } from 'react'
-import { createApp } from '@tarojs/plugin-framework-react' // 从正确的包导入 createApp
+import React from 'react'
+import { createApp } from 'react'
 import Taro from '@tarojs/taro'
 import './app.scss'
 
@@ -29,11 +29,11 @@ export interface IAppProps {
 
 function App({ children }: IAppProps) {
   // 在应用初次加载时初始化云环境
-  useEffect(() => {
+  React.useEffect(() => {
     initCloud();
   }, []);
 
   return children;
 }
 
-export default createApp(App)
+export default createApp(App)

+ 1 - 0
client/src/styles/variables.scss

@@ -0,0 +1 @@
+@forward "@nutui/nutui-react-taro/dist/styles/variables.scss";