Skip to content

Instantly share code, notes, and snippets.

@brysonian
Last active May 19, 2018 04:54
Show Gist options
  • Select an option

  • Save brysonian/0a5a29b76cd58b983fb75abbe90e0b2c to your computer and use it in GitHub Desktop.

Select an option

Save brysonian/0a5a29b76cd58b983fb75abbe90e0b2c to your computer and use it in GitHub Desktop.
create-boilerplate

To create a new project run:

npx https://gist.github.com/brysonian/0a5a29b76cd58b983fb75abbe90e0b2c {PROJECT_NAME}
yarn

To run a dev server: yarn start

#!/usr/bin/env node
const fs = require('fs');
const path = require('path');
const { exec } = require('child_process');
const src = path.dirname(fs.realpathSync(process.argv[1]));
const dest = path.resolve(process.argv[2]);
const name = path.basename(dest);
if (!fs.existsSync(dest)) {
fs.mkdirSync(dest);
}
fs.createReadStream(`${src}/package.src.json`)
.pipe(fs.createWriteStream(`${dest}/package.json`));
fs.createReadStream(`${src}/webpack.config.src.js`)
.pipe(fs.createWriteStream(`${dest}/webpack.config.js`));
fs.mkdirSync(`${dest}/src`);
fs.mkdirSync(`${dest}/public`);
fs.writeFileSync(`${dest}/src/index.js`, '', (err) => {
if (err) throw err;
});
fs.writeFileSync(`${dest}/public/index.html`, `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>${name}</title>
</head>
<body>
<script src="bundle.js" type="text/javascript"></script>
</body>
</html>
`, (err) => {
if (err) throw err;
});
console.log(`
Project Created!
To get running:
cd ${name}
yarn
yarn start
`);
{"name": "create-boilerplate", "version": "0.0.0", "bin": "./index.js"}
{
"name": "PROJECT",
"version": "1.0.0",
"private": true,
"license": "MIT",
"scripts": {
"watch": "webpack --watch",
"build": "webpack",
"start": "webpack-dev-server --open"
},
"babel": {
"presets": [
"env",
"stage-2"
]
},
"devDependencies": {
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-2": "^6.24.1",
"webpack": "^4.8.3",
"webpack-cli": "^2.1.3",
"webpack-dev-server": "^3.1.4"
}
}
const path = require('path');
module.exports = {
entry: './src/index.js',
mode: 'development',
module: {
rules: [
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
use: ['babel-loader']
}
]
},
resolve: {
extensions: ['*', '.js', '.jsx']
},
devServer: {
contentBase: './public'
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'public')
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment