Skip to content

Commit

Permalink
feat: doc 使用 ts进行配置
Browse files Browse the repository at this point in the history
  • Loading branch information
imsunhao committed Jun 27, 2019
1 parent e7ebf50 commit 065e43b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 75 deletions.
35 changes: 14 additions & 21 deletions doc/build.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ import getBase from './build/webpack.base.conf.babel'
import getDll from './build/webpack.dll.conf.babel'
import getClient from './build/webpack.client.conf.babel'
import getServer from './build/webpack.server.conf.babel'
import path from 'path'
import getExtensions from './build/webpack.extensions.conf.babel.js'

export default function(inject: ConfigOptions.getOptionsInject): ConfigOptions.options {
const config = getConfig(inject)

const base: any = getBase(config, inject)
const dll: any = getDll(config, inject)
const client: any = getClient(config, inject)
const server: any = getServer(config, inject)
const webpack: any = {
base: getBase(config, inject),
dll: getDll(config, inject),
client: getClient(config, inject),
server: getServer(config, inject),
}
const extensions: any = getExtensions(config, inject)

const { port } = config
const { port, render, statics, proxyTable } = config

return {
env: ['SERVER_ENV', 'ENV', 'NODE_ENV'],
Expand All @@ -33,20 +36,10 @@ export default function(inject: ConfigOptions.getOptionsInject): ConfigOptions.o
],
],
},
render: config.render,
statics: config.statics,
proxyTable: config.proxyTable,
extensions: {
entry: {
extensions: inject.resolve('./server/index.js'),
},
path: path.resolve(base.output.path),
},
webpack: {
dll,
base,
client,
server,
},
render,
statics,
proxyTable,
extensions,
webpack,
}
}
32 changes: 0 additions & 32 deletions doc/build/utils.js

This file was deleted.

8 changes: 8 additions & 0 deletions doc/build/webpack.extensions.conf.babel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default function(config, { resolve }) {
return {
entry: {
extensions: resolve('./server/index.js'),
},
path: config.assetRoot
}
}
File renamed without changes.
28 changes: 13 additions & 15 deletions doc/config/index.js → doc/config/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { ConfigOptions } from '@bestminr/build'

import path from 'path'
import ProdEnv from './prod.env'
import DevEnv from './dev.env'
Expand Down Expand Up @@ -46,11 +48,11 @@ export function baseConfig(inject) {
statics: {
'/service-worker.js': {
path: resolve('./dist/service-worker.js'),
maxAge: getStaticsMaxAge({ cache: false, isProd: true }),
maxAge: 0,
},
'/manifest.json': {
path: resolve('./manifest.json'),
maxAge: getStaticsMaxAge({ cache: false, isProd: false }),
maxAge: 0,
},
},
render: {
Expand All @@ -71,23 +73,23 @@ export function baseConfig(inject) {
statics: {
'/dist': {
path: resolve('./dist'),
maxAge: getStaticsMaxAge({ cache: true, isProd: false }),
maxAge: 0,
},
'/common-assets': {
path: resolve('./common-assets'),
maxAge: getStaticsMaxAge({ cache: true, isProd: false }),
maxAge: 0,
},
'/public': {
path: resolve('./public'),
maxAge: getStaticsMaxAge({ cache: true, isProd: false }),
maxAge: 0,
},
'/service-worker.js': {
path: resolve('./dist/service-worker.js'),
maxAge: getStaticsMaxAge({ cache: false, isProd: false }),
maxAge: 0,
},
'/manifest.json': {
path: resolve('./manifest.json'),
maxAge: getStaticsMaxAge({ cache: false, isProd: false }),
maxAge: 0,
},
},
proxyTable: getProxyTable(inject),
Expand All @@ -101,7 +103,7 @@ export function baseConfig(inject) {
}
}

export function getConfig(inject, opts = {}) {
export function getConfig(inject: ConfigOptions.getOptionsInject, opts = {}) {
const config = baseConfig(inject)
const { resolve } = inject
let resultConfig
Expand All @@ -115,15 +117,15 @@ export function getConfig(inject, opts = {}) {
...resultConfig.statics,
'/dist': {
path: resolve('./dist'),
maxAge: getStaticsMaxAge({ cache: true, isProd: false }),
maxAge: 0,
},
'/common-assets': {
path: resolve('./common-assets'),
maxAge: getStaticsMaxAge({ cache: true, isProd: false }),
maxAge: 0,
},
[`${outputPath}public`]: {
path: resolve('./public'),
maxAge: getStaticsMaxAge({ cache: true, isProd: false }),
maxAge: 0,
},
}
resultConfig.proxyTable = getProxyTable(inject)
Expand All @@ -133,7 +135,3 @@ export function getConfig(inject, opts = {}) {
}
return resultConfig
}

function getStaticsMaxAge(options) {
return options.cache && options.isProd ? STATICS_MAX_AGE : 0
}
File renamed without changes.
18 changes: 11 additions & 7 deletions src/utils/compiler.webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,13 +296,17 @@ function prodCompilerExtensions(options: ConfigOptions.options) {

compiler.run((err, stats) => {
{
consola.log(
stats.toString({
all: false,
assets: true
})
)
showError(stats)
if (err) {
consola.fatal(err)
} else {
consola.log(
stats.toString({
all: false,
assets: true
})
)
showError(stats)
}
}
})
})
Expand Down

0 comments on commit 065e43b

Please sign in to comment.