Skip to content

Commit

Permalink
Merge pull request #91 from nighca/master
Browse files Browse the repository at this point in the history
修复 staticDir 不存在时会报错的问题
  • Loading branch information
nighca authored Dec 4, 2018
2 parents d23e513 + a5479cd commit 2271813
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 14 deletions.
34 changes: 22 additions & 12 deletions lib/webpack-config/build-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* @author nighca <[email protected]>
*/

const fs = require('fs')
const path = require('path')
const CopyWebpackPlugin = require('copy-webpack-plugin')

Expand Down Expand Up @@ -45,18 +46,27 @@ module.exports = () => Promise.all([
webpackConfig = require('./addons/gen-pages')(webpackConfig, pages, buildConfig.publicUrl, buildConfig.optimization)

// gen static
webpackConfig.plugins.push(
new CopyWebpackPlugin([
{
from: paths.getStaticPath(buildConfig),
to: 'static',
toType: 'dir'
}
], {
debug: logger.level === 'debug' ? 'info' : 'warning',
context: projectPaths.root
})
)
const staticPath = paths.getStaticPath(buildConfig)
try {
const stats = fs.statSync(staticPath)
if (!stats.isDirectory()) {
throw new Error('staticPath not a directory')
}
webpackConfig.plugins.push(
new CopyWebpackPlugin([
{
from: staticPath,
to: 'static',
toType: 'dir'
}
], {
debug: logger.level === 'debug' ? 'info' : 'warning',
context: projectPaths.root
})
)
} catch (e) {
logger.warn('Copy staticDir content failed:', e.message)
}

webpackConfig.output = {
path: projectPaths.dist,
Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fec-builder",
"version": "1.10.0",
"version": "1.10.1",
"bin": {
"fec-builder": "./bin/fec-builder"
},
Expand Down

0 comments on commit 2271813

Please sign in to comment.