What is `require.context`?

One of the main features of webpack’s compiler is to recursively parse all the modules, starting from the entries, to build a graph of all the module dependencies by analyzing require(), require.context(), import and import() expressions. The usual interpretation of “context” in webpack, and similarly in Node.js, is some directory that is used as a … Read more

Is it possible to create custom resolver in webpack?

Yes, it’s possible. To avoid ambiguity and for easier implementation, we’ll use a prefix hash symbol as marker of your convention: require(“#./components/SettingsPanel”); Then add this to your configuration file (of course, you can refactor it later): var webpack = require(‘webpack’); var path = require(‘path’); var MyConventionResolver = { apply: function(resolver) { resolver.plugin(‘module’, function(request, callback) { … Read more

Webpack: “there are multiple modules with names that only differ in casing” but modules referenced are identical

This is usually a result of a minuscule typo. For instance, if you are importing your modules like this: import Vue from ‘vue’ or: import Vuex from ‘vuex’ Go through your files and check where you used phrases like from ‘Vue’ or from ‘Vuex’ and make sure to use the exact same capitals (uppercase letters) … Read more

Cannot find module ‘webpack/bin/config-yargs’

If you’re using webpack-cli 4 or webpack 5, change webpack-dev-server to webpack serve. Example: “serve”: “webpack serve –config config/webpack.dev.js –progress” You might want also check this comment on GitHub: NPM package.json scripts are a convenient and useful means to run locally installed binaries without having to be concerned about their full paths. Simply define a … Read more

How to inline CSS in the head tag of a NextJS project?

I managed to successfully inline my CSS by slightly tweaking the pages/_document.jsx file. I extended the <Head> component natively provided with NextJS and added it to my custom document markup. Here’s a partial representation of my modifications: import { readFileSync } from ‘fs’; import { join } from ‘path’; class InlineStylesHead extends Head { getCssLinks() … Read more