Почему дублируются сообщения в консоли браузера?
Почему дублируются сообщения в консоли браузера? Причём как служебные так и console.log() в коде модуля.
const path = require('path');
const fs = require('fs');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const {
CleanWebpackPlugin
} = require('clean-webpack-plugin');
const webpack = require('webpack');
const PATHS = {
src: path.join(__dirname, '../src'),
dist: path.join(__dirname, '../dist'),
site_pages: path.join(__dirname, '../src/components/site-pages'),
ui_kit: path.join(__dirname, '../src/components/ui-kit'),
assets: 'assets/',
};
// Pages const for HtmlWebpackPlugin
const PAGES_DIR = `${PATHS.src}/pages`;
const PAGES = fs
.readdirSync(PAGES_DIR)
.filter((filename) => filename.endsWith('.pug'));
module.exports = {
externals: {
paths: PATHS,
},
entry: {
'app': `${PATHS.src}/app.ts`,
'index': `${PATHS.site_pages}/index/index.ts`,
},
output: {
filename: `${PATHS.assets}js/[name].[hash].js`,
path: PATHS.dist,
},
optimization: {
splitChunks: {
cacheGroups: {
vendor: {
name: 'vendors',
test: /node_modules/,
chunks: 'all',
enforce: true,
},
},
},
},
module: {
rules: [{
test: /\.pug$/,
loader: 'pug-loader',
},
{
test: /\.m?js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env'],
},
},
},
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
'@babel/preset-env',
'@babel/preset-typescript',
],
},
},
},
{
test: /\.(woff(2)?|ttf|eot|svg)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader',
options: {
outputPath: 'assets/fonts',
publicPath: '../fonts',
name: '[name].[ext]',
limit: 1000,
},
},
{
test: /\.(png|jpg|gif|svg)$/,
loader: 'url-loader',
options: {
name: '[name].[ext]',
},
},
{
test: /\.scss$/,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: true,
config: {
path: './postcss.config.js'
},
},
},
{
loader: 'sass-loader',
options: {
sourceMap: true
},
},
],
},
],
},
resolve: {
alias: {
'~': 'src',
},
extensions: ['.tsx', '.ts', '.js'],
},
plugins: [
new webpack.ProvidePlugin({
$: 'jquery',
jquery: 'jquery',
jQuery: 'jquery',
'window.jquery': 'jquery',
'window.jQuery': 'jquery',
}),
new CleanWebpackPlugin(),
new MiniCssExtractPlugin({
filename: `${PATHS.assets}css/[name].[hash].css`,
}),
new CopyWebpackPlugin([{
from: `${PATHS.src}/components/**/*.{jpg,jpeg,png,svg,gif}`,
to: `${PATHS.assets}img`,
flatten: true,
},
{
from: `${PATHS.src}/static`,
to: ''
},
]),
...PAGES.map(
(page) => new HtmlWebpackPlugin({
template: `${PAGES_DIR}/${page}`, // .pug
filename: `./${page.replace(/\.pug/, '.html')}`, // .html
chunks: ['app', 'vendors', path.parse(page).name],
}),
),
],
};
const webpack = require('webpack');
const {
merge
} = require('webpack-merge');
const baseWebpackConfig = require('./webpack.base.conf');
const devWebpackConfig = merge(baseWebpackConfig, {
mode: 'development',
target: 'web',
devtool: 'eval-cheap-module-source-map',
stats: {
children: true,
},
devServer: {
contentBase: baseWebpackConfig.externals.paths.dist,
port: 8081,
public: 'localhost:8081',
overlay: {
warnings: true,
errors: true,
},
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.SourceMapDevToolPlugin({
filename: '[file].map',
}),
],
});
module.exports = new Promise((resolve, reject) => {
resolve(devWebpackConfig);
});
Ответы (1 шт):
Автор решения: Divatoz
→ Ссылка
Сообщения задваиваются из-за лишней точки входа index ...
'index': `${PATHS.site_pages}/index/index.ts`
... js которой импортируется в app.js
