Answer the question
In order to leave comments, you need to log in
How to prevent Webpack from generating styles, ejs templates in a js bundle?
There is this config:
const wpConf = {
entry: {
index: "./src/pages/index.ejs",
about: "./src/pages/about.ejs",
styles: "./src/css/styles.css"
},
output: {
clean: true,
filename: 'js/[name].bundle.js',
path: path.resolve(__dirname, 'dist'),
},
module: {
rules: [
{
test: /\.css$/i,
use: [
MiniCssExtractPlugin.loader,
"css-loader",
{ loader: "postcss-loader" },
],
},
{
test: /\.ejs$/,
use: [
{ loader: 'ejs-loader', options: { esModule: false } },
],
}
],
},
plugins: [
new MiniCssExtractPlugin({
filename: 'css/[name].css',
chunkFilename: 'css/[id].css',
}),
new HtmlWebpackPlugin({
filename: `index.html`,
chunks: ['index', 'styles'],
template: `./src/pages/${title}.ejs`,
}),
new HtmlWebpackPlugin({
filename: `about.html`,
chunks: ['about', 'styles'],
template: `./src/pages/${title}.ejs`,
}),
],
resolve: {
extensions: ['.js', '.json', '.ejs'],
},
};
asset js/about.bundle.js 1.1 KiB [emitted] [minimized] (name: about)
asset js/index.bundle.js 1.1 KiB [emitted] [minimized] (name: index)
asset js/runtime.bundle.js 924 bytes [emitted] [minimized] (name: runtime)
asset js/styles.bundle.js 138 bytes [emitted] [minimized] (name: styles)
assets by path *.html 1.12 KiB
asset about.html 572 bytes [emitted]
asset index.html 570 bytes [emitted]
asset css/styles.css 139 bytes [emitted] (name: styles)
"use strict";(self.webpackChunkfrontend_boilerplate=self.webpackChunkfrontend_boilerplate||[]).push([[532],{894:()=>{}},e=>{e(e.s=894)}]);
(self.webpackChunkfrontend_boilerplate=self.webpackChunkfrontend_boilerplate||[]).push([[179],{617:(module,__unused_webpack_exports,__webpack_require__)=>{module.exports=function(obj){obj||(obj={});var __t,__p="";with(obj)__p+='<!DOCTYPE html>\n<html class="no-js" lang="ru">\n<head>\n '+(null==(__t=__webpack_require__(89)({title}))?"":__t)+'\n</head>\n<body class="body-content">\n '+(null==(__t=__webpack_require__(732)())?"":__t)+"\n "+(null==(__t=__webpack_require__(162)())?"":__t)+"\n</body>\n</html>\n";return __p}},162:module=>{module.exports=function(obj){obj||(obj={});var __t,__p="";with(obj)__p+='<footer class="footer">\n <p>...</p>\n</footer>\n';return __p}},89:module=>{module.exports=function(obj){obj||(obj={});var __t,__p="";with(obj)__p+='<meta charset="utf-8">\n<meta name="viewport" content="width=device-width, initial-scale=1.0">\n<title>'+(null==(__t=title)?"":__t)+"</title>\n";return __p}},732:module=>{module.exports=function(obj){obj||(obj={});var __t,__p="";with(obj)__p+='<header class="header">\n</header>\n';return __p}}},_=>{_(_.s=617)}]);
Answer the question
In order to leave comments, you need to log in
You get the files that you specified in entry.
I want webpack to not generate `styles.bundle.js` because it already generated `css/styles.css`,
Same with ejs,
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question