Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Clean build folder and use build path from webpack.config.js #28

Merged
merged 1 commit into from
Aug 1, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions packages/accurapp-scripts/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,21 @@ const chalk = require('chalk')
const path = require('path')
const fs = require('fs-extra')
const { measureFileSizesBeforeBuild, printFileSizesAfterBuild } = require('react-dev-utils/FileSizeReporter')
const { log, createWebpackCompiler, coloredBanner } = require('./_utils')
const { log, createWebpackCompiler, readWebpackConfig, coloredBanner } = require('./_utils')

const appDir = process.cwd()
const config = readWebpackConfig()
const appPublic = path.join(appDir, 'public')
const appBuild = path.join(appDir, 'build')
const appBuild = config.output.path
const relativeAppBuildPath = `${path.relative(appDir, appBuild)}/`

function clearBuildFolder() {
log.info(`Cleaning ${chalk.cyan(relativeAppBuildPath)}`)
fs.emptyDirSync(appBuild)
}

function copyPublicFolder() {
log.info(`Copying ${chalk.cyan('public/')} folder...`)
log.info(`Copying ${chalk.cyan('public/')} into ${chalk.cyan(relativeAppBuildPath)}`)
fs.copySync(appPublic, appBuild, {
overwrite: true,
dereference: true,
Expand All @@ -26,7 +33,7 @@ function copyPublicFolder() {
function build() {
log.info(`Creating an optimized production build...`)
const compiler = createWebpackCompiler(() => {
log.ok(`The ${chalk.cyan('build/')} folder is ready to be deployed.`)
log.ok(`The ${chalk.cyan(relativeAppBuildPath)} folder is ready to be deployed.`)
}, () => {
log.err(`Aborting`)
process.exit(2)
Expand All @@ -47,6 +54,7 @@ console.log(coloredBanner('/||||/| accurapp', ['cyan', 'magenta']))

measureFileSizesBeforeBuild(appBuild)
.then((previousFileSizes) => {
clearBuildFolder()
copyPublicFolder()
build()
.then((stats) => {
Expand Down
Loading