bk-shop/config/index.js

181 lines
4.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

import path from 'path'
import pkg from '../package.json'
const chalk = require("chalk")
const { getEnvs, getDefineConstants, getCacheIdentifier } = require('./utils')
require('dotenv-flow').config()
const DIST_PATH = `dist/${process.env.TARO_ENV}`
const APP_ENVS = getEnvs()
// 是否为生产模式
const IS_PROD = process.env.NODE_ENV === 'production'
const BUILD_TARGET = process.env.TARGET
const BUILD_APP_SERVER = process.env.SERVER
const CONST_ENVS = {
APP_NAME: pkg.app_name,
APP_AUTH_PAGE:
process.env.TARO_ENV == 'h5' ? '/subpage/pages/auth/login' : '/subpages/member/index',
APP_BUILD_TARGET: BUILD_TARGET,
APP_LIVE: process.env.APP_LIVE,
...APP_ENVS
}
Object.keys(CONST_ENVS).forEach(key => {
console.log(chalk.green(`${key}=${CONST_ENVS[key]}`))
})
// 是否打包APP
const IS_APP = BUILD_TARGET === 'app'
// 是否打包成APP服务
const IS_APP_SERVER = BUILD_APP_SERVER === 'server'
const copyPatterns = [{ from: 'src/assets', to: `${DIST_PATH}/assets` }]
if (process.env.TARO_ENV == 'weapp') {
copyPatterns.push({ from: 'src/ext.json', to: `${DIST_PATH}/ext.json` })
}
if (process.env.TARO_ENV == 'h5') {
copyPatterns.push({ from: 'src/files', to: `${DIST_PATH}` })
}
if (process.env.TARO_ENV == 'alipay') {
copyPatterns.push({ from: 'mini.project.json', to: `${DIST_PATH}/mini.project.json` })
}
const config = {
projectName: pkg.name,
date: '2021-11-22',
framework: 'react',
designWidth: 750,
deviceRatio: {
'640': 2.34 / 2,
'750': 1,
'828': 1.81 / 2
},
sourceRoot: 'src',
outputRoot: DIST_PATH,
sass: {
resource: path.resolve(__dirname, '..', 'src/style/imports.scss'),
projectDirectory: path.resolve(__dirname, '..')
},
defineConstants: getDefineConstants(CONST_ENVS),
alias: {
'taro-ui$': 'taro-ui/lib/index',
'@': path.join(__dirname, '../src'),
'lodash': 'lodash-es'
},
copy: {
patterns: copyPatterns
},
plugins: [
// 'taro-plugin-compiler-optimization'
// '@shopex/taro-plugin-modules',
// path.join(__dirname, "../src/plugin/test.js")
// path.join(__dirname, "./modify-taro.js")
],
mini: {
// webpackChain (chain, webpack) {
// // chain.plugin('analyzer')
// // .use(require('webpack-bundle-analyzer').BundleAnalyzerPlugin, [])
// chain.merge({
// plugin: {
// install: {
// plugin: require('terser-webpack-plugin'),
// args: [
// {
// terserOptions: {
// compress: true, // 默认使用terser压缩
// // mangle: false,
// keep_classnames: true, // 不改变class名称
// keep_fnames: true, // 不改变函数名称
// },
// },
// ],
// },
// },
// })
// },
cache: {
enable: true,
cacheDirectory: 'node_modules/.cache',
cacheIdentifier: getCacheIdentifier(CONST_ENVS)
},
miniCssExtractPluginOption: {
ignoreOrder: true
},
optimizeMainPackage: {
enable: true
},
// 图片转换base64
imageUrlLoaderOption: {
limit: 0
},
postcss: {
autoprefixer: {
enable: true
},
pxtransform: {
enable: true,
config: {}
},
url: {
enable: true,
config: {
limit: 10240 // 设定转换尺寸上限
}
},
cssModules: {
enable: false, // 默认为 false如需使用 css modules 功能,则设为 true
config: {
namingPattern: 'module', // 转换模式,取值为 global/module
generateScopedName: '[name]__[local]___[hash:base64:5]'
}
}
},
},
h5: {
// publicPath: IS_PROD ? './' : '/',
// publicPath: '/',
publicPath: (IS_APP && IS_PROD && !IS_APP_SERVER) ? './' : '/',
// publicPath: process.env.APP_PUBLIC_PATH || '/',
staticDirectory: 'static',
router: {
mode: IS_APP ? "hash" : "browser"
// mode: "browser"
},
devServer: {
// https: true,
// overlay: {
// warnings: false,
// errors: false
// }
// https: {
// key: "../cert/ecshopx-server.key",
// cert: "../cert/ecshopx-server.crt",
// // passphrase: "webpack-dev-server",
// requestCert: true
// }
},
postcss: {
autoprefixer: {
enable: true,
config: {
overrideBrowserslist: ['last 3 versions', 'Android >= 4.1', 'ios >= 8']
}
}
},
esnextModules: ['taro-ui']
}
}
module.exports = function (merge) {
if (!IS_PROD) {
return merge({}, config, require('./dev'))
}
return merge({}, config, require('./prod'))
}