Skip to content

Instantly share code, notes, and snippets.

@RichardBray
Last active August 18, 2017 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RichardBray/ea782492ba8e7c4e883c392ae386b695 to your computer and use it in GitHub Desktop.
Save RichardBray/ea782492ba8e7c4e883c392ae386b695 to your computer and use it in GitHub Desktop.
Basic webpack js config
const path = require('path');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CleanWebpackPlugin = require('clean-webpack-plugin');
var extractPlugin = new ExtractTextPlugin({
filename: 'main.css'
});
module.exports = {
entry: './src/js/app.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js'
},
module: {
rules: [
{
test: /\.js$/,
use: [
{
loader: 'babel-loader',
options: {
presets: ['es2016']
}
}
]
},
{
test: /\.scss$/,
use: extractPlugin.extract({
use: ['css-loader', 'sass-loader']
})
},
{
test: /\.html$/,
loader: 'html-loader'
},
{
test:/\.(jpg|png)$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]'
}
}
]
},
{
test:/\.html$/,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
}
}
],
exclude: path.resolve(__dirname, 'src/index.html')
}
]
},
plugins: [
extractPlugin,
new HtmlWebpackPlugin({
template: 'src/index.html'
}),
new CleanWebpackPlugin(['dist'])
]
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment