Skip to content

Commit

Permalink
Drop webpack in favor of esbuild
Browse files Browse the repository at this point in the history
TODO:
[ ] cockpit-po-plugin
[ ] fail on warnings eslint (Open eslint issue eslint/eslint#16804)
  • Loading branch information
KKoukiou committed Feb 8, 2023
1 parent 104fa0b commit a21a0f7
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 203 deletions.
9 changes: 2 additions & 7 deletions .eslintrc.json
Expand Up @@ -2,16 +2,11 @@
"root": true,
"env": {
"browser": true,
"es6": true
"es2022": true
},
"extends": ["eslint:recommended", "standard", "standard-jsx", "standard-react", "plugin:jsx-a11y/recommended"],
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaVersion": "7",
"ecmaFeatures": {
"jsx": true
},
"sourceType": "module"
"ecmaVersion": 2022
},
"plugins": ["flowtype", "react", "react-hooks", "jsx-a11y"],
"rules": {
Expand Down
9 changes: 5 additions & 4 deletions Makefile
Expand Up @@ -91,11 +91,12 @@ packaging/arch/PKGBUILD: packaging/arch/PKGBUILD.in
packaging/debian/changelog: packaging/debian/changelog.in
sed 's/VERSION/$(VERSION)/' $< > $@

$(WEBPACK_TEST): $(COCKPIT_REPO_STAMP) $(shell find src/ -type f) package.json webpack.config.js
$(MAKE) package-lock.json && NODE_ENV=$(NODE_ENV) node_modules/.bin/webpack
# In development mode terser does not run and so no LICENSE.txt.gz is generated, so we explictly create it as it is required for building rpm's
$(WEBPACK_TEST): $(COCKPIT_REPO_STAMP) $(shell find src/ -type f) package.json build.js
$(MAKE) package-lock.json && NODE_ENV=$(NODE_ENV) npm run build
# In development mode minification does not run and so no LEGAL.txt is generated, so we explictly create it as it is required for building rpm's
if [ "$$NODE_ENV" = "development" ]; then \
gzip </dev/null >dist/index.js.LICENSE.txt.gz; \
touch dist/index.js.LEGAL.txt; \
touch dist/index.css.LEGAL.txt; \
fi

watch:
Expand Down
48 changes: 48 additions & 0 deletions build.js
@@ -0,0 +1,48 @@
const esbuild = require("esbuild");
const path = require("path");
const eslint = require('esbuild-plugin-linter');
const {sassPlugin } = require('esbuild-sass-plugin')
const { nodeExternalsPlugin } = require('esbuild-node-externals');
const replacePlugin = require('esbuild-plugin-replace-regex');

const production = process.env.NODE_ENV === 'production';
/* development options for faster iteration */
const useEslint = process.env.ESLINT !== '0';
const watchMode = process.env.ESBUILD_WATCH === "true" || false;
if(watchMode) {
console.log("Running in watch mode");
}

nodePaths=["node_modules", path.resolve(__dirname, 'pkg/lib')]

esbuild.build({
// Cockpit's http server is not able to load multiple JS files
bundle: true,
entryPoints: ["./src/index.js"],
// Allow external font files which live in ../../static/fonts
external: ['*.woff', '*.woff2'],
// Move all legal comments to a .LEGAL.txt file
legalComments: 'external',
loader: { ".js": "jsx" },
minify: production,
// List of directories to use when resolving import statements
nodePaths,
outdir: "./dist",
... !production ? { sourcemap: "external" } : {},
target: ['es2020'],
watch: watchMode,
plugins: [
sassPlugin({
loadPaths: nodePaths, quietDeps: true
}),
... useEslint ? [eslint({ filter: /src\/*/ })] : [],
nodeExternalsPlugin(),
replacePlugin({
filter: /patternfly-4-cockpit.scss$/,
patterns: [
[/@font-face[^}]*patternfly-fonts-fake-path[^}]*}/g, ''],
[/src:url\("patternfly-icons-fake-path\/pficon[^}]*/g, 'src:url("../base1/fonts/patternfly.woff") format("woff");'],
]
}),
]
}).catch(() => process.exit(1));
2 changes: 1 addition & 1 deletion node_modules
Submodule node_modules updated 6365 files
46 changes: 18 additions & 28 deletions package.json
Expand Up @@ -6,38 +6,26 @@
"author": "",
"license": "LGPL-2.1",
"scripts": {
"watch": "webpack --watch --progress",
"build": "webpack",
"watch": "ESBUILD_WATCH='true' node build.js",
"build": "node build.js",
"eslint": "eslint --ext .jsx --ext .js src/",
"eslint:fix": "eslint --fix --ext .jsx --ext .js src/",
"stylelint": "stylelint src/*{.css,scss}",
"stylelint:fix": "stylelint --fix src/*{.css,scss}"
},
"devDependencies": {
"@babel/core": "^7.6.0",
"@babel/eslint-parser": "^7.13.14",
"@babel/preset-env": "7.12.17",
"@babel/preset-react": "^7.0.0",
"argparse": "^2.0.1",
"babel-loader": "^8.0.0",
"chrome-remote-interface": "^0.31.2",
"compression-webpack-plugin": "^6.0.0",
"copy-webpack-plugin": "^6.1.0",
"css-loader": "^5.2.0",
"css-minimizer-webpack-plugin": "4.0.0",
"eslint": "^7.10.0",
"eslint-config-standard": "^16.0.0",
"eslint-config-standard-jsx": "^10.0.0",
"eslint-config-standard-react": "^11.0.1",
"eslint-plugin-flowtype": "^5.2.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^5.1.0",
"eslint-plugin-react": "^7.23.0",
"eslint-plugin-react-hooks": "^4.1.2",
"eslint-plugin-standard": "^4.0.1",
"eslint-webpack-plugin": "^2.5.3",
"eslint": "^8.29.0",
"eslint-config-standard": "^17.0.0",
"eslint-config-standard-jsx": "^11.0.0",
"eslint-config-standard-react": "^13.0.0",
"eslint-plugin-flowtype": "^8.0.3",
"eslint-plugin-jsx-a11y": "^6.7.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-standard": "^5.0.0",
"gettext-parser": "^2.0.0",
"htmlparser": "^1.7.7",
"jed": "^1.1.1",
Expand All @@ -47,11 +35,7 @@
"sizzle": "^2.3.3",
"string-replace-loader": "^3.0.0",
"stylelint": "^14.9.1",
"stylelint-config-standard-scss": "^5.0.0",
"stylelint-webpack-plugin": "^3.3.0",
"terser-webpack-plugin": "^5.1.3",
"webpack": "^5.31.0",
"webpack-cli": "^4.6.0"
"stylelint-config-standard-scss": "^5.0.0"
},
"dependencies": {
"@patternfly/patternfly": "4.224.2",
Expand All @@ -60,6 +44,12 @@
"@patternfly/react-table": "4.112.39",
"date-fns": "2.28.0",
"docker-names": "1.2.1",
"esbuild": "0.16.14",
"esbuild-node-externals": "1.6.0",
"esbuild-plugin-linter": "0.0.2",
"esbuild-plugin-replace": "1.3.0",
"esbuild-plugin-replace-regex": "0.0.2",
"esbuild-sass-plugin": "2.4.5",
"prop-types": "15.8.1",
"react": "18.2.0",
"react-dom": "18.2.0",
Expand Down
2 changes: 1 addition & 1 deletion packaging/cockpit-podman.spec.in
Expand Up @@ -53,7 +53,7 @@ appstream-util validate-relax --nonet %{buildroot}/%{_datadir}/metainfo/*

%files
%doc README.md
%license LICENSE dist/index.js.LICENSE.txt.gz
%license LICENSE dist/index.js.LEGAL.txt dist/index.css.LEGAL.txt
%{_datadir}/cockpit/*
%{_datadir}/metainfo/*

Expand Down
162 changes: 0 additions & 162 deletions webpack.config.js

This file was deleted.

0 comments on commit a21a0f7

Please sign in to comment.