2021-06-24 00:29:53 +02:00
|
|
|
/**
|
|
|
|
* EGroupware - Rollup config file
|
|
|
|
*
|
|
|
|
* @link https://www.egroupware.org
|
|
|
|
* @copyright (c) 2021 by Nathan Gray
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
*
|
|
|
|
* @see http://rollupjs.org/guide/en
|
|
|
|
* @type {import('rollup').RollupOptions}
|
|
|
|
*/
|
|
|
|
|
2021-06-25 22:49:24 +02:00
|
|
|
import path from 'path';
|
|
|
|
import babel from '@babel/core';
|
2021-07-13 08:30:51 +02:00
|
|
|
import { readFileSync, readdirSync, statSync } from "fs";
|
2021-06-25 22:49:24 +02:00
|
|
|
import rimraf from 'rimraf';
|
|
|
|
import { minify } from 'terser';
|
2021-07-06 09:53:18 +02:00
|
|
|
import resolve from '@rollup/plugin-node-resolve';
|
2021-06-24 00:29:53 +02:00
|
|
|
|
2021-06-25 22:49:24 +02:00
|
|
|
// Best practice: use this
|
|
|
|
//rimraf.sync('./dist/');
|
|
|
|
rimraf.sync('./chunks/');
|
|
|
|
|
|
|
|
// Turn on minification
|
2021-07-07 10:32:06 +02:00
|
|
|
const do_minify = true;
|
2021-06-25 22:49:24 +02:00
|
|
|
|
2021-07-02 15:24:12 +02:00
|
|
|
const config = {
|
2021-06-25 22:49:24 +02:00
|
|
|
treeshake: false,
|
|
|
|
input: {
|
|
|
|
// Output : Input
|
|
|
|
// Note the .ts extension on the input - we build directly from the TypeScript when available
|
|
|
|
"pixelegg/js/fw_pixelegg.min": "pixelegg/js/fw_pixelegg.js",
|
2021-06-29 15:21:19 +02:00
|
|
|
"pixelegg/js/fw_mobile.min": "pixelegg/js/fw_mobile.js",
|
2021-06-25 22:49:24 +02:00
|
|
|
"api/js/jsapi/egw.min": "api/js/jsapi/egw_modules.js",
|
|
|
|
|
2021-07-02 15:24:12 +02:00
|
|
|
// app.ts/js are added automatic by addAppsConfig() below
|
2021-06-25 22:49:24 +02:00
|
|
|
},
|
|
|
|
external: function(id,parentId,isResolved) {
|
|
|
|
if(!isResolved)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(id.includes("/vendor/"))
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
},
|
2021-06-24 00:29:53 +02:00
|
|
|
output: {
|
2021-06-25 22:49:24 +02:00
|
|
|
// TODO: Hashed entries, when server supports
|
|
|
|
//entryFileNames: '[name]-[hash].js',
|
|
|
|
entryFileNames: '[name].js',
|
|
|
|
chunkFileNames: 'chunks/[name]-[hash].js',
|
|
|
|
// Best practice: use this:
|
|
|
|
//dir: './dist',
|
|
|
|
dir: '.',
|
|
|
|
sourcemap: true
|
|
|
|
},
|
|
|
|
plugins: [{
|
|
|
|
resolveId (id, parentId) {
|
2021-07-09 21:07:23 +02:00
|
|
|
if (!parentId || parentId.indexOf(path.sep + 'node_modules' + path.sep) !== -1)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(id.endsWith(".js"))
|
2021-06-25 22:49:24 +02:00
|
|
|
{
|
|
|
|
const tsPath =path.resolve(path.dirname(parentId), id.slice(0,-3) + '.ts');
|
|
|
|
try {
|
|
|
|
readFileSync(tsPath);
|
|
|
|
console.warn(id + " is a TS file loaded with wrong extension. Remove the extension on the import in " + parentId);
|
|
|
|
}
|
|
|
|
catch (e) {}
|
|
|
|
}
|
2021-07-09 21:07:23 +02:00
|
|
|
else if (!id.endsWith('.ts')) {
|
2021-06-25 22:49:24 +02:00
|
|
|
|
|
|
|
const tsPath =path.resolve(path.dirname(parentId), id + '.ts');
|
|
|
|
const jsPath =path.resolve(path.dirname(parentId), id + '.js');
|
|
|
|
try {
|
|
|
|
readFileSync(tsPath);
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
return jsPath;
|
|
|
|
}
|
|
|
|
return tsPath;
|
|
|
|
}
|
|
|
|
}
|
2021-07-06 09:53:18 +02:00
|
|
|
},
|
|
|
|
// resolve (external) node modules from node_modules directory
|
2021-07-09 21:07:23 +02:00
|
|
|
resolve(),
|
2021-07-06 09:53:18 +02:00
|
|
|
{
|
2021-06-25 22:49:24 +02:00
|
|
|
transform (code, id) {
|
|
|
|
if (id.endsWith('.ts'))
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
return babel.transform(code, {
|
|
|
|
filename: id,
|
|
|
|
sourceMaps: true,
|
|
|
|
ast: false,
|
|
|
|
compact: false,
|
|
|
|
sourceType: 'module',
|
|
|
|
parserOpts: {
|
|
|
|
// plugins: stage3Syntax,
|
|
|
|
errorRecovery: true
|
|
|
|
},
|
2021-07-14 19:59:44 +02:00
|
|
|
presets: ['@babel/preset-typescript'],
|
|
|
|
plugins: [
|
2021-07-15 00:11:20 +02:00
|
|
|
// These two allow us to use LitElement decorators, but cause problems witn some TypeScript properties
|
|
|
|
//['@babel/plugin-proposal-decorators', {decoratorsBeforeExport: true}],
|
|
|
|
//'@babel/plugin-proposal-class-properties',
|
2021-07-14 19:59:44 +02:00
|
|
|
]
|
2021-06-25 22:49:24 +02:00
|
|
|
}, function (err, result) {
|
|
|
|
if (err)
|
|
|
|
return reject(err);
|
|
|
|
resolve(result);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
transform (code,id) {
|
|
|
|
if(!do_minify || id.includes(".min"))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
return minify(code, {
|
|
|
|
mangle: false,
|
2021-07-05 16:24:22 +02:00
|
|
|
sourceMap: true,
|
2021-06-25 22:49:24 +02:00
|
|
|
output: {
|
|
|
|
preamble: `/*!
|
2021-07-02 15:24:12 +02:00
|
|
|
* EGroupware (https://www.egroupware.org/) minified Javascript
|
2021-06-25 22:49:24 +02:00
|
|
|
*
|
|
|
|
* full sources are available under https://github.com/EGroupware/egroupware/
|
|
|
|
*
|
|
|
|
* build ${Date.now()}
|
|
|
|
*/
|
|
|
|
`
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}],
|
|
|
|
|
2021-07-02 15:24:12 +02:00
|
|
|
// Custom warning handler to give more information about circular dependencies
|
2021-06-25 22:49:24 +02:00
|
|
|
onwarn: function(warning,warn) {
|
2021-07-04 09:54:44 +02:00
|
|
|
console.warn(warning.toString());
|
2021-06-24 00:29:53 +02:00
|
|
|
}
|
2021-07-02 15:24:12 +02:00
|
|
|
};
|
2021-06-25 22:49:24 +02:00
|
|
|
|
2021-07-02 15:24:12 +02:00
|
|
|
/**
|
|
|
|
* Add existing app.ts/js endpoints to config.input and return it
|
|
|
|
*
|
|
|
|
* @return Promise<object>
|
|
|
|
*/
|
2021-07-13 08:30:51 +02:00
|
|
|
export default function addAppsConfig()
|
2021-07-02 15:24:12 +02:00
|
|
|
{
|
|
|
|
const conf = config;
|
2021-07-13 08:30:51 +02:00
|
|
|
const files = readdirSync('.', { withFileTypes: true});
|
2021-07-02 15:24:12 +02:00
|
|
|
for (const file of files)
|
|
|
|
{
|
|
|
|
if (file.isDirectory())
|
|
|
|
{
|
|
|
|
try {
|
2021-07-13 08:30:51 +02:00
|
|
|
statSync(file.name + '/js/app.ts');
|
2021-07-02 15:24:12 +02:00
|
|
|
config.input[file.name + '/js/app'] = file.name + '/js/app.ts';
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
try {
|
2021-07-13 08:30:51 +02:00
|
|
|
statSync(file.name + '/js/app.js');
|
2021-07-02 15:24:12 +02:00
|
|
|
config.input[file.name + '/js/app.min'] = file.name + '/js/app.js';
|
|
|
|
}
|
|
|
|
catch (e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return conf;
|
|
|
|
}
|