'Get the complete folder structure in the output in multiple entries with webpack
I want to get the complete folder structure in the output. But now,if I use npm run start comand, doesn't load index.html and chrome gives a Cannot GET / error. And with the npm run build command, index.html does not load styles. Can you help with this please? My webpack conig:
const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const MiniCssExtractPlugin = require('mini-css-extract-plugin')
module.exports = {
entry: {
'pages/main/index' : './src/pages/main/index.js',
'pages/pets/pets' : './src/pages/pets/pets.js'
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'dist'),
publicPath: '',
assetModuleFilename: (pathData) => {
const filepath = path
.dirname(pathData.filename)
.split("/")
.slice(1)
.join("/");
return `${filepath}/[name].[hash][ext][query]`;
},
},
mode: 'development',
module: {
rules: [
{
test: /\.html$/i,
loader: "html-loader",
},
{
test: /\.s[ac]ss$/i,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
"sass-loader",
],
},
],
},
plugins: [
new HtmlWebpackPlugin({
template: './src/pages/main/index.html',
filename: './pages/main/index.html',
excludeChunks: ['pages/pets/pets']
}),
new HtmlWebpackPlugin({
template: './src/pages/pets/pets.html',
filename: './pages/pets/pets.html',
chunks: ['pages/pets/pets']
}),
new MiniCssExtractPlugin({
filename: '[name].css',
chunkFilename: "[id].css"
}),
],
devServer: {
compress: true,
port: 3000,
},
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
