Solving Duplicate Styles/Scripts warning #54
-
I'm using the plugin to generate a static site that I'll transform into a WordPress theme later. webpack.config.js //webpack.config.js
const path = require('path');
const PugPlugin = require('pug-plugin');
module.exports = {
entry: {
index: './src/index.pug',
},
output: {
path: path.join(__dirname, 'dist/'),
publicPath: 'dist/',
filename: 'assets/js/[name].[contenthash:8].js',
clean: true
},
plugins: [
new PugPlugin({
pretty: true,
extractCss: {
filename: 'assets/css/[name].[contenthash:8].css'
}
}),
new PugPlugin({
filename: 'about.pug',
pretty: true,
extractCss: {
filename: 'assets/css/[name].[contenthash:8].css'
}
})
],
module: {
rules: [
{
test: /\.pug$/,
loader: PugPlugin.loader
},
{
test: /\.(css|sass|scss)$/,
use: ['css-loader', 'sass-loader'],
generator: {
filename: 'assets/css/[name].phash:8][ext]'
}
},
{
test: /\.(png|jpg|jpeg|ico)/,
type: 'asset/resource',
generator: {
filename: 'assets/img/[name].[hash:8][ext]'
}
},
{
test: /\.(woff|woff2|eot|ttf|otf|svg)$/i,
type: 'asset/resource',
generator: {
filename: 'assets/fonts/[name][ext][query]'
}
}
]
},
stats: 'errors-only'
}; |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hello @kaili-kameoka, you has wrong Webpack config. Unlike the Please update const path = require('path');
const PugPlugin = require('pug-plugin');
module.exports = {
entry: {
// define all Pug files only here
index: './src/index.pug',
about: './src/about.pug',
},
output: {
path: path.join(__dirname, 'dist/'),
publicPath: '/', // Note: this is the path relative by output.path, or `auto`
clean: true
},
plugins: [
new PugPlugin({
pretty: true,
js: {
// since pug-plugin v4.6.0 place filename for JS here
filename: 'assets/js/[name].[contenthash:8].js',
},
// since pug-plugin v4.6.0 the 'extractCss' option is renamed to 'css'
css: {
filename: 'assets/css/[name].[contenthash:8].css'
},
}),
],
module: {
rules: [
{
test: /\.pug$/,
loader: PugPlugin.loader
},
{
test: /\.(css|sass|scss)$/,
use: ['css-loader', 'sass-loader'],
// don't use filename for CSS here, it must be defined by PugPlugin options, see above
//generator: {
// filename: 'assets/css/[name].phash:8][ext]'
//}
},
{
test: /\.(png|jpg|jpeg|ico)/,
type: 'asset/resource',
generator: {
filename: 'assets/img/[name].[hash:8][ext]'
}
},
{
test: /\.(woff|woff2|eot|ttf|otf|svg)$/i,
type: 'asset/resource',
generator: {
filename: 'assets/fonts/[name][ext][query]'
}
}
]
},
stats: 'errors-only'
}; |
Beta Was this translation helpful? Give feedback.
Hello @kaili-kameoka,
you has wrong Webpack config.
Unlike the
html-webpack-plugin
, thenew PugPlugin(..)
must be initialised only once inplugins
and all Pug files must be defined in Webpack entry.Please update
pug-plugin
tov4.6.0
. The new version has some improvements and optimization of options.