Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.14.0 (2025-12-30)

- feat(plugin-blocklet): support custom chunkSizeLimit

## 0.13.2 (2025-12-29)

- fix(vite-plugin-blocklet): truely hide powered by
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "create-blocklet",
"private": true,
"version": "0.13.2",
"version": "0.14.0",
"description": "",
"keywords": [],
"author": "",
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-blocklet",
"version": "0.13.2",
"version": "0.14.0",
"exports": "./index.js",
"type": "module",
"repository": "[email protected]:blocklet/create-blocklet.git",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"typescript": "^5.7.2",
"vite": "^7.0.0",
"vite-node": "^3.2.4",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vite-plugin-require": "^1.2.14",
"vite-plugin-svgr": "^4.3.0",
"vite-tsconfig-paths": "^5.1.4",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
"simple-git-hooks": "^2.11.1",
"tsx": "^4.19.3",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vite-plugin-svgr": "^4.3.0",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/did-wallet-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"simple-git-hooks": "^2.11.1",
"vite": "^7.0.0",
"vite-node": "^3.2.4",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vite-plugin-require": "^1.2.14",
"vite-plugin-svgr": "^4.3.0",
"zx": "^8.3.2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"tsx": "^4.19.3",
"typescript": "^5.7.3",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vite-plugin-svgr": "^4.3.0",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/react-dapp-ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@
"tsx": "^4.19.3",
"typescript": "^5.7.3",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vite-plugin-svgr": "^4.3.0",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/react-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"simple-git-hooks": "^2.11.1",
"tsx": "^4.19.3",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vite-plugin-svgr": "^4.3.0",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/react-gun-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"simple-git-hooks": "^2.11.1",
"tsx": "^4.19.3",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vite-plugin-svgr": "^4.3.0",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/react-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vite-plugin-svgr": "^4.3.0",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/solidjs-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"simple-git-hooks": "^2.11.1",
"tsx": "^4.19.3",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vite-plugin-solid": "^2.11.7",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/solidjs-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"simple-git-hooks": "^2.11.1",
"solid-js": "^1.9.4",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vite-plugin-solid": "^2.11.7",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/svelte-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
"svelte": "^4.2.19",
"tsx": "^4.19.3",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"zx": "^8.3.2"
},
"lint-staged": {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/svelte-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"simple-git-hooks": "^2.11.1",
"svelte": "^4.2.19",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"zx": "^8.3.2"
},
"lint-staged": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
"tsx": "^4.19.3",
"typescript": "^5.7.3",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vite-plugin-svgr": "^4.3.0",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/vue-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"simple-git-hooks": "^2.11.1",
"tsx": "^4.19.3",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vue": "^3.5.13",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/vue-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vue": "^3.5.13",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/vue-ts-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
"taze": "^0.16.9",
"typescript": "^5.7.3",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vue-tsc": "^2.2.2",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/vue2-dapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"simple-git-hooks": "^2.11.1",
"tsx": "^4.19.3",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vue": "^2.7.16",
"zx": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion packages/create-app/templates/vue2-static/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"rimraf": "^5.0.10",
"simple-git-hooks": "^2.11.1",
"vite": "^7.0.0",
"vite-plugin-blocklet": "^0.13.2",
"vite-plugin-blocklet": "^0.14.0",
"vue": "^2.7.16",
"zx": "^8.3.2"
},
Expand Down
1 change: 1 addition & 0 deletions plugins/vite-plugin-blocklet/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import setupClient from './libs/client.js';
* @property {number} [embedBuildConcurrency=0] - The plugins to be used in the embeds.
*
* @property {'middleware'|'client'|'server'|'wsUpgrade'} [hmrMode='middleware'] - 当未传入任何 option 参数时,会自动变为 middleware 模式
* @property {number} [chunkSizeLimit=2000] - The chunk size limit in KB.
*/

