Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Commit

Permalink
fix: 解决自定义配置问题
Browse files Browse the repository at this point in the history
  • Loading branch information
virgoone committed Oct 28, 2021
1 parent abff8ae commit 904cd67
Show file tree
Hide file tree
Showing 4 changed files with 8,438 additions and 8,166 deletions.
13 changes: 6 additions & 7 deletions src/.babel.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ const path = require('path')
// TODO: 作为一个 preset 的方式大概会更好

module.exports = (api) => {
const projectBabelPath = getProjectFilePath('.babel.config.js')
const projectBabelPath =
getProjectFilePath('.babel.config.js') ||
getProjectFilePath('babel.config.js')

let customBabelConfig = {}
if (fs.existsSync(projectBabelPath)) {
Expand All @@ -18,10 +20,7 @@ module.exports = (api) => {
const { NODE_ENV, BABEL_ENV } = process.env
const resolverOpts = {
root: [path.relative(__dirname, process.cwd())],
extensions: ['.js', '.jsx', '.tsx', '.ts'],
alias: {
'@': './src'
}
extensions: ['.js', '.jsx', '.tsx', '.ts']
}

let environment = []
Expand All @@ -39,8 +38,8 @@ module.exports = (api) => {
const config = {
presets: [
['@babel/preset-env'],
'@babel/preset-react',
'@babel/preset-typescript'
'@babel/preset-typescript',
'@babel/preset-react'
],
plugins: [
...environment,
Expand Down
4 changes: 1 addition & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,4 @@ yargs
})
.demandCommand()
.help()
.option('version', {
alias: 'v'
}).argv
.version().argv
9 changes: 5 additions & 4 deletions src/utils/custom-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,19 @@ const getCustomConfig = () => {
return customConfig
}

let webpackConfig = null
const processWebpackConfig = (config) => {
const customWebpackConfig = getCustomConfig().configureWebpack

if (typeof customWebpackConfig === 'function') {
customConfig = customWebpackConfig(config)
webpackConfig = customWebpackConfig(config)
} else if (typeof customWebpackConfig === 'object') {
customConfig = customWebpackConfig
webpackConfig = customWebpackConfig
}

if (customConfig) {
if (webpackConfig) {
// eslint-disable-next-line no-param-reassign
config = mergeWebpackConfig(config, customConfig)
config = mergeWebpackConfig(config, webpackConfig)
}
return config
}
Expand Down
Loading

0 comments on commit 904cd67

Please sign in to comment.