rename compiler file

This commit is contained in:
Km.Van
2026-07-11 15:09:35 +08:00
parent f785416560
commit 05b0528e6b
6 changed files with 36 additions and 29 deletions
+1 -1
View File
@@ -4,4 +4,4 @@ namespace InnStudio\Make;
include __DIR__ . '/vendor/autoload.php';
new \InnStudio\Prober\Compiler\Compiler(__DIR__);
new \InnStudio\Prober\Compiler\Compiler(__DIR__)->compile();
+6 -13
View File
@@ -61,7 +61,7 @@ final class Compiler
// 2. 生产模式下,合并所有的 PHP 组件文件
// 2. In production mode, merge all PHP component files
if ( ! $this->isDev()) {
if ( !$this->isDev()) {
foreach ($this->yieldPhpFiles($this->componentsDir) as $filePath) {
$code .= $this->getCodeViaFilePath($filePath);
}
@@ -83,13 +83,13 @@ final class Compiler
$code = preg_replace("/(\r\n|\r|\n)+/", "\n", $code);
// 4. 写入初步打包的代码 / 4. Write compiled code into target file
if ( ! $this->writeFile($code)) {
if ( !$this->writeFile($code)) {
throw new Exception('[Compiler Error] Failed to write compiled source code.');
}
// 5. 生产模式下,注入前端 JS/CSS 到单文件中
// 5. In production mode, inject frontend JS/CSS assets into the single file
if ( ! $this->isDev()) {
if ( !$this->isDev()) {
try {
$scriptGen = new ScriptGeneration(
scriptFilePath: "{$this->root}/.tmp/app.js",
@@ -152,13 +152,6 @@ final class Compiler
return isset($argv) && \in_array('dev', $argv, true);
}
private function isDebug(): bool
{
global $argv;
return isset($argv) && \in_array('debug', $argv, true);
}
private function preDefine(array $code): string
{
$codeStr = implode("\n", $code);
@@ -197,7 +190,7 @@ PHP;
private function genVendorCode(): string
{
if ( ! $this->isDev()) {
if ( !$this->isDev()) {
return '';
}
@@ -212,7 +205,7 @@ PHP;
*/
private function yieldPhpFiles(string $dir): Generator
{
if ( ! is_dir($dir)) {
if ( !is_dir($dir)) {
return;
}
@@ -230,7 +223,7 @@ PHP;
{
$dir = \dirname($this->compileFilePath);
if ( ! is_dir($dir) && ! mkdir($dir, 0755, true) && ! is_dir($dir)) {
if ( !is_dir($dir) && !mkdir($dir, 0755, true) && !is_dir($dir)) {
return false;
}
+2 -2
View File
@@ -6,9 +6,9 @@
"type": "module",
"scripts": {
"lang": "node ./tools/lang-builder.mjs",
"dev": "vite --config ./dev.vite.config.mjs",
"dev": "vite --config ./vite.config.dev.mjs",
"dev:php": "bash ./php-dev.sh",
"build": "vite build --config ./prod.vite.config.mjs",
"build": "vite build --config ./vite.config.dist.mjs",
"build:php": "bash ./php-build.sh",
"build:php-debug": "php ./Make.php build debug && echo '\nPlease access via http://localhost:8001/prober.php' && PHP_CLI_SERVER_WORKERS=4 php -S localhost:8001 -t dist",
"php-cs-fixer-54": "php-cs-fixer fix ./src --config=.php-cs-fixer54.php"
+1 -1
View File
@@ -1,6 +1,6 @@
#!/bin/bash
set -e
php-cs-fixer fix ./src --config=.php-cs-fixer54
php-cs-fixer fix ./src --config=.php-cs-fixer.dist.php
php ./Make.php build
echo '\nPlease access via http://localhost:8001/prober.php'
PHP_CLI_SERVER_WORKERS=8 php -S localhost:8001 -t dist
+26 -12
View File
@@ -6,14 +6,16 @@ import { defineConfig } from "vite";
const __dirname = dirname(fileURLToPath(import.meta.url));
const tmpDir = resolve(__dirname, ".tmp");
if (!existsSync(tmpDir)) {
mkdirSync(tmpDir);
}
export default defineConfig({
build: {
emptyOutDir: true,
lib: {
cssFileName: "app",
cssFileName: "app", // 如果想让生成的 css 叫 app.css,保留此项
entry: resolve(__dirname, "src/main.tsx"),
fileName: () => "app.js",
formats: ["umd"],
@@ -22,31 +24,43 @@ export default defineConfig({
outDir: tmpDir,
sourcemap: "hidden",
target: "es2024",
// rollupOptions:{
// 如果之后需要强制把所有 asset/css 改名,可以取消下方注释
// rollupOptions: {
// output: {
// assetFileNames: (assetInfo) => {
// for(const name of assetInfo.names) {
// if (name.endsWith('.css')) {
// return 'app.css';
// }
// if (assetInfo.name && assetInfo.name.endsWith('.css')) {
// return 'app.css';
// }
// return '[name].[ext]';
// }
// }
// }
},
define: {
__DEV__: false,
DEBUG: false,
"process.env": {
NODE_ENV: JSON.stringify("production"),
WEBPACK_ENV: JSON.stringify("production"),
// 1. 核心 CSS 优化(适配 Vite 8.1 + 解决 lightningcss 的 :global 报错)
css: {
lightningcss: {
// 👈 开启这个,lightningcss 就能完美识别并处理 :global 语法了
cssModules: true,
},
minify: true, // Vite 8.x 推荐直接在这里开启 CSS 压缩
transformer: "lightningcss",
},
define: {
__DEV__: "false",
DEBUG: "false",
"process.env.NODE_ENV": JSON.stringify("production"),
"process.env.WEBPACK_ENV": JSON.stringify("production"),
},
esbuild: {
legalComments: "none",
},
mode: "production",
plugins: [react()],
resolve: {
alias: {
"@": resolve(__dirname, "src/"),