Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade webpack@5 to fix CI builds #6509

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"@commitlint/config-conventional": "^16.0.0",
"@emotion/eslint-plugin": "^11.0.0",
"@octokit/rest": "^16.28.7",
"@soda/friendly-errors-webpack-plugin": "^1.8.1",
"@storybook/addon-actions": "^5.3.6",
"@storybook/addon-links": "^5.3.6",
"@storybook/react": "^5.3.6",
Expand Down Expand Up @@ -135,7 +136,6 @@
"eslint-plugin-react": "^7.17.0",
"eslint-plugin-unicorn": "^41.0.1",
"execa": "^5.0.0",
"friendly-errors-webpack-plugin": "^1.7.0",
"fs-extra": "^10.0.0",
"gitlab": "^14.1.1",
"http-server": "^14.0.0",
Expand All @@ -150,16 +150,19 @@
"nock": "^13.0.0",
"node-fetch": "^2.3.0",
"npm-run-all": "^4.1.5",
"path-browserify": "^1.0.1",
"postcss": "^8.4.7",
"postcss-scss": "^4.0.3",
"prettier": "^2.3.0",
"process": "^0.11.10",
"react": "^16.12.0",
"react-dom": "^16.12.0",
"react-test-renderer": "^16.8.4",
"rehype": "^7.0.0",
"rimraf": "^3.0.0",
"simple-git": "^3.0.0",
"start-server-and-test": "^1.7.11",
"stream-browserify": "^3.0.0",
"stylelint": "^14.5.3",
"stylelint-config-standard-scss": "^3.0.0",
"stylelint-config-styled-components": "^0.1.1",
Expand All @@ -168,8 +171,8 @@
"to-string-loader": "^1.1.5",
"typescript": "^3.7.2",
"unist-util-visit": "^1.4.0",
"webpack": "^4.29.6",
"webpack-cli": "^4.0.0",
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0",
"webpack-dev-server": "^3.2.1"
},
"workspaces": {
Expand Down
4 changes: 2 additions & 2 deletions packages/netlify-cms-editor-component-image/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
},
"devDependencies": {
"cross-env": "^7.0.0",
"webpack": "^4.29.6",
"webpack-cli": "^4.0.0"
"webpack": "^5.73.0",
"webpack-cli": "^4.10.0"
},
"peerDependencies": {
"react": "^16.8.4 || ^17.0.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/netlify-cms-proxy-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"ts-loader": "^8.0.0",
"ts-node": "^10.0.0",
"tsconfig-paths-webpack-plugin": "^3.2.0",
"webpack": "^4.41.5",
"webpack": "^5.73.0",
"webpack-node-externals": "^3.0.0"
},
"engines": {
Expand Down
2 changes: 1 addition & 1 deletion packages/netlify-cms/webpack.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path');
require('dotenv').config({ path: path.join(__dirname, '..', '..', '.env') });
const webpack = require('webpack');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const FriendlyErrorsWebpackPlugin = require('@soda/friendly-errors-webpack-plugin');
Copy link
Author

@adunkman adunkman Jul 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • friendly-errors-webpack-plugin does not support webpack@5 and is archived on GitHub.
  • @soda/friendly-errors-webpack-plugin is a fork which supports webpack@5.

const CopyWebpackPlugin = require('copy-webpack-plugin');

const pkg = require('./package.json');
Expand Down
25 changes: 22 additions & 3 deletions scripts/webpack.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');
const webpack = require('webpack');
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin');
const FriendlyErrorsWebpackPlugin = require('@soda/friendly-errors-webpack-plugin');
const { flatMap } = require('lodash');

const { toGlobalName, externals } = require('./externals');
Expand Down Expand Up @@ -44,8 +44,21 @@ function rules() {

function plugins() {
return {
ignoreEsprima: () => new webpack.IgnorePlugin(/^esprima$/, /js-yaml/),
ignoreMomentOptionalDeps: () => new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
ignoreEsprima: () =>
new webpack.IgnorePlugin({
resourceRegExp: /^esprima$/,
contextRegExp: /js-yaml/,
}),
ignoreMomentOptionalDeps: () =>
new webpack.IgnorePlugin({
resourceRegExp: /^\.\/locale$/,
contextRegExp: /moment$/,
}),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The syntax for IgnorePlugin changed (new documentation):

If you are using IgnorePlugin with a regular expression as argument, it takes an options object now: new IgnorePlugin({ resourceRegExp: /regExp/ }).

includePolyfills: () =>
new webpack.ProvidePlugin({
Buffer: ['buffer', 'Buffer'],
process: 'process',
}),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Webpack 5 no longer includes automatic polyfills for Node.js:

In the early days, webpack's aim was to allow running most Node.js modules in the browser, but the module landscape changed and many module uses are now written mainly for frontend purposes. Webpack <= 4 ships with polyfills for many of the Node.js core modules, which are automatically applied once a module uses any of the core modules (i.e. the crypto module).

While this makes using modules written for Node.js easier, it adds these huge polyfills to the bundle. In many cases these polyfills are unnecessary.

Webpack 5 stops automatically polyfilling these core modules and focus on frontend-compatible modules. Our goal is to improve compatibility with the web platform, where Node.js core modules are not available.

It's possible to manually add a polyfill for a Node.js core module. An error message will give a hint on how to achieve that.

This (and the below fallback configuration lines) follow those hints.

friendlyErrors: () => new FriendlyErrorsWebpackPlugin(),
};
}
Expand Down Expand Up @@ -129,6 +142,12 @@ function baseConfig({ target = isProduction ? 'umd' : 'umddir' } = {}) {
alias: {
moment$: 'moment/moment.js',
},
fallback: {
buffer: require.resolve('buffer'),
path: require.resolve('path-browserify'),
process: require.resolve('process'),
stream: require.resolve('stream-browserify'),
},
},
plugins: Object.values(plugins()).map(plugin => plugin()),
devtool: isTest ? '' : 'source-map',
Expand Down
Loading