Начал разбирать webpack, и столкнулся с проблемой. Например, в файле index.js подключаю normalize и bootstrap.css, но они обьединяются в один файл vendors~main.css. Как их разъединить ?
Код с webpack.config.js
const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const CopyPlugin = require('copy-webpack-plugin');
const isDev = process.env.NODE_ENV === "development";
const isProd = process.env.NODE_ENV === "production";
module.exports = {
mode: 'development', // метод по умолчанию
// context: path.resolve(__dirname, "src"), // папка исходных файлов
entry: {
main: ["@babel/polyfill", './src/index.js'],
},
output: {
filename: '[name].js',
path: path.resolve(__dirname, 'assets'),
},
resolve: {
alias: {
"@": path.resolve(__dirname, "src"), // теперь @ - ссылка на путь корневой папки, если прописывать в import в index.js
}
},
optimization: {
splitChunks: {
// chunks: "all", // разделить подключенные файлы
cacheGroups: {
styles: {
name: 'styles',
test: /\.css$/,
chunks: 'all',
enforce: true,
},
},
}
},
devtool: 'inline-source-map',
devServer: {
contentBase: './assets',
},
plugins: [
new CleanWebpackPlugin(),
new HtmlWebpackPlugin({
template: "./src/index.html",
minify: {
collapseWhitespace: isProd,
}
}),
new MiniCssExtractPlugin({
filename: '/styles/css/[name].css',
chunkFilename: '/styles/css/[name].css',
}),
new CopyPlugin([
{ from: 'src/styles/scss/', to: 'styles/scss/' },
// { from: 'src/fonts/', to: 'fonts/' },
// { from: 'src/images/', to: 'images/' },
// { from: 'src/files/', to: 'files/' },
]),
],
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
loader: {
loader: "babel-loader",
options: {
presets: [
"@babel/preset-env"
]
}
}
},
{
test: /\.css$/,
use: [
MiniCssExtractPlugin.loader,
'css-loader',
{
loader: "postcss-loader",
options: {
sourceMap: true,
config: {
path: "src/js-config/postcss.config.js"
}
}
},
],
},
{
test: /\.s[ac]ss$/i,
use: [
'style-loader',
MiniCssExtractPlugin.loader,
{
loader: 'css-loader',
options: {
sourceMap: true,
},
},
{
loader: "postcss-loader",
options: {
sourceMap: true,
config: {
path: "src/js-config/postcss.config.js"
}
}
},
{
loader: 'sass-loader',
options: {
sourceMap: true,
},
},
],
},
{
test: /\.(png|svg|jpg|jpeg|gif)$/,
use: [
'file-loader',
],
},
{
test: /\.(woff|woff2|eot|ttf|otf)$/,
use: [
{
loader: 'file-loader',
options: {
// context: 'public',
name: 'assets/images/[name].[ext]?v=[hash]',
// publicPath: './',
},
},
],
},
{
test: /\.(csv|tsv)$/,
use: [
'csv-loader',
],
},
{
test: /\.xml$/,
use: [
'xml-loader',
],
},
],
},
};