Skip to content

Instantly share code, notes, and snippets.

@alterebro
Created November 30, 2016 11:09
Show Gist options
  • Save alterebro/b3570eeb190a9c1a1186812096742831 to your computer and use it in GitHub Desktop.
Save alterebro/b3570eeb190a9c1a1186812096742831 to your computer and use it in GitHub Desktop.

init

# init project
$ npm init -y

# save dependencies
$ npm install --save-dev babel-core babel-loader babel-preset-es2015 css-loader extract-text-webpack-plugin html-webpack-plugin style-loader webpack 

webpack.config.js

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");

module.exports = {
	context: __dirname + "/src",
	entry: "./app.js",
	output: {
		path: path.resolve(__dirname, "./dist"),
		filename: "js/app.min.js",
	},
	module: {
		loaders: [
			{ test: /\.css$/, loader: ExtractTextPlugin.extract("style-loader", "css-loader") },
		    { test: /\.js$/,
		      exclude: /(node_modules|bower_components|dist)/,
		      loader: 'babel-loader',
		      query: { presets: ['es2015'] }
		  	}
        ]
	},
	plugins: [
		new HtmlWebpackPlugin({
			template: './app.html',
			inject: 'body',
			filename: 'index.html',
			minify: {collapseWhitespace: true, removeComments: true},
		}),
		new ExtractTextPlugin("css/app.min.css"),
		new webpack.optimize.UglifyJsPlugin({
			compress: { warnings: false },
			output: { comments: false }
		})
	]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment