Skip to content

Commit

Permalink
✨ Clean build folder before building and use build path specified in …
Browse files Browse the repository at this point in the history
…webpack config

This fix will clean the build folder before compilation and allows to change the build path on your local webpack.config.js file
  • Loading branch information
markov00 committed Jul 27, 2017
1 parent fa07d61 commit c4abd28
Show file tree
Hide file tree
Showing 4 changed files with 4,605 additions and 4 deletions.
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

0 comments on commit c4abd28

Please sign in to comment.