Olá Alura!
Ao utilizar o splitChunks (em substituição ao CommonsChunkPlugin) e executar npm run build-dev
, está retornando o erro:
ERROR in chunk vendor~main [initial]
vendor.bundle.js
Conflict: Multiple chunks emit assets to the same filename vendor.bundle.js (chunks 1 and 1)
Child mini-css-extract-plugin ../projeto-webpack\client\node_modules\css-loader\dist\cjs.js!../../projeto-webpack\client\css\cssqualquer.css:
Entrypoint mini-css-extract-plugin = *
[0] ./node_modules/css-loader/dist/cjs.js!./css/cssqualquer.css 356 bytes {0} [built]
+ 1 hidden module
Child mini-css-extract-plugin ../projeto-webpack\client\node_modules\css-loader\dist\cjs.js!../../projeto-webpack\client\node_modules\bootstrap\dist\css\bootstrap.css:
Entrypoint mini-css-extract-plugin = *
2 modules
- arquivo webpack.config.js
const path = require('path');
const babiliPlugin = require('babili-webpack-plugin');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const optimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
const webpack = require('webpack');
let plugins = [];
plugins.push(new MiniCssExtractPlugin(
{
filename: 'styles.css'
}
));
plugins.push(
new webpack.ProvidePlugin({
'$': 'jquery/dist/jquery.js',
'jQuery': 'jquery/dist/jquery.js'
})
);
if (process.env.NODE_ENV == 'production') {
plugins.push(new webpack.optimize.ModuleConcatenationPlugin());
plugins.push(new babiliPlugin());
plugins.push(new optimizeCSSAssetsPlugin({
cssProcessor: require('cssnano'),
cssProcessorOptions: {
discardComments: {
removeAll: true
}
},
canPrint: true
}));
}
module.exports = {
mode: 'none',
entry: path.resolve(__dirname, 'app-src/app.js'),
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
publicPath: 'dist'
},
optimization: { // substituto do CommonsChunkPlugin
splitChunks: {
cacheGroups: {
vendor: {
filename: 'vendor.bundle.js', // bundle das bibliotecas de terceiros
test: /[\\/]node_modules[\\/](jquery|bootstrap|reflect-metadata)[\\/]/,
chunks: 'all'
}
}
}
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader'
}
},
{
test: /\.css$/,
use: [MiniCssExtractPlugin.loader, 'css-loader']
},
{
test: /\.(woff|woff2)(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=application/font-woff'
},
{
test: /\.ttf(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=application/octet-stream'
},
{
test: /\.eot(\?v=\d+\.\d+\.\d+)?$/,
loader: 'file-loader'
},
{
test: /\.svg(\?v=\d+\.\d+\.\d+)?$/,
loader: 'url-loader?limit=10000&mimetype=image/svg+xml'
}
]
},
plugins
}
arquivo package.json
{ "name": "client", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build-dev": "webpack --config webpack.config.js", "build-prod": "cross-env NODE_ENV=production webpack --config webpack.config.js", "start": "webpack-dev-server" }, "author": "", "license": "ISC", "dependencies": { "@babel/runtime": "^7.11.2", "bootstrap": "^4.5.2", "core-js": "^3.6.5", "jquery": "^3.5.1", "reflect-metadata": "^0.1.10" }, "devDependencies": { "@babel/core": "^7.11.6", "@babel/plugin-proposal-decorators": "^7.10.5", "@babel/plugin-transform-runtime": "^7.11.5", "@babel/preset-env": "^7.11.5", "babel-loader": "^8.1.0", "babili-webpack-plugin": "^0.1.2", "cross-env": "^7.0.2", "css-loader": "^4.3.0", "cssnano": "^4.1.10", "file-loader": "^6.1.1", "mini-css-extract-plugin": "^1.0.0", "optimize-css-assets-webpack-plugin": "^5.0.4", "style-loader": "^2.0.0", "url-loader": "^4.1.1", "webpack": "^4.44.2", "webpack-cli": "^3.3.12", "webpack-dev-server": "^3.11.0" } }
arquivo cssqualquer.css
/* comentário teste */
table {
box-shadow: 5px 5px 5px black;
}
- arquivo app.js
import 'core-js'; // sanar problema com a tag <script> do index.html q n carregava
import { NegociacaoController } from './controllers/NegociacaoController.js';
import { Negociacao } from './domain/index.js';
import 'bootstrap/dist/css/bootstrap.css';
import '../css/cssqualquer.css';
import 'bootstrap/js/dist/modal';
import 'reflect-metadata/Reflect.js';
const controller = new NegociacaoController();
// ...
Aguardo, desde já obrigado.