/**
Expand Down
83 changes: 78 additions & 5 deletions plugins/vite-plugin-blocklet/libs/config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import fs from 'fs';
import path from 'path';
import { isEqual, joinURL, withTrailingSlash } from 'ufo';
import { toBlockletDid, isInBlocklet, blockletPort, blockletPrefix, getBlockletYAML } from './utils.js';

export default function createConfigPlugin() {
const SIZE = 1000;
const MAX_CHUNK_SIZE = 2000;

/**
* @param {object} options
* @param {number} [options.chunkSizeLimit=2048] - The chunk size limit in KB.
* @return {import('vite').Plugin} The Vite config plugin.
*/
export default function createConfigPlugin({ chunkSizeLimit = MAX_CHUNK_SIZE }) {
let resolvedConfig;

return {
name: 'blocklet:config',
configureServer(server) {
Expand Down Expand Up @@ -35,6 +47,11 @@ export default function createConfigPlugin() {
}

if (command === 'build') {
let targetConfig = {
build: {
chunkSizeWarningLimit: chunkSizeLimit,
},
};
if (!config.base) {
try {
let { name, did } = await getBlockletYAML();
Expand All @@ -43,18 +60,74 @@ export default function createConfigPlugin() {
}
if (did) {
const base = `/.blocklet/proxy/${did}/`;
return {
base,
};
targetConfig.base = base;
return targetConfig;
}
} catch (err) {
console.error(err);
return {};
return targetConfig;
}
}
}

return {};
},
configResolved(config) {
resolvedConfig = config;
},
closeBundle() {
const limitInKB = chunkSizeLimit;
const outDir = resolvedConfig.build.outDir || 'dist';
const distPath = path.resolve(resolvedConfig.root, outDir);

if (!fs.existsSync(distPath)) return;

// 递归获取所有文件(包含子目录,如 assets/)
const getAllFiles = (dirPath, arrayOfFiles = []) => {
const files = fs.readdirSync(dirPath);
files.forEach((file) => {
const fullPath = path.join(dirPath, file);
if (fs.statSync(fullPath).isDirectory()) {
getAllFiles(fullPath, arrayOfFiles);
} else {
arrayOfFiles.push(fullPath);
}
});
return arrayOfFiles;
};

const allFiles = getAllFiles(distPath);
const overSizedFiles = [];

allFiles.forEach((filePath) => {
// 只检查 JS 和 CSS
if (filePath.endsWith('.js') || filePath.endsWith('.css')) {
const stats = fs.statSync(filePath);
const sizeKB = Number((stats.size / SIZE).toFixed(2));

if (sizeKB > limitInKB) {
overSizedFiles.push({
// 显示相对路径,方便查看是哪个 chunk
File: path.relative(distPath, filePath),
'Size(KB)': sizeKB,
'Limit(KB)': limitInKB,
});
}
}
});

if (overSizedFiles.length > 0) {
overSizedFiles.sort((a, b) => b['Size(KB)'] - a['Size(KB)']);
console.log('\n\x1b[41m\x1b[37m ERROR \x1b[0m \x1b[31mChunk Size Limit Exceeded:\x1b[0m');
console.table(overSizedFiles); // 以表格形式漂亮地打印

console.error(`\x1b[31mTotal ${overSizedFiles.length} files exceeded the ${limitInKB}KB limit.\x1b[0m\n`);

// 强制退出,确保 CI/CD 流程中断
process.exit(1);
} else {
console.log('\n\x1b[42m\x1b[30m DONE \x1b[0m All chunks are within the size limit.');
}
},
};
}
2 changes: 1 addition & 1 deletion plugins/vite-plugin-blocklet/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-plugin-blocklet",
"type": "module",
"version": "0.13.2",
"version": "0.14.0",
"description": "",
"main": "index.js",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion plugins/vite-plugin-wss-hmr/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "vite-plugin-wss-hmr",
"type": "module",
"version": "0.13.2",
"version": "0.14.0",
"description": "",
"main": "index.js",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.13.2
0.14.0
2 changes: 1 addition & 1 deletion website/docs/blocklet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository:
type: git
url: git+https://github.com/blocklet/create-blocklet.git
specVersion: 1.2.8
version: 0.13.2
version: 0.14.0
logo: logo.png
files:
- logo.png
Expand Down
2 changes: 1 addition & 1 deletion website/pages/blocklet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ repository:
type: git
url: git+https://github.com/blocklet/create-blocklet.git
specVersion: 1.2.8
version: 0.13.2
version: 0.14.0
logo: logo.png
files:
- logo.png
Expand Down
Loading