Answer the question
In order to leave comments, you need to log in
How to edit webpack config for layout?
Here's exactly what I've done so far
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const { CleanWebpackPlugin } = require('clean-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
const cssRegx = /\.css$/
const imgRegx = /\.(png|jpe?g|gif)$/i
const htmlRegx = /\.(html)$/
module.exports = {
context: path.resolve(__dirname, 'src'),
mode: 'development',
entry: {
main: './home/main.js',
sakura: './home/sakura.js'
},
output: {
filename: 'js/[name].[contenthash].js',
path: path.resolve(__dirname, 'dist')
},
plugins: [
new HtmlWebpackPlugin({
template: './index.html'
}),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: 'css/[name].[contenthash].css',
chunkFilename: 'css/[name].[contenthash].chunk.css'
})
],
module: {
rules: [
{
test: cssRegx,
use: [
'style-loader',
{
loader: MiniCssExtractPlugin.loader,
options: {
publicPath: './dist',
minimize: true
}
},
'css-loader'
]
},
{
test: imgRegx,
use: [
{
loader: 'file-loader',
options: {
name: '[name].[ext]',
outputPath: 'img',
}
},
],
}
]
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question