Skip to content

Commit

Permalink
feat: 添加 tsconfig 扩展选项
Browse files Browse the repository at this point in the history
  • Loading branch information
imsunhao committed Aug 15, 2019
1 parent 8f0fca2 commit 0f10d10
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
5 changes: 5 additions & 0 deletions @types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,11 @@ declare namespace build {
*/
babelrc?: TransformOptions

/**
* tsconfig PATH 配置
*/
tsconfig?: string

/**
* webpack 配置
*/
Expand Down
24 changes: 14 additions & 10 deletions src/config/webpack.base.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@ export function getBaseConfig(options: ConfigOptions.options) {
const mode = options.webpack.mode || 'production'
const isProd = mode === 'production'
const base = options.webpack ? options.webpack.base || {} : {}
const tsLoader: any = {
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
transpileOnly: true,
happyPackMode: true,
}
}
if (options.tsconfig) {
tsLoader.options.context = options.rootDir
tsLoader.options.configFile = options.tsconfig
}
// consola.fatal(tsLoader)

const babelLoder = {
loader: 'babel-loader',
Expand Down Expand Up @@ -96,16 +109,7 @@ export function getBaseConfig(options: ConfigOptions.options) {
]
).concat([
new VueLoaderPlugin(),
makeHappyPack('ts', [
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/],
transpileOnly: true,
happyPackMode: true
}
}
]),
makeHappyPack('ts', [tsLoader]),
makeHappyPack('babel', [babelLoder])
])
},
Expand Down
2 changes: 1 addition & 1 deletion src/utils/compiler.webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ function devCompilerExtensions(options: ConfigOptions.options, app?: Express) {
const souce = mfs.readFileSync(resolve(outputPath, name), 'utf-8')
extensions = requireFromString(souce).default
} catch (error) {
consola.fatal('devCompilerExtensions', error)
consola.fatal('devCompilerExtensions', resolve(outputPath, name), error)
return process.exit(1)
}
Object.keys(extensions).forEach(extensionKey => {
Expand Down

0 comments on commit 0f10d10

Please sign in to comment.