Skip to content

Commit 776d95b

Browse files
committed
feat: add rollup v4
1 parent 2f5d5c2 commit 776d95b

36 files changed

+2339
-1346
lines changed

examples/react-component/build.config.mts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,27 @@ import { defineConfig } from '@ice/pkg';
33
// https://pkg.ice.work/reference/config-list
44
export default defineConfig({
55
plugins: [
6-
[
7-
'@ice/pkg-plugin-docusaurus',
8-
{
9-
remarkPlugins: [
10-
"require('@ice/remark-react-docgen-docusaurus')",
11-
// "[require('remark-react-docgen'), {}]",
12-
],
13-
},
14-
],
15-
['@ice/pkg-plugin-jsx-plus'],
6+
// [
7+
// '@ice/pkg-plugin-docusaurus',
8+
// {
9+
// remarkPlugins: [
10+
// "require('@ice/remark-react-docgen-docusaurus')",
11+
// // "[require('remark-react-docgen'), {}]",
12+
// ],
13+
// },
14+
// ],
15+
// ['@ice/pkg-plugin-jsx-plus'],
1616
],
1717
transform: {
18-
formats: ['esm', 'es2017', 'cjs'],
18+
// formats: [],
1919
},
20-
jsxRuntime: 'classic',
20+
// jsxRuntime: 'classic',
21+
// declaration: false,
2122
sourceMaps: false,
2223
bundle: {
23-
formats: ['esm', 'es2017'],
24-
development: true,
24+
formats: ['esm'],
25+
// modes: ['production', 'development']
26+
// development: true,
2527
},
2628
alias: {
2729
'@': './src',

examples/react-component/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@
3737
},
3838
"dependencies": {
3939
"@ice/jsx-runtime": "^0.2.0",
40-
"@swc/helpers": "^0.5.1",
41-
"babel-runtime-jsx-plus": "^0.1.5"
40+
"@swc/helpers": "^0.5.13",
41+
"babel-runtime-jsx-plus": "^0.1.5",
42+
"core-js": "^3.38.1"
4243
},
4344
"devDependencies": {
4445
"@ice/pkg": "workspace:*",
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export interface Person {
2+
age: number;
3+
name: string;
4+
}
5+
export declare const p: Person;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export default function (): void;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as React from 'react';
2+
import './index.scss';
3+
interface ButtonProps {
4+
/**
5+
* 设置按钮类型
6+
*/
7+
type?: 'primary' | 'default';
8+
/**
9+
* 点击跳转的地址,指定此属性 button 的行为和 a 链接一致
10+
*/
11+
href?: string;
12+
/**
13+
* 显式加载状态
14+
*/
15+
loading: boolean;
16+
/**
17+
* 点击按钮时的回调
18+
*/
19+
onClick?: React.MouseEventHandler;
20+
}
21+
export declare const app: Application;
22+
declare const Button: React.FunctionComponent<React.PropsWithChildren<ButtonProps>>;
23+
export default Button;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as React from 'react';
2+
export default class Input extends React.Component {
3+
render(): JSX.Element;
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { default as Button } from '@/components/Button';
2+
export { default as Test } from '@/components/Test';
3+
export { default as Input } from '@/components/Input';

packages/pkg/bin/cli.mjs

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,2 @@
11
#!/usr/bin/env node
2-
3-
import { fileURLToPath } from 'url';
4-
import consola from 'consola';
5-
import { cac } from 'cac';
6-
import { readFileSync } from 'fs';
7-
import { join, dirname } from 'path';
8-
import pkgService, { getBuiltInPlugins } from '../lib/index.js';
9-
10-
const __dirname = dirname(fileURLToPath(import.meta.url));
11-
12-
const cli = cac('ice-pkg');
13-
14-
(async () => {
15-
cli
16-
.command('build', 'Bundle files', {
17-
allowUnknownOptions: false,
18-
})
19-
.option('--config <config>', 'specify custom config path')
20-
.option('--analyzer', "visualize size of output files(it's only valid in bundle mode)", {
21-
default: false,
22-
})
23-
.option('--rootDir <rootDir>', 'specify root directory', {
24-
default: process.cwd(),
25-
})
26-
.action(async (options) => {
27-
delete options['--'];
28-
const { rootDir, ...commandArgs } = options;
29-
30-
await pkgService.run({
31-
command: 'build',
32-
commandArgs,
33-
getBuiltInPlugins,
34-
rootDir: options.rootDir,
35-
});
36-
});
37-
38-
cli
39-
.command('start', 'Watch files', {
40-
allowUnknownOptions: false,
41-
})
42-
.option('--config <config>', 'specify custom config path')
43-
.option('--analyzer', "visualize size of output files(it's only valid in bundle mode)", {
44-
default: false,
45-
})
46-
.option('--rootDir <rootDir>', 'specify root directory', {
47-
default: process.cwd(),
48-
})
49-
.action(async (options) => {
50-
delete options['--'];
51-
const { rootDir, ...commandArgs } = options;
52-
53-
await pkgService.run({
54-
command: 'start',
55-
commandArgs,
56-
getBuiltInPlugins,
57-
rootDir: options.rootDir,
58-
});
59-
});
60-
61-
cli.help();
62-
63-
const pkgPath = join(__dirname, '../package.json');
64-
cli.version(JSON.parse(readFileSync(pkgPath, 'utf-8')).version);
65-
66-
cli.parse(process.argv, { run: true });
67-
})()
68-
.catch((err) => {
69-
consola.error(err);
70-
process.exit(1);
71-
});
2+
import '../lib/cli.js'

packages/pkg/package.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,35 +37,37 @@
3737
"@babel/preset-react": "^7.18.6",
3838
"@babel/preset-typescript": "^7.18.6",
3939
"@rollup/plugin-alias": "^5.0.1",
40-
"@rollup/plugin-commonjs": "^25.0.0",
40+
"@rollup/plugin-commonjs": "^28.0.0",
4141
"@rollup/plugin-image": "^3.0.1",
42-
"@rollup/plugin-json": "^4.1.0",
42+
"@rollup/plugin-json": "^6.0.1",
4343
"@rollup/plugin-node-resolve": "^15.0.2",
44-
"@rollup/plugin-replace": "^5.0.1",
45-
"@rollup/pluginutils": "^4.1.2",
46-
"@swc/core": "1.3.80",
47-
"acorn": "^8.7.0",
44+
"@rollup/plugin-replace": "^6.0.0",
45+
"@rollup/pluginutils": "^5.0.0",
46+
"@swc/core": "1.7.40",
47+
"acorn": "^8.10.0",
4848
"autoprefixer": "^10.4.2",
4949
"build-scripts": "^2.0.0",
5050
"cac": "^6.7.12",
5151
"chokidar": "^3.5.3",
52+
"cli-spinners": "^3.2.0",
5253
"consola": "^2.15.3",
5354
"debug": "^4.3.3",
5455
"deepmerge": "^4.2.2",
5556
"es-module-lexer": "^1.3.1",
5657
"escape-string-regexp": "^5.0.0",
58+
"figures": "^6.1.0",
5759
"fs-extra": "^10.0.0",
5860
"globby": "^11.0.4",
5961
"gzip-size": "^7.0.0",
6062
"lodash.merge": "^4.6.2",
6163
"magic-string": "^0.25.7",
6264
"picocolors": "^1.0.0",
63-
"postcss": "^8.4.6",
65+
"postcss": "^8.4.31",
6466
"postcss-plugin-rpx2vw": "^1.0.0",
65-
"rollup": "^2.79.1",
67+
"rollup": "^4.0.0",
6668
"rollup-plugin-styles": "^4.0.0",
6769
"rollup-plugin-visualizer": "^5.8.3",
68-
"semver": "^7.0.0",
70+
"semver": "^7.5.2",
6971
"tsc-alias": "^1.8.2",
7072
"typescript": "^4.9.4"
7173
},

packages/pkg/src/cli.ts

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { fileURLToPath } from 'node:url';
2+
import consola from 'consola';
3+
import { cac } from 'cac';
4+
import { readFileSync } from 'node:fs';
5+
import { join, dirname } from 'node:path';
6+
import { pkgService } from './service.js';
7+
import { getBuiltInPlugins } from './utils.js';
8+
9+
const __dirname = dirname(fileURLToPath(import.meta.url));
10+
11+
const cli = cac('ice-pkg');
12+
13+
(async () => {
14+
cli
15+
.command('build', 'Bundle files', {
16+
allowUnknownOptions: false,
17+
})
18+
.option('--config <config>', 'specify custom config path')
19+
.option('--analyzer', "visualize size of output files(it's only valid in bundle mode)", {
20+
default: false,
21+
})
22+
.option('--rootDir <rootDir>', 'specify root directory', {
23+
default: process.cwd(),
24+
})
25+
.action(async (options) => {
26+
delete options['--'];
27+
const { rootDir, ...commandArgs } = options;
28+
29+
await pkgService.run({
30+
command: 'build',
31+
commandArgs,
32+
getBuiltInPlugins,
33+
rootDir: options.rootDir,
34+
});
35+
});
36+
37+
cli
38+
.command('start', 'Watch files', {
39+
allowUnknownOptions: false,
40+
})
41+
.option('--config <config>', 'specify custom config path')
42+
.option('--analyzer', "visualize size of output files(it's only valid in bundle mode)", {
43+
default: false,
44+
})
45+
.option('--rootDir <rootDir>', 'specify root directory', {
46+
default: process.cwd(),
47+
})
48+
.action(async (options) => {
49+
delete options['--'];
50+
const { rootDir, ...commandArgs } = options;
51+
52+
await pkgService.run({
53+
command: 'start',
54+
commandArgs,
55+
getBuiltInPlugins,
56+
rootDir: options.rootDir,
57+
});
58+
});
59+
60+
cli.help();
61+
62+
const pkgPath = join(__dirname, '../package.json');
63+
cli.version(JSON.parse(readFileSync(pkgPath, 'utf-8')).version);
64+
65+
cli.parse(process.argv, { run: true });
66+
})()
67+
.catch((err) => {
68+
consola.error(err);
69+
process.exit(1);
70+
});

packages/pkg/src/commands/build.ts

Lines changed: 11 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import fse from 'fs-extra';
2-
import { RollupOptions } from 'rollup';
32
import { getBuildTasks } from '../helpers/getBuildTasks.js';
4-
import { getRollupOptions } from '../helpers/getRollupOptions.js';
5-
import { buildBundleTasks } from '../tasks/bundle.js';
6-
import { buildTransformTasks } from '../tasks/transform.js';
7-
8-
import type { Context, OutputResult, TaskRunnerContext } from '../types.js';
3+
import type { Context, OutputResult } from '../types.js';
4+
import { parallelPromiseAll } from '../utils.js';
5+
import { RunnerLinerTerminalReporter } from '../helpers/runnerReporter.js';
6+
import { getTaskRunners } from '../helpers/getTaskRunners.js';
97

108
export default async function build(context: Context) {
119
const { applyHook, commandArgs } = context;
@@ -31,45 +29,16 @@ export default async function build(context: Context) {
3129
const outputDirs = taskConfigs.map((config) => config.outputDir).filter(Boolean);
3230
outputDirs.forEach((outputDir) => fse.emptyDirSync(outputDir));
3331

34-
const transformOptions = buildTasks
35-
.filter(({ config }) => config.type === 'transform')
36-
.map((buildTask) => {
37-
const { config: { modes } } = buildTask;
38-
return modes.map((mode) => {
39-
const taskRunnerContext: TaskRunnerContext = { mode, buildTask };
40-
const rollupOptions = getRollupOptions(context, taskRunnerContext);
41-
return [rollupOptions, taskRunnerContext] as [RollupOptions, TaskRunnerContext];
42-
});
43-
})
44-
.flat(1);
45-
46-
const bundleOptions = buildTasks
47-
.filter(({ config }) => config.type === 'bundle')
48-
.map((buildTask) => {
49-
const { config: { modes } } = buildTask;
50-
return modes.map((mode) => {
51-
const taskRunnerContext: TaskRunnerContext = { mode, buildTask };
52-
const rollupOptions = getRollupOptions(context, taskRunnerContext);
53-
return [rollupOptions, taskRunnerContext] as [RollupOptions, TaskRunnerContext];
54-
});
55-
})
56-
.flat(1);
32+
const tasks = getTaskRunners(buildTasks, context)
5733

5834
try {
59-
const outputResults: OutputResult[] = [];
60-
const { outputResults: transformOutputResults } = await buildTransformTasks(
61-
transformOptions,
62-
context,
63-
);
64-
const { outputResults: bundleOutputResults } = await buildBundleTasks(
65-
bundleOptions,
66-
context,
67-
);
35+
const results = parallelPromiseAll(tasks.map(task => () => task.run()))
36+
const terminal = new RunnerLinerTerminalReporter(tasks)
37+
terminal.start()
38+
39+
const outputResults: OutputResult[] = await results
6840

69-
outputResults.push(
70-
...bundleOutputResults,
71-
...transformOutputResults,
72-
);
41+
terminal.stop()
7342

7443
await applyHook('after.build.compile', outputResults);
7544
} catch (err) {

0 commit comments

Comments
 (0)