elf
elf copied to clipboard
Vendor file not being created because of chunk size being small
Hi! I was having some issues trying to setup a project through netlify. The error was :
ENOENT: no such file or directory, open './src/compiled-assets/vendor.js'
I did some investigating and after tweaking the webpack.common.js by enforcing the vendor file to be created I no longer got this bug. I think this is probably a niche case since the project I'm working on was at the very start but it could be worth adding that to config.
What I ended up with for webpack.common.js:
// Makes Sass faster!
const Fiber = require('fibers');
const MiniCssExtractPlugin = require('mini-css-extract-plugin');
const path = require('path');
module.exports = {
// Our "entry" point
entry: './src/assets/js/index.js',
output: {
// The global variable name any `exports` from `index.js` will be available at
library: 'SITE',
// Where webpack will compile the assets
path: path.resolve(__dirname, 'src/compiled-assets'),
},
module: {
rules: [
// Transpile and polyfill our JavaScript
{
test: /\.js$/,
use: 'babel-loader',
exclude: /node_modules/,
},
{
// Setting up compiling our Sass
test: /\.scss$/,
use: [
{
loader: MiniCssExtractPlugin.loader,
},
{
loader: 'css-loader',
options: {
url: false,
},
},
{
loader: 'postcss-loader',
},
{
loader: 'sass-loader',
options: {
// eslint-disable-next-line global-require
implementation: require('sass'),
sassOptions: {
fiber: Fiber,
outputStyle: 'expanded',
},
},
},
],
},
],
},
// Any `import`s from `node_modules` will compiled in to a `vendor.js` file.
optimization: {
splitChunks: {
cacheGroups: {
commons: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: 'all',
enforce: true,
},
},
},
},
plugins: [
new MiniCssExtractPlugin({
filename: '[name].css',
}),
],
};