2021-11-04 08:33:11 +01:00
|
|
|
/*
|
2024-09-24 09:42:07 +02:00
|
|
|
* Copyright (c) 2020 - present Cloudogu GmbH
|
2021-11-04 08:33:11 +01:00
|
|
|
*
|
2024-09-24 09:42:07 +02:00
|
|
|
* This program is free software: you can redistribute it and/or modify it under
|
|
|
|
|
* the terms of the GNU Affero General Public License as published by the Free
|
|
|
|
|
* Software Foundation, version 3.
|
2021-11-04 08:33:11 +01:00
|
|
|
*
|
2024-09-24 09:42:07 +02:00
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
|
|
|
|
|
* details.
|
2021-11-04 08:33:11 +01:00
|
|
|
*
|
2024-09-24 09:42:07 +02:00
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
|
* along with this program. If not, see https://www.gnu.org/licenses/.
|
2021-11-04 08:33:11 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
const path = require("path");
|
|
|
|
|
const fs = require("fs");
|
|
|
|
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
|
|
|
const RemoveThemesPlugin = require("./RemoveThemesPlugin");
|
2022-01-21 14:25:19 +01:00
|
|
|
const ReactDOM = require("react-dom");
|
2021-11-04 08:33:11 +01:00
|
|
|
|
|
|
|
|
const root = path.resolve("..");
|
|
|
|
|
|
|
|
|
|
const themedir = path.join(root, "ui-styles", "src");
|
|
|
|
|
|
2022-04-25 16:34:40 +02:00
|
|
|
ReactDOM.createPortal = (node) => node;
|
2022-01-21 14:25:19 +01:00
|
|
|
|
2021-11-04 08:33:11 +01:00
|
|
|
const themes = fs
|
|
|
|
|
.readdirSync(themedir)
|
2022-04-25 16:34:40 +02:00
|
|
|
.map((filename) => path.parse(filename))
|
|
|
|
|
.filter((p) => p.ext === ".scss")
|
2021-11-10 10:10:17 +01:00
|
|
|
.reduce((entries, current) => ({ ...entries, [`ui-theme-${current.name}`]: path.join(themedir, current.base) }), {});
|
|
|
|
|
// .map(f => path.join(themedir, f.base));
|
2021-11-04 08:33:11 +01:00
|
|
|
|
|
|
|
|
module.exports = {
|
2021-11-10 10:10:17 +01:00
|
|
|
core: {
|
2022-04-25 16:34:40 +02:00
|
|
|
builder: "webpack5",
|
2021-11-10 10:10:17 +01:00
|
|
|
},
|
|
|
|
|
typescript: { reactDocgen: false },
|
2021-11-04 08:33:11 +01:00
|
|
|
stories: ["../src/**/*.stories.tsx"],
|
2022-04-25 16:34:40 +02:00
|
|
|
framework: "@storybook/react",
|
|
|
|
|
addons: ["storybook-addon-i18next", "storybook-addon-themes", "@storybook/addon-links", "@storybook/addon-essentials", "@storybook/addon-interactions"],
|
|
|
|
|
webpackFinal: async (config) => {
|
2021-11-04 08:33:11 +01:00
|
|
|
// add our themes to webpack entry points
|
|
|
|
|
config.entry = {
|
|
|
|
|
main: config.entry,
|
2022-04-25 16:34:40 +02:00
|
|
|
...themes,
|
2021-11-04 08:33:11 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// create separate css files for our themes
|
|
|
|
|
config.plugins.push(
|
|
|
|
|
new MiniCssExtractPlugin({
|
2021-11-10 10:10:17 +01:00
|
|
|
filename: "[name].css",
|
2022-04-25 16:34:40 +02:00
|
|
|
ignoreOrder: false,
|
2021-11-10 10:10:17 +01:00
|
|
|
})
|
2021-11-04 08:33:11 +01:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
config.module.rules.push({
|
|
|
|
|
test: /\.scss$/,
|
2022-04-25 16:34:40 +02:00
|
|
|
use: [MiniCssExtractPlugin.loader, "css-loader", "sass-loader"],
|
2021-11-04 08:33:11 +01:00
|
|
|
});
|
|
|
|
|
|
2021-11-10 10:10:17 +01:00
|
|
|
// the html-webpack-plugin adds the generated css and js files to the iframe,
|
2021-11-04 08:33:11 +01:00
|
|
|
// which overrides our manually loaded css files.
|
|
|
|
|
// So we use a custom plugin which uses a hook of html-webpack-plugin
|
|
|
|
|
// to filter our themes from the output.
|
|
|
|
|
config.plugins.push(new RemoveThemesPlugin());
|
|
|
|
|
|
2022-04-25 16:34:40 +02:00
|
|
|
// force node version of "decode-named-character-reference" instead of browser version which does not work in web worker
|
|
|
|
|
config.resolve.alias["decode-named-character-reference"] = require.resolve("decode-named-character-reference");
|
|
|
|
|
|
2022-06-22 11:49:26 +02:00
|
|
|
// force cjs instead of esm
|
|
|
|
|
// https://github.com/tannerlinsley/react-query/issues/3513
|
|
|
|
|
config.resolve.alias["react-query/devtools"] = require.resolve("react-query/devtools");
|
|
|
|
|
|
2021-11-04 08:33:11 +01:00
|
|
|
return config;
|
2022-04-25 16:34:40 +02:00
|
|
|
},
|
2021-11-04 08:33:11 +01:00
|
|
|
};
|