packages/cli: support multiple packager configs
This commit is contained in:
@@ -21,32 +21,34 @@ import postcss from 'rollup-plugin-postcss';
|
||||
import esbuild from 'rollup-plugin-esbuild';
|
||||
import imageFiles from 'rollup-plugin-image-files';
|
||||
import json from '@rollup/plugin-json';
|
||||
import { RollupWatchOptions } from 'rollup';
|
||||
import { RollupOptions } from 'rollup';
|
||||
|
||||
export const makeConfig = (): RollupWatchOptions => {
|
||||
return {
|
||||
input: 'src/index.ts',
|
||||
output: {
|
||||
file: 'dist/index.esm.js',
|
||||
format: 'module',
|
||||
export const makeConfigs = (): RollupOptions[] => {
|
||||
return [
|
||||
{
|
||||
input: 'src/index.ts',
|
||||
output: {
|
||||
file: 'dist/index.esm.js',
|
||||
format: 'module',
|
||||
},
|
||||
plugins: [
|
||||
peerDepsExternal({
|
||||
includeDependencies: true,
|
||||
}),
|
||||
resolve({
|
||||
mainFields: ['browser', 'module', 'main'],
|
||||
}),
|
||||
commonjs({
|
||||
include: ['node_modules/**', '../../node_modules/**'],
|
||||
exclude: ['**/*.stories.*', '**/*.test.*'],
|
||||
}),
|
||||
postcss(),
|
||||
imageFiles(),
|
||||
json(),
|
||||
esbuild({
|
||||
target: 'es2019',
|
||||
}),
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
peerDepsExternal({
|
||||
includeDependencies: true,
|
||||
}),
|
||||
resolve({
|
||||
mainFields: ['browser', 'module', 'main'],
|
||||
}),
|
||||
commonjs({
|
||||
include: ['node_modules/**', '../../node_modules/**'],
|
||||
exclude: ['**/*.stories.*', '**/*.test.*'],
|
||||
}),
|
||||
postcss(),
|
||||
imageFiles(),
|
||||
json(),
|
||||
esbuild({
|
||||
target: 'es2019',
|
||||
}),
|
||||
],
|
||||
};
|
||||
];
|
||||
};
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { rollup, OutputOptions } from 'rollup';
|
||||
import { rollup, RollupOptions } from 'rollup';
|
||||
import chalk from 'chalk';
|
||||
import { relative as relativePath } from 'path';
|
||||
import { paths } from '../paths';
|
||||
import { makeConfig } from './config';
|
||||
import { makeConfigs } from './config';
|
||||
|
||||
function formatErrorMessage(error: any) {
|
||||
let msg = '';
|
||||
@@ -67,13 +67,21 @@ function formatErrorMessage(error: any) {
|
||||
return msg;
|
||||
}
|
||||
|
||||
export const buildPackage = async () => {
|
||||
async function build(config: RollupOptions) {
|
||||
try {
|
||||
const config = makeConfig();
|
||||
const bundle = await rollup(config);
|
||||
await bundle.generate(config.output as OutputOptions);
|
||||
await bundle.write(config.output as OutputOptions);
|
||||
if (config.output) {
|
||||
for (const output of [config.output].flat()) {
|
||||
await bundle.generate(output);
|
||||
await bundle.write(output);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
throw new Error(formatErrorMessage(error));
|
||||
}
|
||||
}
|
||||
|
||||
export const buildPackage = async () => {
|
||||
const configs = makeConfigs();
|
||||
await Promise.all(configs.map(build));
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user