Created
May 2, 2018 23:38
-
-
Save iandanforth/fdf989ab15d650042a1066396d0decab to your computer and use it in GitHub Desktop.
build.js diff
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
diff --git a/app/tools/build.js b/app/tools/build.js | |
index 936182e..7a3af61 100644 | |
--- a/app/tools/build.js | |
+++ b/app/tools/build.js | |
@@ -6,11 +6,15 @@ | |
const path = require('path'); | |
const shell = require('shelljs'); | |
const crypto = require('crypto'); | |
-const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer'); | |
+const { | |
+ BundleAnalyzerPlugin | |
+} = require('webpack-bundle-analyzer'); | |
const webpack = require('webpack'); | |
const ProgressPlugin = require('webpack/lib/ProgressPlugin'); | |
const config = require('../webpack-config')('dist'); | |
-const { ArgumentParser } = require('argparse'); | |
+const { | |
+ ArgumentParser | |
+} = require('argparse'); | |
const parser = new ArgumentParser({ | |
addHelp: true, | |
@@ -46,12 +50,15 @@ if (args.profile) { | |
})); | |
} | |
-// Clean folder | |
+// Clean folders | |
const buildFolder = path.join(__dirname, '../build'); | |
shell.rm('-rf', buildFolder); | |
shell.mkdir(buildFolder); | |
shell.mkdir(`${buildFolder}/static`); | |
+const docsFolder = path.join(__dirname, '../../docs'); | |
+shell.rm('-rf', docsFolder); | |
+ | |
// Bundle versioning using timestamp hash to prevent browser cache. | |
const timestamp = crypto | |
.createHash('md5') | |
@@ -65,12 +72,16 @@ const timestamp = crypto | |
let lines = shell.cat(path.join(__dirname, '../src/index.html')).split(/\r?\n/); | |
lines = lines.filter(line => line.indexOf('/.tmp/dev-vendors.js') < 0); // remove dev-vendors | |
let indexHtml = lines.join('\n'); | |
-indexHtml = indexHtml.replace('/static/main.js', `/static/main.${timestamp}.js`); | |
+indexHtml = indexHtml.replace('/static/main.js', `static/main.${timestamp}.js`); | |
+indexHtml = indexHtml.replace('/favicon.png', 'favicon.png'); | |
shell.ShellString(indexHtml).to(path.join(buildFolder, 'index.html')); | |
// Copy favicon | |
shell.cp(path.join(__dirname, '../src/favicon.png'), buildFolder); | |
+// Copy images | |
+shell.cp('-R', path.join(__dirname, '../src/images'), buildFolder); | |
+ | |
// Webpack build | |
console.log('Building, it may take a few seconds...'); | |
console.time('Done'); | |
@@ -92,8 +103,13 @@ compiler.run((err) => { | |
// Add timestamp hash to bundle file name. | |
// Use timeout so that the bundle analyzer will find main.js before renaming. | |
setTimeout(() => { | |
- shell.mv(path.join(buildFolder, './static/main.js'), path.join(buildFolder, `/static/main.${timestamp}.js`)); | |
+ shell.mv(path.join(buildFolder, './static/main.js'), path.join( | |
+ buildFolder, `/static/main.${timestamp}.js`)); | |
console.timeEnd('Done'); | |
+ | |
+ // Copy build to docs | |
+ shell.cp('-R', buildFolder, docsFolder); | |
+ | |
}, 100); | |
} | |
-}); | |
+}); | |
\ No newline at end of file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment