|
@@ -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)
|
|
|
+})
|