Skip to content

Instantly share code, notes, and snippets.

@alfonsodev
Last active February 7, 2017 14:30
Show Gist options
  • Select an option

  • Save alfonsodev/5186c274b7146465fd3e50f57470fd20 to your computer and use it in GitHub Desktop.

Select an option

Save alfonsodev/5186c274b7146465fd3e50f57470fd20 to your computer and use it in GitHub Desktop.
javascript babel-webpack latest basic boilerplate

Basic manual babel latests + webpack boilerplate.

npm init -y

Install npm modules

npm install --save-dev babel babel-core babel-loader babel-preset-latest-node6 json-loader webpack 

copy the webpack.config.js file to your project.

The webpack.config.js is in this same gist.
The first code block in that file is to list node_modules that have to be ignored.

create src and build folders

mkdir src build
touch src/index.js

var path = require('path');
var fs = require('fs');
var webpack = require('webpack');
var nodeModules = {};
fs.readdirSync(path.resolve(__dirname, 'node_modules'))
.filter(x => ['.bin'].indexOf(x) === -1)
.forEach(mod => {
nodeModules[mod] = `commonjs ${mod}`;
});
module.exports = {
"target": "node",
externals: nodeModules,
entry: {
main: __dirname + '/src/index.js'
},
output: {
path: __dirname + "/build",
filename: "[name].js",
libraryTarget: 'umd'
},
module: {
loaders: [
{
test: /\.js$/,
exclude: /(node_modules|bower_components)/,
loader: 'babel-loader',
query: {
presets: ['latest-node6']
}
},
{
test: /\.json$/,
loader: 'json'
}
]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment