feat: copy static files for production build

This commit is contained in:
endiliey 2018-08-08 02:28:29 +08:00
parent 77ec02a278
commit fa02f6ef60
2 changed files with 19 additions and 1 deletions

View file

@ -3,4 +3,6 @@ id: hello
title: Hello, World ! title: Hello, World !
--- ---
Hi, Endilie here :) Hi, Endilie here :)
![sakura](/img/sakura.png)

View file

@ -2,6 +2,8 @@ const webpackNiceLog = require('webpack-nicelog');
const webpack = require('webpack'); const webpack = require('webpack');
const path = require('path'); const path = require('path');
const chalk = require('chalk'); const chalk = require('chalk');
const fs = require('fs-extra');
const globby = require('globby');
const load = require('../load'); const load = require('../load');
const createProdConfig = require('../webpack/prod'); const createProdConfig = require('../webpack/prod');
@ -51,6 +53,20 @@ module.exports = async function build(siteDir, cliOptions = {}) {
await compile(config); await compile(config);
const {outDir} = props; const {outDir} = props;
// copy static files
const staticDir = path.resolve(siteDir, 'static');
const staticFiles = await globby(['**'], {
cwd: staticDir
});
await Promise.all(
staticFiles.map(async source => {
const fromPath = path.resolve(staticDir, source);
const toPath = path.resolve(outDir, source);
return fs.copy(fromPath, toPath);
})
);
const relativeDir = path.relative(process.cwd(), outDir); const relativeDir = path.relative(process.cwd(), outDir);
console.log( console.log(
`\n${chalk.green('Success!')} Generated static files in ${chalk.cyan( `\n${chalk.green('Success!')} Generated static files in ${chalk.cyan(