I am going through a CSS course and have got tired of typing out similar HTML structures by hand, so I hooked up pug templates and webpack-dev-server to serve it.
NOTE: my entry point is .scss
file not .js
I have two issues:
a) only assets from css get loaded to build folder, but images and svg's that are referenced in src
attributes in .pug
template are left out.
b) browser reloading doesn't work in webpack-dev-server
My webpack.config.js
:
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
module.exports = {
entry: './sass/main.scss',
output: {
path: path.resolve(__dirname, 'build'),
filename: 'css/style.css',
},
mode: 'development',
module: {
rules: [
{
test: /\.pug$/,
use: ['pug-loader'],
},
{
test: /\.(css|sass|scss)$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: [
{
loader: 'css-loader',
},
{
loader: 'postcss-loader',
},
{
loader: 'sass-loader',
},
]
})
},
{
test: /\.(gif|png|jpe?g|svg)$/i,
use: [
// {
// loader: 'file-loader',
// options: {
// name: 'img/[name].[ext]',
// }
// },
{
loader: 'url-loader',
options: {
limit: 10000,
publicPath: "../",
name: 'img/[name].[ext]',
}
}
],
}
],
},
plugins: [
new HtmlWebpackPlugin({
template: './test.pug',
filename: 'index.html',
favicon: 'img/favicon.png',
cache: false,
}),
new ExtractTextPlugin('css/style.css'),
],
devServer: {
contentBase: path.join(__dirname, 'build'),
compress: true,
open: 'firefox',
port: 8080,
hot: true,
},
};
Please advise.