2019-12-02 18:12:59 +01:00
|
|
|
// rollup.config.js
|
2021-08-19 05:34:47 +02:00
|
|
|
import linaria from '@linaria/rollup';
|
|
|
|
import alias from '@rollup/plugin-alias';
|
2020-07-17 14:30:34 +02:00
|
|
|
import commonjs from "@rollup/plugin-commonjs";
|
2021-08-19 05:34:47 +02:00
|
|
|
import image from '@rollup/plugin-image';
|
2020-04-06 17:35:51 +02:00
|
|
|
import json from "@rollup/plugin-json";
|
2021-08-19 05:34:47 +02:00
|
|
|
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';
|
2021-08-19 05:34:47 +02:00
|
|
|
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
|
|
|
|
}
|
2020-07-17 14:30:34 +02:00
|
|
|
|
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' }
|
|
|
|
]
|
|
|
|
}),
|
2020-04-06 17:35:51 +02:00
|
|
|
|
2022-01-04 21:06:17 +01:00
|
|
|
ignore(["module", "os"]),
|
|
|
|
nodeResolve({
|
|
|
|
browser: true,
|
|
|
|
preferBuiltins: true,
|
|
|
|
}),
|
2020-04-06 17:35:51 +02:00
|
|
|
|
2022-01-04 21:06:17 +01:00
|
|
|
//terser(),
|
2020-04-06 17:35:51 +02:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2020-04-06 17:35:51 +02: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",
|
2020-04-06 17:35:51 +02:00
|
|
|
format: "iife",
|
2020-07-17 14:30:34 +02:00
|
|
|
exports: "none",
|
2020-04-06 17:35:51 +02:00
|
|
|
name: "webExtensionBackgroundScript",
|
2019-12-05 19:38:19 +01:00
|
|
|
},
|
2021-06-14 19:38:17 +02:00
|
|
|
plugins: makePlugins(),
|
2020-04-06 17:35:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const webExtensionCryptoWorker = {
|
2022-01-04 21:06:17 +01:00
|
|
|
input: "src/browserWorkerEntry.ts",
|
2020-04-06 17:35:51 +02:00
|
|
|
output: {
|
2020-08-10 18:49:23 +02:00
|
|
|
file: "dist/browserWorkerEntry.js",
|
2020-04-06 17:35:51 +02:00
|
|
|
format: "iife",
|
2020-07-17 14:30:34 +02:00
|
|
|
exports: "none",
|
2020-04-06 17:35:51 +02:00
|
|
|
name: "webExtensionCryptoWorker",
|
|
|
|
},
|
2021-06-14 19:38:17 +02:00
|
|
|
plugins: makePlugins(),
|
2020-04-06 17:35:51 +02:00
|
|
|
};
|
|
|
|
|
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',
|
|
|
|
}),
|
|
|
|
],
|
|
|
|
}))
|
|
|
|
|
2020-04-06 17:35:51 +02:00
|
|
|
export default [
|
2021-06-16 22:01:06 +02:00
|
|
|
webExtensionPopupEntryPoint,
|
|
|
|
webExtensionWalletEntryPoint,
|
2020-04-06 17:35:51 +02:00
|
|
|
webExtensionBackgroundPageScript,
|
|
|
|
webExtensionCryptoWorker,
|
2022-01-04 21:06:17 +01:00
|
|
|
...tests,
|
2020-04-06 17:35:51 +02:00
|
|
|
];
|