Skip to content

Commit

Permalink
upgrade: Webpack 5
Browse files Browse the repository at this point in the history
This is a work in progress to try upgrading to webpack 5.
  • Loading branch information
icirellik committed Oct 16, 2020
1 parent f87ce33 commit 07db8a8
Show file tree
Hide file tree
Showing 6 changed files with 2,048 additions and 1,238 deletions.
23 changes: 9 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,7 @@
"@types/styled-system": "5.1.9",
"@types/styled-system__theme-get": "5.0.0",
"@types/underscore.string": "0.0.32",
"@types/webpack": "4.4.24",
"@types/webpack-env": "1.13.6",
"@types/webpack-env": "^1.15.3",
"@typescript-eslint/eslint-plugin": "2.30.0",
"@typescript-eslint/parser": "2.30.0",
"babel-jest": "24.8.0",
Expand All @@ -280,7 +279,6 @@
"babel-plugin-styled-components": "1.11.1",
"benv": "3.3.0",
"cache-loader": "1.2.2",
"case-sensitive-paths-webpack-plugin": "2.3.0",
"coffee-loader": "0.8.0",
"coffeescript": "1.11.1",
"cypress": "5.1.0",
Expand All @@ -294,9 +292,7 @@
"eslint-plugin-react": "7.19.0",
"eslint-plugin-react-hooks": "4.0.4",
"eslint-plugin-styled-components-a11y": "0.0.16",
"fork-ts-checker-notifier-webpack-plugin": "0.4.0",
"fork-ts-checker-webpack-plugin": "0.4.10",
"friendly-errors-webpack-plugin": "1.6.1",
"graphql-tag": "2.10.3",
"graphql-tools": "4.0.3",
"hulk-editor": "craigspaeth/hulk",
Expand Down Expand Up @@ -334,27 +330,26 @@
"relay-test-utils": "9.1.0",
"rewire": "2.2.0",
"should": "11.2.1",
"simple-progress-webpack-plugin": "1.1.2",
"sinon": "1.17.7",
"speed-measure-webpack-plugin": "1.3.3",
"static-extend": "0.1.2",
"strip-ansi": "5.0.0",
"style-loader": "0.23.1",
"stylus-loader": "3.0.2",
"supertest": "2.0.1",
"terser-webpack-plugin": "4.1.0",
"terser-webpack-plugin": "5.0.0",
"typescript": "3.9.7",
"typescript-styled-plugin": "0.15.0",
"vscode-apollo-relay": "1.5.1",
"webpack": "4.44.1",
"webpack-bundle-analyzer": "3.6.0",
"webpack-cli": "3.3.12",
"webpack": "5.1.3",
"webpack-bundle-analyzer": "3.9.0",
"webpack-cli": "4.0.0",
"webpack-config-utils": "2.3.1",
"webpack-dev-middleware": "3.5.1",
"webpack-hot-middleware": "2.24.3",
"webpack-manifest-plugin": "2.0.4",
"webpack-dev-middleware": "3.7.2",
"webpack-hot-middleware": "2.25.0",
"webpack-manifest-plugin": "^2.2.0",
"webpack-merge": "4.2.1",
"webpack-node-externals": "1.7.2",
"webpack-node-externals": "2.5.2",
"webpack-notifier": "1.7.0",
"webpack-retry-chunk-load-plugin": "1.2.0",
"yn": "4.0.0"
Expand Down
18 changes: 5 additions & 13 deletions webpack/envs/clientCommonConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,12 @@ export const clientCommonConfig = {
},
}),
// Remove moment.js localization files
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
new webpack.IgnorePlugin({ resourceRegExp: /^\.\/locale$/ }),
new webpack.IgnorePlugin({ resourceRegExp: /moment$/ }),
// Remove server-only modules from client bundles
...[
// Remove server side of relay network layer.
new webpack.IgnorePlugin(
/^react-relay-network-modern-ssr\/node8\/server/
),
// No matter what, we don't want the graphql-js package in client
// bundles. This /may/ lead to a broken build when e.g. a reaction
// module that's used on the client side imports something from
// graphql-js, but that's better than silently including this.
new webpack.IgnorePlugin(/^graphql(\/.*)?$/),
],
new webpack.NamedModulesPlugin(),
// TODO: Why would these end up in the client bundle?
new webpack.IgnorePlugin({ resourceRegExp: /^react-relay-network-modern-ssr\/node8\/server/ }),
new webpack.IgnorePlugin({ resourceRegExp: /^graphql(\/.*)?$/ }),
new webpack.ProvidePlugin({
$: "jquery",
jQuery: "jquery",
Expand Down
22 changes: 1 addition & 21 deletions webpack/envs/clientDevelopmentConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@ const chalk = require("chalk")
const fs = require("fs")
const path = require("path")
const webpack = require("webpack")
const ForkTsCheckerNotifierWebpackPlugin = require("fork-ts-checker-notifier-webpack-plugin")
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin")
const FriendlyErrorsWebpackPlugin = require("friendly-errors-webpack-plugin")
const WebpackNotifierPlugin = require("webpack-notifier")
const SimpleProgressWebpackPlugin = require("simple-progress-webpack-plugin")
const CaseSensitivePathsPlugin = require("case-sensitive-paths-webpack-plugin")
const { basePath, env } = require("../utils/env")

const cacheDirectory = path.resolve(basePath, ".cache")
Expand All @@ -18,7 +14,7 @@ if (!env.onCi && !fs.existsSync(cacheDirectory)) {
console.log(
chalk.yellow(
"\n[!] No existing `.cache` directory detected, initial " +
"launch will take a while.\n"
"launch will take a while.\n"
)
)
}
Expand Down Expand Up @@ -56,29 +52,13 @@ export const clientDevelopmentConfig = {
],
},
plugins: [
new CaseSensitivePathsPlugin(),
new webpack.HotModuleReplacementPlugin(),
// @ts-ignore
new SimpleProgressWebpackPlugin({
format: "compact",
}),
new ForkTsCheckerWebpackPlugin({
formatter: "codeframe",
formatterOptions: "highlightCode",
checkSyntacticErrors: true,
watch: ["./src"],
}),
new ForkTsCheckerNotifierWebpackPlugin({
excludeWarnings: true,
skipFirstNotification: true,
}),
new FriendlyErrorsWebpackPlugin({
clearConsole: false,
compilationSuccessInfo: {
messages: [`[Force] Listening on http://localhost:${env.port} \n`],
notes: [""],
},
}),
new WebpackNotifierPlugin(),
],
}
6 changes: 2 additions & 4 deletions webpack/envs/clientProductionConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const path = require("path")
const WebpackManifestPlugin = require("webpack-manifest-plugin")
const { HashedModuleIdsPlugin } = require("webpack")
const webpack = require("webpack")
const { getCSSManifest } = require("../utils/getCSSManifest")
const TerserPlugin = require("terser-webpack-plugin")
const { basePath, env } = require("../utils/env")
Expand All @@ -18,7 +18,7 @@ export const clientProductionConfig = {
// @see: https://github.com/artsy/force/blob/master/src/desktop/lib/global_client_setup.tsx#L7
},
plugins: [
new HashedModuleIdsPlugin(),
new webpack.ids.HashedModuleIdsPlugin(),
new WebpackManifestPlugin({
fileName: path.resolve(basePath, "manifest.json"),
basePath: "/assets/",
Expand All @@ -29,9 +29,7 @@ export const clientProductionConfig = {
minimize: !env.webpackDebug,
minimizer: [
new TerserPlugin({
cache: false,
parallel: env.onCi ? env.webpackCiCpuLimit : true, // Only use 4 cpus (default) in CircleCI, by default it will try using 36 and OOM
sourceMap: true, // Must be set to true if using source-maps in production
}),
],
},
Expand Down
6 changes: 2 additions & 4 deletions webpack/envs/serverConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,16 @@ export const serverConfig = {
minimize: env.isProduction && !env.webpackDebug,
minimizer: [
new TerserPlugin({
cache: false,
parallel: env.onCi ? env.webpackCiCpuLimit : true, // Only use 4 cpus (default) in CircleCI, by default it will try using 36 and OOM
sourceMap: true, // Must be set to true if using source-maps in production
}),
],
},
plugins: removeEmpty([
env.enableWebpackAnalyze
? undefined
: new webpack.optimize.LimitChunkCountPlugin({
maxChunks: 1,
}),
maxChunks: 1,
}),
]),
resolve: {
extensions: [".js", ".jsx", ".ts", ".tsx", ".json", ".coffee"],
Expand Down
Loading

0 comments on commit 07db8a8

Please sign in to comment.