Refactor rollup configuration
This commit is contained in:
parent
7332096828
commit
9e322c4cfb
|
@ -1,53 +1,6 @@
|
|||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
|
||||
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 || {})
|
||||
};
|
||||
}
|
||||
|
||||
import { SyndicateRollup } from '../../rollup.js';
|
||||
const r = new SyndicateRollup('syndicate-compiler', { globalName: 'SyndicateCompiler' });
|
||||
export default [
|
||||
{
|
||||
input: 'lib/index.js',
|
||||
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()] }),
|
||||
],
|
||||
}
|
||||
r.config('lib/index.js', r.umd),
|
||||
r.config('lib/index.js', r.es6),
|
||||
];
|
||||
|
|
|
@ -1,56 +1,16 @@
|
|||
import resolve from '@rollup/plugin-node-resolve';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
|
||||
function distfile(insertion) {
|
||||
const f = `syndicate${insertion}.js`;
|
||||
return `dist/${f}`;
|
||||
}
|
||||
|
||||
function umd(insertion, extra) {
|
||||
return {
|
||||
file: distfile(insertion),
|
||||
format: 'umd',
|
||||
name: 'Syndicate',
|
||||
sourcemap: true,
|
||||
globals: {
|
||||
'crypto': 'crypto',
|
||||
},
|
||||
... (extra || {})
|
||||
};
|
||||
}
|
||||
|
||||
function es6(insertion, extra) {
|
||||
return {
|
||||
file: distfile('.es6' + insertion),
|
||||
format: 'es',
|
||||
sourcemap: true,
|
||||
... (extra || {})
|
||||
};
|
||||
}
|
||||
|
||||
import { SyndicateRollup } from '../../rollup.js';
|
||||
const r = new SyndicateRollup('syndicate', { globalName: 'Syndicate' });
|
||||
export default [
|
||||
{
|
||||
input: 'lib/index.js',
|
||||
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()] }),
|
||||
],
|
||||
}
|
||||
r.config('lib/index.js', r.umd, {
|
||||
output: {
|
||||
globals: {
|
||||
'crypto': 'crypto',
|
||||
},
|
||||
},
|
||||
}),
|
||||
r.config('lib/index.js', r.es6, {
|
||||
resolve: {
|
||||
moduleDirectories: ['stubs', 'node_modules'],
|
||||
},
|
||||
}),
|
||||
];
|
||||
|
|
|
@ -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