How to write Webpack plugin which adds modules to the bundle on the fly based on other modules?

This is a really complex question, but I can show how you can add additional dependencies to specific modules as if those were required from that module. This ensures that your added modules will be in the correct chunks and will also be removed if the parent module is removed from the bundle. const CommonJsRequireDependency … Read more

Ignore or prevent ESLint errors from breaking the build in a React project (create-react-project)

If you want to force ESLint to always emit warnings (that will not stop you build) instead of errors, you need to set emitWarning: true: { enforce: ‘pre’, include: paths.appSrc, test: /\.(js|jsx|mjs)$/, use: [{ loader: require.resolve(‘eslint-loader’), options: { formatter: eslintFormatter, eslintPath: require.resolve(‘eslint’), emitWarning: true, 👈 HERE }, }], }, As stated in the docs: Errors … Read more

Sourcemaps are detected in chrome but original source is not loaded, using webpack-2

Generated files with source maps won’t automatically redirect to their original files, because there’s potentially a 1-to-many relationship. If you see the message Source Map Detected, the original file should already appear on the side file tree or the file explorer via Crl + P. If you don’t know the original file name, you can … Read more

How to pass .env file variables to webpack config?

You can use dotenv package for this purpose. npm install dotenv –save After installing the package, add this in the top of your config: const webpack = require(‘webpack’); // only add this if you don’t have yet // replace accordingly ‘./.env’ with the path of your .env file require(‘dotenv’).config({ path: ‘./.env’ }); then in plugins … Read more

Output an ES module using webpack

Firstly I would like to state the difference between the commonJS and commonJS2 CommonJS doesn’t support the use of module.exports = function() {} which is used by node.js and many other commonJS implementations. Webpack2 employs the concept of the bundling the library code and for the widespread use of it and to make it compatible … Read more

Testing with Jest and Webpack aliases

This seems to have been fixed. Below is a working setup: Versions “jest”: “~20.0.4” “webpack”: “^3.5.6” package.json “jest”: { “moduleNameMapper”: { “^@root(.*)$”: “<rootDir>/src$1”, “^@components(.*)$”: “<rootDir>/src/components$1″, } } webpack.shared.js const paths = { APP_DIR: path.resolve(__dirname, ‘..’, ‘src’), }; exports.resolveRoot = [paths.APP_DIR, ‘node_modules’]; exports.aliases = { ‘@root’: path.resolve(paths.APP_DIR, ”), ‘@components’: path.resolve(paths.APP_DIR, ‘components’), };

How to determine the installed webpack version

Version Installed: Using webpack CLI: (–version, -v Show version number [boolean]) webpack –version or: webpack -v Using npm list command: npm list webpack Results in name@version-range: <projectName>@<projectVersion> /path/to/project └── webpack@<version-range> Using yarn list command: yarn list webpack How to do it programmatically? Webpack 2 introduced Configuration Types. Instead of exporting a configuration object, you may … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)