const path = require("path");
const webpack = require("webpack");
const CleanWebpackPlugin = require('clean-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
module.exports = {
entry: ["./src/hello.js", "./src/scss/custom.scss"],
mode: "development",
output: {
filename: "bundle.js",
path: path.resolve(__dirname, "dist")
},
devServer: {
contentBase: "./dist",
watchContentBase: true
},
devtool: 'inline-source-map',
plugins: [
new CleanWebpackPlugin(),
new webpack.HotModuleReplacementPlugin(),
new HtmlWebpackPlugin({
hash: true,
title: 'My Awesome application',
header: 'Hello World',
template: './src/index.html',
filename: './index.html' //relative to root of the application
}),
new CopyWebpackPlugin([
{ context: './src/scripts/', from: '**/*.html', to: './' },
{ context: './src/', from: 'assets/*', to: './' },
]),
new webpack.HotModuleReplacementPlugin()
],
module: {
rules: [
{
test: /\.(scss)$/,
use: [
{
// Adds CSS to the DOM by injecting a `<style>` tag
loader: 'style-loader'
},
{
// Interprets `@import` and `url()` like `import/require()` and will resolve them
loader: 'css-loader'
},
{
// Loader for webpack to process CSS with PostCSS
loader: 'postcss-loader',
options: {
plugins: function () {
return [
require('autoprefixer')
];
}
}
},
{
// Loads a SASS/SCSS file and compiles it to CSS
loader: 'sass-loader'
}
]
},
{
test: /\.(png|svg|jpg|gif)$/,
use: ["file-loader"]
}
]
}
};