Skip to content

Commit

Permalink
feat: 完善 customBuild 等 rules
Browse files Browse the repository at this point in the history
  • Loading branch information
imsunhao committed Oct 25, 2019
1 parent 94aa6c5 commit 7019a1f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 17 deletions.
30 changes: 24 additions & 6 deletions src/config/webpack.custom-build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import { ConfigOptions } from '@types'

export function getCustomConfig(options: ConfigOptions.options, target: string) {
if (!(options.webpack && options.webpack.mode)) {
consola.fatal(
'[getCustomConfig] options.webpack or options.webpack.mode is undefined'
)
consola.fatal('[getCustomConfig] options.webpack or options.webpack.mode is undefined')
return process.exit(1)
}

Expand All @@ -21,23 +19,43 @@ export function getCustomConfig(options: ConfigOptions.options, target: string)

if (options.customBuild[target]) {
const customBuild = options.customBuild[target] || {}
const rules = []
if (customBuild.module && customBuild.module.rules) {
const babelJS = customBuild.module.rules.find(rule => rule.test === /\.js$/)
if (!babelJS) {
rules.push({
test: /\.js$/,
loader: 'happypack/loader?id=babel',
exclude: /node_modules/
})
}
const babelTS = customBuild.module.rules.find(rule => rule.test === /\.tsx?$/)
if (!babelTS) {
rules.push({
test: /\.tsx?$/,
use: ['happypack/loader?id=babel', 'happypack/loader?id=ts'],
exclude: /node_modules/
})
}
}
const mode = options.webpack.mode || 'production'
const base: any = options.webpack ? options.webpack.base || {} : {}
return (merge as any)(
getCommonBaseConfig(options),
{
name: target,
mode,
module: {
rules
},
devtool: false,
output: base.output,
resolve: base.resolve
},
customBuild
)
} else {
consola.fatal(
`[getServerConfig] options.webpack[${target}] is undefined`
)
consola.fatal(`[getServerConfig] options.webpack[${target}] is undefined`)
return process.exit(1)
}
}
20 changes: 16 additions & 4 deletions src/config/webpack.dll.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import webpack from 'webpack'
import { getCommonConfig } from './webpack.common.config'
import VueSSRClientPlugin from 'vue-server-renderer/client-plugin'

export function getDllConfig(
options: ConfigOptions.options
): webpack.Configuration {
export function getDllConfig(options: ConfigOptions.options): webpack.Configuration {
if (!(options.webpack && options.webpack.dll)) {
consola.fatal('getDllConfig options.webpack.dll is undefined')
return process.exit(1)
Expand All @@ -27,6 +25,20 @@ export function getDllConfig(
name: 'dll',
mode,
entry: dll.entry,
module: {
rules: [
{
test: /\.js$/,
loader: 'happypack/loader?id=babel',
exclude: /node_modules/
},
{
test: /\.tsx?$/,
use: ['happypack/loader?id=babel', 'happypack/loader?id=ts'],
exclude: /node_modules/
}
]
},
output: {
path: dll.path,
publicPath: dll.publicPath,
Expand All @@ -51,7 +63,7 @@ export function getDllConfig(
plugins: [
new VueSSRClientPlugin({
filename: 'vue-ssr-dll-manifest.json'
}),
})
]
},
getDllPlugin(dll),
Expand Down
9 changes: 2 additions & 7 deletions src/config/webpack.extensions.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ import consola from 'consola'
import { babelLoder } from './webpack.config.config'
import { getCommonConfig } from './webpack.common.config'

export function getExtensionsConfig(
options: ConfigOptions.options
): webpack.Configuration {
export function getExtensionsConfig(options: ConfigOptions.options): webpack.Configuration {
if (
!(
options.extensions &&
Expand All @@ -19,9 +17,7 @@ export function getExtensionsConfig(
options.webpack.mode
)
) {
consola.fatal(
'getExtensionsConfig options.extensions.entry or options.babelrc is undefined'
)
consola.fatal('getExtensionsConfig options.extensions.entry or options.babelrc is undefined')
return process.exit(1)
}

Expand Down Expand Up @@ -60,7 +56,6 @@ export function getExtensionsConfig(
exclude: /node_modules/,
use: ['ts-loader']
},

{
test: /\.js$/,
use: babelLoder,
Expand Down

0 comments on commit 7019a1f

Please sign in to comment.