-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from nighca/master
修复 staticDir 不存在时会报错的问题
- Loading branch information
Showing
3 changed files
with
24 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
* @author nighca <[email protected]> | ||
*/ | ||
|
||
const fs = require('fs') | ||
const path = require('path') | ||
const CopyWebpackPlugin = require('copy-webpack-plugin') | ||
|
||
|
@@ -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, | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters