Webpack(webpackConfig, function (arg1, arg2) { var html if (arg2.compilation.assets) { html = arg2.compilation.assets['index.html'].source() } else { html = '<!doctype html>' } // Due to a bug with the style-loader we have to "touch" a file // to force a rebundle after the initial one. Kudos to my colleague // Stephan for this one fs.writeFile('./public/index.html', html, function(err) { if (err) { console.log(err); } }) fs.writeFileSync(mainPath, fs.readFileSync(mainPath).toString()) console.log('Project is ready!') })
webpack({ mode: 'production', entry: { main: path.resolve(__dirname, './index.js') }, output: {} }, (err, stats) => { if (!err) { const template = fs.readFileSync(path.resolve(__dirname, './index.tpl'), 'utf8') const code = Simplite.toCodeBlock(template) let jsContent = stats.compilation.assets['main.js']._value const render = ` module.exports = (data) => { data.__main__ = ${JSON.stringify(jsContent)} return Function('_this',${JSON.stringify(code)}).call({defaultAttr:v=>v},data); } ` fs.writeFileSync(path.resolve(__dirname, '../../dist/render.js'), render) fs.unlinkSync(path.resolve(__dirname, '../../dist/main.js')) } else { console.log(err) } })