From 6a7f62f2c2c36bed871e36d401a19894b6eb6761 Mon Sep 17 00:00:00 2001 From: hide_d Date: Sun, 12 Dec 2021 16:33:20 +0900 Subject: [PATCH] =?UTF-8?q?build(WIP):=20php=EB=8B=A8=EC=97=90=EC=84=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=EB=90=9C=20dist=5Fjs=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EA=B2=8C=20js,css=20=EB=A1=9C=EB=93=9C=20-=20fix:=20webpack=20?= =?UTF-8?q?=EC=B6=9C=EB=A0=A5=EB=AC=BC=20=EB=AC=B8=EC=A0=9C=20-=20webpack?= =?UTF-8?q?=20splitChunks=20=ED=8C=8C=EC=9D=BC=20=ED=86=B5=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hwe/index.php | 8 +-- hwe/ts/v_main.ts | 1 + src/sammo/WebUtil.php | 37 ++++++++++++++ webpack.config.cjs | 111 +++++++++++++----------------------------- 4 files changed, 72 insertions(+), 85 deletions(-) diff --git a/hwe/index.php b/hwe/index.php index 512b5c6c..b2c0b649 100644 --- a/hwe/index.php +++ b/hwe/index.php @@ -118,15 +118,9 @@ if (!$otherTextInfo) { - - - - - + - - DB::prefix(), diff --git a/hwe/ts/v_main.ts b/hwe/ts/v_main.ts index d20f92e7..a2a1b1fb 100644 --- a/hwe/ts/v_main.ts +++ b/hwe/ts/v_main.ts @@ -1,4 +1,5 @@ import '@scss/main.scss'; +import "@scss/common_legacy.scss"; exportWindow(scrollHardTo, 'scrollHardTo'); diff --git a/src/sammo/WebUtil.php b/src/sammo/WebUtil.php index cc93c471..e61d3457 100644 --- a/src/sammo/WebUtil.php +++ b/src/sammo/WebUtil.php @@ -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[] = "\n"; + continue; + } + $mtime = filemtime($checkPath); + if($ext == 'css'){ + $outputs[] = "\n"; + } + else if($ext == 'js'){ + $typeText = $isDefer ? 'defer' : ''; + $outputs[] = "\n"; + } + } + } + return join("", $outputs); + } + public static function printJS(string $path, bool $isDefer = false) { //async 옵션 고려? diff --git a/webpack.config.cjs b/webpack.config.cjs index 5942ae29..c1639052 100644 --- a/webpack.config.cjs +++ b/webpack.config.cjs @@ -33,7 +33,7 @@ module.exports = (env, argv) => { let emitDone = false; let writeDone = false; return function (percentage, msg, ...args) { - if(msg == 'emitting'){ + if (msg == 'emitting') { emitDone = true; } if (percentage == 0) { @@ -59,6 +59,33 @@ module.exports = (env, argv) => { entryIngame[entry] = `${tsDir}/${filePath}`; } + const optimization = { + splitChunks: { + cacheGroups: { + commons: { + test: /[\\/]node_modules[\\/]/, + name: 'vendors', + priority: -10, + chunks: 'all', + reuseExistingChunk: true, + }, + default: { + name: 'common_ts', + minChunks: 2, + priority: -20, + chunks: 'all', + reuseExistingChunk: true, + }, + }, + }, + minimizer: [ + new ESBuildMinifyPlugin({ + css: true + }), + ], + moduleIds: 'deterministic', + }; + const ingame_vue = { name: `ingame_${versionTarget}_vue`, resolve: { @@ -77,32 +104,7 @@ module.exports = (env, argv) => { path: resolve(outputPath, 'vue') }, devtool: 'source-map', - optimization: { - splitChunks: { - cacheGroups: { - commons: { - test: /[\\/]node_modules[\\/]/, - name: 'vendors_vue', - priority: -10, - chunks: 'all', - reuseExistingChunk: true, - }, - default: { - name: 'common_vue', - minChunks: 2, - priority: -20, - chunks: 'all', - reuseExistingChunk: true, - }, - }, - }, - minimizer: [ - new ESBuildMinifyPlugin({ - css: true - }), - ], - moduleIds: 'deterministic', - }, + optimization, module: { rules: [ //FROM `vue inspect` and some tweaks @@ -211,30 +213,7 @@ module.exports = (env, argv) => { path: resolve(outputPath, 'ts') }, devtool: 'source-map', - optimization: { - splitChunks: { - cacheGroups: { - commons: { - test: /[\\/]node_modules[\\/]/, - name: 'vendors', - chunks: 'all', - }, - default: { - name: 'common_ts', - minChunks: 2, - priority: -20, - chunks: 'all', - reuseExistingChunk: true, - }, - }, - }, - minimizer: [ - new ESBuildMinifyPlugin({ - css: true - }), - ], - moduleIds: 'deterministic', - }, + optimization, module: { rules: [{ test: /\.ts$/, @@ -319,30 +298,7 @@ module.exports = (env, argv) => { path: resolve(outputPath, 'gateway') }, devtool: 'source-map', - optimization: { - splitChunks: { - cacheGroups: { - commons: { - test: /[\\/]node_modules[\\/]/, - name: 'vendors', - chunks: 'all', - }, - default: { - name: 'common_ts', - minChunks: 2, - priority: -20, - chunks: 'all', - reuseExistingChunk: true, - }, - }, - }, - minimizer: [ - new ESBuildMinifyPlugin({ - css: true - }), - ], - moduleIds: 'deterministic', - }, + optimization, module: { rules: [{ test: /\.ts$/, @@ -397,9 +353,8 @@ module.exports = (env, argv) => { }, }; - if(env.WEBPACK_WATCH || !versionValue){ - return [ingame_vue]; - //return [gateway, ingame_vue, ingame]; + if (env.WEBPACK_WATCH || !versionValue) { + return [gateway, ingame_vue, ingame]; } const buildConfList = [];