chore: switch bundler to tsup

This commit is contained in:
haiqin 2024-01-27 14:38:40 +08:00
parent 7b6713bc6c
commit 71d6765b05
6 changed files with 36 additions and 76 deletions

View File

@ -20,7 +20,7 @@ import chalk from 'chalk';
import * as solid from './solid-reactive.js';
import * as reactively from '@reactively/core';
import Table from 'cli-table';
import { reactive, computed } from '../dist/index.js';
import { reactive, computed, RNode } from '../dist/index.js';
const BATCHED = true;
const RUNS_PER_TIER = 150;
@ -44,10 +44,9 @@ const SOLUTIONS = {
const isSolution = (layers, answer) => answer.every((_, i) => SOLUTIONS[layers][i] === _);
async function main() {
debugger
const report = {};
// report.solid = { fn: runSolid, runs: [] };
// report.reactively = { fn: runReactively, runs: [], avg: [] };
report.solid = { fn: runSolid, runs: [] };
report.reactively = { fn: runReactively, runs: [], avg: [] };
report.inluaReactive = { fn: runInulaReactive, runs: [], avg: [] };
// report.inluaDeepReactive = { fn: runInulaDeepReactive, runs: [], avg: [] };
@ -91,7 +90,6 @@ async function main() {
slowestLib = lib;
}
}
report[fastestLib].runs[i] = chalk.green(report[fastestLib].runs[i].toFixed(2));
report[slowestLib].runs[i] = chalk.red(report[slowestLib].runs[i].toFixed(2));
}
@ -113,10 +111,10 @@ async function start(runner, layers) {
function runInulaReactive(layers, done) {
const start = {
a: new reactive(1),
b: new reactive(2),
c: new reactive(3),
d: new reactive(4),
a: new RNode(1),
b: new RNode(2),
c: new RNode(3),
d: new RNode(4),
};
let layer = start;
@ -124,10 +122,10 @@ function runInulaReactive(layers, done) {
for (let i = layers; i--; ) {
layer = (m => {
return {
a: new computed(() => m.b.get()),
b: new computed(() => m.a.get() - m.c.get()),
c: new computed(() => m.b.get() + m.d.get()),
d: new computed(() => m.c.get()),
a: new RNode(() => m.b.get()),
b: new RNode(() => m.a.get() - m.c.get()),
c: new RNode(() => m.b.get() + m.d.get()),
d: new RNode(() => m.c.get()),
};
})(layer);
}

View File

@ -5,7 +5,7 @@
"main": "dist/index.js",
"type": "module",
"scripts": {
"build": "rollup --config ./rollup.config.js",
"build": "tsup",
"test": "jest --config=jest.config.js",
"bench": "node --experimental-specifier-resolution=node --inspect ./bench/index.js"
},
@ -16,6 +16,7 @@
"devDependencies": {
"chalk": "^5.3.0",
"cli-table": "^0.3.11",
"tslib": "^2.6.2"
"tsup": "^6.7.0",
"esbuild-plugin-replace": "^1.4.0"
}
}

View File

@ -1,59 +0,0 @@
/*
* Copyright (c) 2023 Huawei Technologies Co.,Ltd.
*
* openInula is licensed under Mulan PSL v2.
* You can use this software according to the terms and conditions of the Mulan PSL v2.
* You may obtain a copy of Mulan PSL v2 at:
*
* http://license.coscl.org.cn/MulanPSL2
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
* See the Mulan PSL v2 for more details.
*/
import nodeResolve from '@rollup/plugin-node-resolve';
import babel from '@rollup/plugin-babel';
import path from 'path';
import replace from '@rollup/plugin-replace';
const extensions = ['.js', '.ts', '.tsx'];
const getBasicPlugins = mode => {
return [
nodeResolve({
extensions,
modulesOnly: true,
}),
babel({
exclude: 'node_modules/**',
configFile: path.join(__dirname, './babel.config.cjs'),
extensions,
}),
replace({
values: {
'process.env.NODE_ENV': `"${mode}"`,
},
preventAssignment: true,
}),
];
};
function genConfig(mode) {
return {
input: path.resolve(__dirname, 'src', 'index.ts'),
output: [
{
file:path.resolve(__dirname, 'dist', 'index.js'),
format: 'esm',
},
],
plugins: [
...getBasicPlugins(mode),
],
};
}
export default [genConfig('production')];

View File

@ -0,0 +1,20 @@
import {defineConfig} from 'tsup';
import {replace} from 'esbuild-plugin-replace';
export default defineConfig({
esbuildPlugins: [
replace({
values: {
'process.env.NODE_ENV': '\'production\'',
},
})],
entry: [
'src/index.ts',
],
format: [
'cjs',
'esm',
],
treeshake: true,
clean: true,
});

View File

@ -50,7 +50,7 @@ const getBasicPlugins = mode => {
}),
babel({
exclude: 'node_modules/**',
configFile: path.join(__dirname, '../../babel.config.cjs'),
configFile: path.join(__dirname, '../../babel.config.js'),
babelHelpers: 'runtime',
extensions,
}),

View File

@ -202,4 +202,4 @@ describe('ElementUnit', () => {
expect(t.isStringLiteral((firstChild as HTMLUnit).tag, { value: 'div' })).toBeTruthy();
expect((firstChild as HTMLUnit).children![0].type).toBe('text');
});
});
});