forked from cockpit-project/cockpit-podman
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
maint: Drop webpack in favor of esbuild
For eslint integration there are two existing plugins [1], [2] but none can be used because of unsatisfied peer dependency version of esbuild. Let's just use our own eslint plugin for now. [1] to-codando/esbuild-plugin-linter#1 [2] robinloeffel/esbuild-plugin-eslint#5 TODO: [ ] cockpit-po-plugin [ ] cockpit-rsync-plugin [ ] stylelint intergration [ ] fail on warnings eslint [0] [0] eslint/eslint#16804
- Loading branch information
Showing
8 changed files
with
118 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import copy from 'esbuild-plugin-copy'; | ||
import fs from "fs"; | ||
import esbuild from "esbuild"; | ||
import path from "path"; | ||
import { sassPlugin } from 'esbuild-sass-plugin'; | ||
import { eslintPlugin } from './esbuild-eslint-plugin.js'; | ||
|
||
const useEslint = process.env.ESLINT !== '0'; | ||
const production = process.env.NODE_ENV === 'production'; | ||
|
||
const nodePaths=['pkg/lib'] | ||
|
||
const context = await esbuild.context({ | ||
// 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', '*.jpg', '*.svg', '../../assets*'], | ||
// 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'], | ||
logLevel: "debug", | ||
plugins: [ | ||
... useEslint ? [eslintPlugin] : [], | ||
// Esbuild will only copy assets that are explicitly imported and used | ||
// in the code. This is a problem for index.html and manifest.json which are not imported | ||
copy({ | ||
assets: [ | ||
{ from: ['./src/manifest.json'], to: [ './manifest.json' ] }, | ||
{ from: ['./src/index.html'], to: ['./index.html'] }, | ||
] | ||
}), | ||
sassPlugin({ | ||
loadPaths: [...nodePaths, 'node_modules'], quietDeps: true, | ||
async transform(source, resolveDir, path) { | ||
if (path.includes('patternfly-4-cockpit.scss')) { | ||
return source | ||
.replace(/url.*patternfly-icons-fake-path.*;/g, 'url("../base1/fonts/patternfly.woff") format("woff");') | ||
.replace(/@font-face[^}]*patternfly-fonts-fake-path[^}]*}/g, ''); | ||
} | ||
return source; | ||
} | ||
}), | ||
] | ||
}) | ||
|
||
// Manually do an incremental build | ||
const result = await context.rebuild() | ||
|
||
/* development options for faster iteration */ | ||
const watchMode = process.env.ESBUILD_WATCH === "true" || false; | ||
if(watchMode) { | ||
console.log("Running in watch mode"); | ||
// Enable watch mode | ||
await context.watch() | ||
} | ||
else { | ||
context.dispose(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// FIXME: replace with plugin from npmjs if possible | ||
// Candidate [1] https://github.com/to-codando/esbuild-plugin-linter/issues/1 | ||
// Candidate [2] https://github.com/robinloeffel/esbuild-plugin-eslint/issues/5 | ||
|
||
import { ESLint } from 'eslint'; | ||
|
||
export const eslintPlugin = { | ||
name: 'eslintPlugin', | ||
setup(build) { | ||
const filesToLint = []; | ||
const eslint = new ESLint(); | ||
const filter = /src\/.*\.(jsx?|js?)$/; | ||
|
||
build.onLoad({ filter }, ({ path }) => { | ||
filesToLint.push(path); | ||
}); | ||
|
||
build.onEnd(async () => { | ||
const result = await eslint.lintFiles(filesToLint); | ||
const formatter = await eslint.loadFormatter('stylish'); | ||
const output = formatter.format(result); | ||
if (output.length > 0) { | ||
// eslint-disable-next-line no-console | ||
console.log(output); | ||
} | ||
}); | ||
}, | ||
} |
Submodule node_modules
updated
8168 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.