Refactor rollup configuration
This commit is contained in:
parent
7332096828
commit
9e322c4cfb
|
@ -1,53 +1,6 @@
|
||||||
import resolve from '@rollup/plugin-node-resolve';
|
import { SyndicateRollup } from '../../rollup.js';
|
||||||
import { terser } from 'rollup-plugin-terser';
|
const r = new SyndicateRollup('syndicate-compiler', { globalName: 'SyndicateCompiler' });
|
||||||
|
|
||||||
function distfile(insertion) {
|
|
||||||
const f = `syndicate-compiler${insertion}.js`;
|
|
||||||
return `dist/${f}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function umd(insertion, extra) {
|
|
||||||
return {
|
|
||||||
file: distfile(insertion),
|
|
||||||
format: 'umd',
|
|
||||||
name: 'SyndicateCompiler',
|
|
||||||
sourcemap: true,
|
|
||||||
... (extra || {})
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function es6(insertion, extra) {
|
|
||||||
return {
|
|
||||||
file: distfile('.es6' + insertion),
|
|
||||||
format: 'es',
|
|
||||||
sourcemap: true,
|
|
||||||
... (extra || {})
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default [
|
export default [
|
||||||
{
|
r.config('lib/index.js', r.umd),
|
||||||
input: 'lib/index.js',
|
r.config('lib/index.js', r.es6),
|
||||||
plugins: [
|
|
||||||
resolve({
|
|
||||||
preferBuiltins: false,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
output: [
|
|
||||||
umd(''),
|
|
||||||
umd('.min', { plugins: [terser()] }),
|
|
||||||
],
|
|
||||||
}, {
|
|
||||||
input: 'lib/index.js',
|
|
||||||
plugins: [
|
|
||||||
resolve({
|
|
||||||
// moduleDirectories: ['stubs', 'node_modules'],
|
|
||||||
preferBuiltins: false,
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
output: [
|
|
||||||
es6(''),
|
|
||||||
es6('.min', { plugins: [terser()] }),
|
|
||||||
],
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,56 +1,16 @@
|
||||||
import resolve from '@rollup/plugin-node-resolve';
|
import { SyndicateRollup } from '../../rollup.js';
|
||||||
import { terser } from 'rollup-plugin-terser';
|
const r = new SyndicateRollup('syndicate', { globalName: 'Syndicate' });
|
||||||
|
export default [
|
||||||
function distfile(insertion) {
|
r.config('lib/index.js', r.umd, {
|
||||||
const f = `syndicate${insertion}.js`;
|
output: {
|
||||||
return `dist/${f}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function umd(insertion, extra) {
|
|
||||||
return {
|
|
||||||
file: distfile(insertion),
|
|
||||||
format: 'umd',
|
|
||||||
name: 'Syndicate',
|
|
||||||
sourcemap: true,
|
|
||||||
globals: {
|
globals: {
|
||||||
'crypto': 'crypto',
|
'crypto': 'crypto',
|
||||||
},
|
},
|
||||||
... (extra || {})
|
},
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function es6(insertion, extra) {
|
|
||||||
return {
|
|
||||||
file: distfile('.es6' + insertion),
|
|
||||||
format: 'es',
|
|
||||||
sourcemap: true,
|
|
||||||
... (extra || {})
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
export default [
|
|
||||||
{
|
|
||||||
input: 'lib/index.js',
|
|
||||||
plugins: [
|
|
||||||
resolve({
|
|
||||||
preferBuiltins: false,
|
|
||||||
}),
|
}),
|
||||||
],
|
r.config('lib/index.js', r.es6, {
|
||||||
output: [
|
resolve: {
|
||||||
umd(''),
|
|
||||||
umd('.min', { plugins: [terser()] }),
|
|
||||||
],
|
|
||||||
}, {
|
|
||||||
input: 'lib/index.js',
|
|
||||||
plugins: [
|
|
||||||
resolve({
|
|
||||||
moduleDirectories: ['stubs', 'node_modules'],
|
moduleDirectories: ['stubs', 'node_modules'],
|
||||||
preferBuiltins: false,
|
},
|
||||||
}),
|
}),
|
||||||
],
|
|
||||||
output: [
|
|
||||||
es6(''),
|
|
||||||
es6('.min', { plugins: [terser()] }),
|
|
||||||
],
|
|
||||||
}
|
|
||||||
];
|
];
|
||||||
|
|
|
@ -0,0 +1,67 @@
|
||||||
|
import resolve from '@rollup/plugin-node-resolve';
|
||||||
|
import { terser } from 'rollup-plugin-terser';
|
||||||
|
|
||||||
|
export class SyndicateRollup {
|
||||||
|
constructor(packageName, options = {}) {
|
||||||
|
this.packageName = packageName;
|
||||||
|
this.globalName = options.globalName;
|
||||||
|
this.configs = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
distfile(insertion) {
|
||||||
|
const f = `${this.packageName}${insertion}.js`;
|
||||||
|
return `dist/${f}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
terser() {
|
||||||
|
return terser();
|
||||||
|
}
|
||||||
|
|
||||||
|
get umd() {
|
||||||
|
return (insertion, extra) => ({
|
||||||
|
file: this.distfile(insertion),
|
||||||
|
format: 'umd',
|
||||||
|
sourcemap: true,
|
||||||
|
... (this.globalName !== void 0) && { name: this.globalName },
|
||||||
|
... (extra || {})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
get es6() {
|
||||||
|
return (insertion, extra) => ({
|
||||||
|
file: this.distfile('.es6' + insertion),
|
||||||
|
format: 'es',
|
||||||
|
sourcemap: true,
|
||||||
|
... (extra || {})
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
config(inputFile, outputMaker, options) {
|
||||||
|
return {
|
||||||
|
input: inputFile,
|
||||||
|
plugins: [
|
||||||
|
resolve({
|
||||||
|
preferBuiltins: false,
|
||||||
|
... options && options.resolve
|
||||||
|
}),
|
||||||
|
... (options && options.inputPlugins) || []
|
||||||
|
],
|
||||||
|
output: [
|
||||||
|
outputMaker('', options && options.output),
|
||||||
|
outputMaker('.min', { plugins: [terser()], ... options && options.output }),
|
||||||
|
],
|
||||||
|
... options && options.external && { external: options.external },
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
configNoCore(inputFile, outputMaker, options) {
|
||||||
|
options = { ... options };
|
||||||
|
options.output = { ... options.output };
|
||||||
|
options.output.globals = { ... options.output.globals };
|
||||||
|
if (!('@syndicate-lang/core' in options.output.globals))
|
||||||
|
options.output.globals['@syndicate-lang/core'] = 'Syndicate';
|
||||||
|
options.external = options.external || [];
|
||||||
|
options.external.push('@syndicate-lang/core');
|
||||||
|
return this.config(inputFile, outputMaker, options);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue