task:
const fs = require('fs');
const param = process.env.page;
const webpackFile = './webpack.config.js';
const msgErr = (msg)=>{
console.log(msg);
process.exit();
}
if(!param) {
msgErr('param --page is required');
}
let webpackContent = fs.readFileSync(webpackFile).toString();
if(webpackContent.match(new RegExp(`entry\\['${param}'\\]`))) {
console.log(`Page exist: ${param}\n`);
console.log('webpack:', webpackContent);
process.exit();
}
let webpackNewContent = webpackContent.replace('entry = {};', `entry = {};\nentry['${param}'] = './${param}.js';`);
fs.writeFileSync(`./${param}.js`,'');
fs.writeFileSync(webpackFile, webpackNewContent);
console.log(`Page create: ${param}\n`);
console.log(webpackNewContent);
webpack config file
const entry = {};
module.exports = {
entry: entry,
output:{
filename:'./[name].bundle.js'
},
};