Last active
August 18, 2017 16:59
-
-
Save RichardBray/ea782492ba8e7c4e883c392ae386b695 to your computer and use it in GitHub Desktop.
Basic webpack js config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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