wallet-core/packages/taler-wallet-webextension/rollup.config.js

157 lines
3.2 KiB
JavaScript
Raw Normal View History

2019-12-02 18:12:59 +01:00
// rollup.config.js
import linaria from '@linaria/rollup';
import alias from '@rollup/plugin-alias';
import commonjs from "@rollup/plugin-commonjs";
import image from '@rollup/plugin-image';
import json from "@rollup/plugin-json";
import nodeResolve from "@rollup/plugin-node-resolve";
2020-08-10 18:49:23 +02:00
import replace from "@rollup/plugin-replace";
2021-07-10 04:15:49 +02:00
import css from 'rollup-plugin-css-only';
import ignore from "rollup-plugin-ignore";
2022-01-04 21:06:17 +01:00
import typescript from '@rollup/plugin-typescript';
import path from 'path';
import fs from 'fs';
function fromDir(startPath, regex) {
if (!fs.existsSync(startPath)) {
return;
}
const files = fs.readdirSync(startPath);
const result = files.flatMap(file => {
const filename = path.join(startPath, file);
const stat = fs.lstatSync(filename);
if (stat.isDirectory()) {
return fromDir(filename, regex);
}
else if (regex.test(filename)) {
return filename
}
}).filter(x => !!x)
return result
}
2021-06-14 19:38:17 +02:00
const makePlugins = () => [
2022-01-04 21:06:17 +01:00
typescript({
outputToFilesystem: false,
}),
2021-07-10 04:15:49 +02:00
2022-01-04 21:06:17 +01:00
alias({
entries: [
{ find: 'react', replacement: 'preact/compat' },
{ find: 'react-dom', replacement: 'preact/compat' }
]
}),
2022-01-04 21:06:17 +01:00
ignore(["module", "os"]),
nodeResolve({
browser: true,
preferBuiltins: true,
}),
2022-01-04 21:06:17 +01:00
//terser(),
2021-06-14 19:38:17 +02:00
2022-01-04 21:06:17 +01:00
replace({
"process.env.NODE_ENV": JSON.stringify("production"),
// "__filename": "'__webextension__'",
preventAssignment: true
}),
commonjs({
include: [/node_modules/, /dist/],
extensions: [".js"],
ignoreGlobal: true,
sourceMap: true,
}),
json(),
image(),
linaria({
sourceMap: process.env.NODE_ENV !== 'production',
}),
2021-07-10 04:15:49 +02:00
2021-06-14 19:38:17 +02:00
];
2021-06-16 22:01:06 +02:00
const webExtensionWalletEntryPoint = {
2022-01-04 21:06:17 +01:00
input: "src/walletEntryPoint.tsx",
2021-06-14 19:38:17 +02:00
output: {
2021-06-16 22:01:06 +02:00
file: "dist/walletEntryPoint.js",
2021-06-14 19:38:17 +02:00
format: "iife",
exports: "none",
2021-06-16 22:01:06 +02:00
name: "webExtensionWalletEntry",
},
2021-08-23 21:51:49 +02:00
plugins: [
...makePlugins(),
css({
output: 'walletEntryPoint.css',
2022-01-04 21:06:17 +01:00
}),
],
2021-06-16 22:01:06 +02:00
};
const webExtensionPopupEntryPoint = {
2022-01-04 21:06:17 +01:00
input: "src/popupEntryPoint.tsx",
2021-06-16 22:01:06 +02:00
output: {
file: "dist/popupEntryPoint.js",
format: "iife",
exports: "none",
name: "webExtensionPopupEntry",
2021-06-14 19:38:17 +02:00
},
2021-08-23 21:51:49 +02:00
plugins: [
...makePlugins(),
css({
output: 'popupEntryPoint.css',
2022-01-04 21:06:17 +01:00
}),
],
2019-12-02 18:12:59 +01:00
};
const webExtensionBackgroundPageScript = {
2022-01-04 21:06:17 +01:00
input: "src/background.ts",
2019-12-05 19:38:19 +01:00
output: {
2020-08-10 18:49:23 +02:00
file: "dist/background.js",
format: "iife",
exports: "none",
name: "webExtensionBackgroundScript",
2019-12-05 19:38:19 +01:00
},
2021-06-14 19:38:17 +02:00
plugins: makePlugins(),
};
const webExtensionCryptoWorker = {
2022-01-04 21:06:17 +01:00
input: "src/browserWorkerEntry.ts",
output: {
2020-08-10 18:49:23 +02:00
file: "dist/browserWorkerEntry.js",
format: "iife",
exports: "none",
name: "webExtensionCryptoWorker",
},
2021-06-14 19:38:17 +02:00
plugins: makePlugins(),
};
2022-01-04 21:06:17 +01:00
const tests = fromDir('./src', /.test.ts$/).map(test => ({
input: test,
output: {
file: test.replace(/^src/, 'dist').replace(/\.ts$/, '.js'),
format: "iife",
exports: "none",
name: test,
},
plugins: [
...makePlugins(),
css({
output: 'walletEntryPoint.css',
}),
],
}))
export default [
2021-06-16 22:01:06 +02:00
webExtensionPopupEntryPoint,
webExtensionWalletEntryPoint,
webExtensionBackgroundPageScript,
webExtensionCryptoWorker,
2022-01-04 21:06:17 +01:00
...tests,
];