build(WIP): php단에서 변경된 dist_js에 맞게 js,css 로드

- fix: webpack 출력물 문제
- webpack splitChunks 파일 통일
This commit is contained in:
2021-12-12 16:33:20 +09:00
parent 0b82024caa
commit 6a7f62f2c2
4 changed files with 72 additions and 85 deletions
+37
View File
@@ -139,6 +139,43 @@ class WebUtil
return static::preloadAsset($path, 'script');
}
public static function printDist(string $type, string|array $entryName, bool $isDefer = false){
if(is_string($entryName)){
$entryName = [$entryName];
}
if(is_subclass_of('\\sammo\\VersionGit', '\\sammo\\VersionGitDynamic')){
$version = DB::prefix().'_dynamic';
}
else{
$version = VersionGit::getVersion();
}
$basePath = dirname(__DIR__, 2)."/dist_js/{$version}/{$type}";
$serverBasePath = \phpUri::parse(ServConfig::$serverWebPath)->path;
$serverBasePath .= "/dist_js/{$version}/{$type}";
$outputs = ["\n"];
foreach(["vendors", "common_ts", ...$entryName] as $moduleName){
foreach(['js', 'css'] as $ext){
$checkPath = $basePath."/{$moduleName}.{$ext}";
if (!file_exists($checkPath)) {
$outputs[] = "<!-- '{$version}/{$type}/{$moduleName}.{$ext}' -->\n";
continue;
}
$mtime = filemtime($checkPath);
if($ext == 'css'){
$outputs[] = "<link href='{$serverBasePath}/{$moduleName}.{$ext}?{$mtime}' rel='stylesheet' type='text/css' />\n";
}
else if($ext == 'js'){
$typeText = $isDefer ? 'defer' : '';
$outputs[] = "<script src='{$serverBasePath}/{$moduleName}.{$ext}?{$mtime}' {$typeText}></script>\n";
}
}
}
return join("", $outputs);
}
public static function printJS(string $path, bool $isDefer = false)
{
//async 옵션 고려?