build: Move to a webpack module

Cockpit recently changed to an ESM build system [1]. Bump
COCKPIT_REPO_COMMIT to that and follow suit.

This does not work with old node.js 10 any more which is still the
default in RHEL 8. Install the newer version 16 instead.

[1] https://github.com/cockpit-project/cockpit/pull/18366
This commit is contained in:
Martin Pitt 2023-02-17 19:27:02 +01:00 committed by Katerina Koukiou
parent 1f4e0fac24
commit 4990d6a103
4 changed files with 31 additions and 23 deletions

View file

@ -1,15 +1,15 @@
const fs = require("fs");
const path = require("path");
import fs from "fs";
const copy = require("copy-webpack-plugin");
const extract = require("mini-css-extract-plugin");
const TerserJSPlugin = require('terser-webpack-plugin');
const CssMinimizerPlugin = require('css-minimizer-webpack-plugin');
const CompressionPlugin = require("compression-webpack-plugin");
const ESLintPlugin = require('eslint-webpack-plugin');
const CockpitPoPlugin = require("./pkg/lib/cockpit-po-plugin");
const CockpitRsyncPlugin = require("./pkg/lib/cockpit-rsync-plugin");
const StylelintPlugin = require('stylelint-webpack-plugin');
import copy from "copy-webpack-plugin";
import extract from "mini-css-extract-plugin";
import TerserJSPlugin from 'terser-webpack-plugin';
import CssMinimizerPlugin from 'css-minimizer-webpack-plugin';
import CompressionPlugin from "compression-webpack-plugin";
import ESLintPlugin from 'eslint-webpack-plugin';
import StylelintPlugin from 'stylelint-webpack-plugin';
import CockpitPoPlugin from "./pkg/lib/cockpit-po-plugin.js";
import CockpitRsyncPlugin from "./pkg/lib/cockpit-rsync-plugin.js";
/* A standard nodejs and webpack pattern */
const production = process.env.NODE_ENV === 'production';
@ -31,9 +31,9 @@ const copy_files = [
const plugins = [
new copy({ patterns: copy_files }),
new extract({filename: "[name].css"}),
new extract({ filename: "[name].css" }),
new CockpitPoPlugin(),
new CockpitRsyncPlugin({dest: packageJson.name}),
new CockpitRsyncPlugin({ dest: packageJson.name }),
];
if (eslint) {
@ -42,7 +42,7 @@ if (eslint) {
if (stylelint) {
plugins.push(new StylelintPlugin({
context: "src/",
context: "src/",
}));
}
@ -54,14 +54,14 @@ if (production) {
}));
}
module.exports = {
const config = {
mode: production ? 'production' : 'development',
resolve: {
modules: [ "node_modules", path.resolve(__dirname, 'pkg/lib') ],
modules: ["node_modules", 'pkg/lib'],
alias: { 'font-awesome': 'font-awesome-sass/assets/stylesheets' },
},
resolveLoader: {
modules: [ "node_modules", path.resolve(__dirname, 'pkg/lib') ],
modules: ["node_modules", 'pkg/lib'],
},
watchOptions: {
ignored: /node_modules/,
@ -70,7 +70,7 @@ module.exports = {
index: "./src/index.js",
},
// cockpit.js gets included via <script>, everything else should be bundled
externals: { "cockpit": "cockpit" },
externals: { cockpit: "cockpit" },
devtool: "source-map",
stats: "errors-warnings",
// always regenerate dist/, so make rules work
@ -162,5 +162,7 @@ module.exports = {
},
]
},
plugins: plugins
}
plugins
};
export default config;