Skip to content

Instantly share code, notes, and snippets.

@hostmaster
Created August 7, 2017 07:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hostmaster/6ee9b8d015334297461c57f5ce67a221 to your computer and use it in GitHub Desktop.
Save hostmaster/6ee9b8d015334297461c57f5ce67a221 to your computer and use it in GitHub Desktop.
import fs from 'fs'
import path from 'path'
import config from '../constants/config.js'
const fs = require('fs')
const template_dir = path.resolve(__dirname, '../public')
const template_file = 'index.html'
const version = config.version.replace(/\./g, '')
fs.readFile(path.resolve(template_dir, template_file), 'utf8', (err, data) => {
if (err) return console.log(`Error while reading ${template_file}`)
const new_html = data.replace('bundle.js', `bundle_${version}.js`)
const new_html_file_name = `index_${version}.html`
fs.writeFile(`${template_dir}/${new_html_file_name}`, new_html, (err) => {
if (err) return console.log(`Error while writing ${new_html_file_name}`)
console.log(`GENERATED ${new_html_file_name}`)
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment