build(WIP): 빌드 결과물을 서버 주소에 관계없이 통일

This commit is contained in:
2021-12-12 13:52:55 +09:00
parent 83eb58fffa
commit f5b33dbbc7
2 changed files with 79 additions and 57 deletions
+19 -7
View File
@@ -140,7 +140,7 @@ if (!$v->validate()) {
$target = Util::getPost('target'); $target = Util::getPost('target');
$server = basename($request['server']); $server = basename($request['server']);
$settingBasePath = __DIR__ . "/{$server}/d_setting/";
$allowFullUpdate = in_array('fullUpdate', $session->acl[$server] ?? []); $allowFullUpdate = in_array('fullUpdate', $session->acl[$server] ?? []);
$allowFullUpdate |= $session->userGrade >= 6; $allowFullUpdate |= $session->userGrade >= 6;
@@ -244,20 +244,28 @@ if ($server == $baseServerName) {
$version = getVersion(); $version = getVersion();
$gitHash = getHash(); $gitHash = getHash();
if ( if (
hash_file("sha256", __DIR__ . '/' . $server . '/d_setting/VersionGit.dynamic.orig.php') == hash_file("sha256", $settingBasePath . 'VersionGit.dynamic.orig.php') ==
hash_file("sha256", __DIR__ . '/' . $server . '/d_setting/VersionGit.php') hash_file("sha256", $settingBasePath . 'VersionGit.php')
) { ) {
if (file_exists($settingBasePath . 'VersionGit.json')) {
unlink($settingBasePath . 'VersionGit.json');
}
$result = true; $result = true;
} else { } else {
$result = Util::generateFileUsingSimpleTemplate( $result = Util::generateFileUsingSimpleTemplate(
__DIR__ . '/' . $server . '/d_setting/VersionGit.orig.php', $settingBasePath . 'VersionGit.orig.php',
__DIR__ . '/' . $server . '/d_setting/VersionGit.php', $settingBasePath . 'VersionGit.php',
[ [
'verionGit' => $version, 'verionGit' => $version,
'hash' => $gitHash 'hash' => $gitHash
], ],
true true
); );
file_put_contents($settingBasePath . 'VersionGit.json', Json::encode([
'versionGit' => $version,
'hash' => $gitHash,
]));
} }
//git 업데이트했는데, package.json이 바뀌면 곤란하니까 //git 업데이트했는데, package.json이 바뀌면 곤란하니까
@@ -333,14 +341,18 @@ $zip->close();
$version = getVersion($target); $version = getVersion($target);
$gitHash = getHash($target); $gitHash = getHash($target);
$result = Util::generateFileUsingSimpleTemplate( $result = Util::generateFileUsingSimpleTemplate(
__DIR__ . '/' . $server . '/d_setting/VersionGit.orig.php', $settingBasePath . 'VersionGit.orig.php',
__DIR__ . '/' . $server . '/d_setting/VersionGit.php', $settingBasePath . 'VersionGit.php',
[ [
'verionGit' => $version, 'verionGit' => $version,
'hash' => $gitHash 'hash' => $gitHash
], ],
true true
); );
file_put_contents($settingBasePath . 'VersionGit.json', Json::encode([
'versionGit' => $version,
'hash' => $gitHash,
]));
genJS($server); genJS($server);
$storage->$server = [$target, $version]; $storage->$server = [$target, $version];
+60 -50
View File
@@ -6,12 +6,41 @@ const { resolve } = require('path');
const CleanTerminalPlugin = require('clean-terminal-webpack-plugin'); const CleanTerminalPlugin = require('clean-terminal-webpack-plugin');
const { ESBuildMinifyPlugin } = require('esbuild-loader') const { ESBuildMinifyPlugin } = require('esbuild-loader')
const webpack = require('webpack'); const webpack = require('webpack');
const fs = require('fs');
module.exports = (env, argv) => { module.exports = (env, argv) => {
const target = env.target ?? 'hwe'; const target = env.target ?? 'hwe';
const mode = argv.mode ?? 'production'; const mode = argv.mode ?? 'production';
const tsDir = resolve(__dirname, `${target}/ts/`); const tsDir = resolve(__dirname, `${target}/ts/`);
const build_exports = require(`${tsDir}/build_exports.json`); const build_exports = require(`${tsDir}/build_exports.json`);
const versionGitPath = resolve(__dirname, target, 'd_setting', 'VersionGit.json');
const versionValue = (() => {
if (!fs.existsSync(versionGitPath)) {
return undefined;
}
const versionInfo = JSON.parse(fs.readFileSync(versionGitPath, 'utf-8'));
return versionInfo.versionGit;
})()
const versionTarget = versionValue ?? `${target}_dynamic`;
const outputPath = resolve(__dirname, 'dist_js', versionTarget);
fs.mkdirSync(outputPath, {
recursive: true
});
const genBuildHook = function (oTarget) {
const checkFilePath = resolve(outputPath, `build_${oTarget}.txt`);
return function (percentage, msg) {
if (percentage == 0) {
if (fs.existsSync(checkFilePath)) {
fs.unlinkSync(checkFilePath);
}
} else if (percentage == 1) {
fs.writeFileSync(checkFilePath, new Date().toISOString(), 'utf-8');
}
};
};
//TODO: esbuild에 browserslist 사용 가능하면 적용 //TODO: esbuild에 browserslist 사용 가능하면 적용
//서버마다 ts 파일 구성이 다를 가능성이 높기 때문에 어떤 파일이 필요한지는 ts/build_exports.json을 확인한다. //서버마다 ts 파일 구성이 다를 가능성이 높기 때문에 어떤 파일이 필요한지는 ts/build_exports.json을 확인한다.
@@ -25,7 +54,7 @@ module.exports = (env, argv) => {
} }
const ingame_vue = { const ingame_vue = {
name: `ingame_${target}_vue`, name: `ingame_${versionTarget}_vue`,
resolve: { resolve: {
extensions: [".ts", ".tsx", ".vue", ".js"], extensions: [".ts", ".tsx", ".vue", ".js"],
alias: { alias: {
@@ -39,7 +68,7 @@ module.exports = (env, argv) => {
entry: entryIngameVue, entry: entryIngameVue,
output: { output: {
filename: '[name].js', filename: '[name].js',
path: resolve(__dirname, `${target}/dist_js`) path: resolve(outputPath, 'vue')
}, },
devtool: 'source-map', devtool: 'source-map',
optimization: { optimization: {
@@ -128,56 +157,27 @@ module.exports = (env, argv) => {
}, },
{ {
test: /\.(png|jpe?g|gif|webp)$/, test: /\.(png|jpe?g|gif|webp)$/,
use: [ use: ['file-loader']
{
loader: 'file-loader',
options: {
name: '../dist_misc/[name].[contenthash:8].[ext]'
}
}
]
}, },
{ {
test: /\.(svg)$/, test: /\.(svg)$/,
use: [ use: ['file-loader']
{
loader: 'file-loader',
options: {
name: '../dist_misc/[name].[contenthash:8].[ext]'
}
}
]
}, },
{ {
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)$/, test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)$/,
use: [ use: ['file-loader']
{
loader: 'file-loader',
options: {
name: '../dist_misc/[name].[contenthash:8].[ext]'
}
}
]
}, },
{ {
test: /\.(woff2?|eot|ttf|otf)$/i, test: /\.(woff2?|eot|ttf|otf)$/i,
use: [ use: ['file-loader']
{
loader: 'file-loader',
options: {
name: '../dist_misc/[name].[contenthash:8].[ext]'
}
}
]
}, },
] ]
}, },
plugins: [ plugins: [
new CleanTerminalPlugin(), new CleanTerminalPlugin(),
new VueLoaderPlugin(), new VueLoaderPlugin(),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin(),
filename: '../dist_css/[name].css' new webpack.ProgressPlugin(genBuildHook('vue')),
}),
//new BundleAnalyzerPlugin() //new BundleAnalyzerPlugin()
], ],
cache: { cache: {
@@ -185,7 +185,7 @@ module.exports = (env, argv) => {
}, },
}; };
const ingame = { const ingame = {
name: `ingame_${target}`, name: `ingame_${versionTarget}`,
resolve: { resolve: {
extensions: [".js", ".ts", ".tsx"], extensions: [".js", ".ts", ".tsx"],
alias: { alias: {
@@ -198,7 +198,7 @@ module.exports = (env, argv) => {
entry: entryIngame, entry: entryIngame,
output: { output: {
filename: '[name].js', filename: '[name].js',
path: resolve(__dirname, `${target}/dist_js`) path: resolve(outputPath, 'ts')
}, },
devtool: 'source-map', devtool: 'source-map',
optimization: { optimization: {
@@ -272,9 +272,8 @@ module.exports = (env, argv) => {
}, },
plugins: [ plugins: [
new CleanTerminalPlugin(), new CleanTerminalPlugin(),
new MiniCssExtractPlugin({ new MiniCssExtractPlugin(),
filename: '../dist_css/[name].css' new webpack.ProgressPlugin(genBuildHook('ts')),
}),
//new BundleAnalyzerPlugin() //new BundleAnalyzerPlugin()
], ],
cache: { cache: {
@@ -287,7 +286,7 @@ module.exports = (env, argv) => {
} }
}; };
const gateway = { const gateway = {
name: 'gateway', name: `gateway_${versionTarget}`,
resolve: { resolve: {
extensions: [".js", ".ts", ".tsx"], extensions: [".js", ".ts", ".tsx"],
alias: { alias: {
@@ -307,7 +306,7 @@ module.exports = (env, argv) => {
}, },
output: { output: {
filename: '[name].js', filename: '[name].js',
path: path.resolve(__dirname, 'dist_js'), path: resolve(outputPath, 'gateway')
}, },
devtool: 'source-map', devtool: 'source-map',
optimization: { optimization: {
@@ -379,9 +378,8 @@ module.exports = (env, argv) => {
}] }]
}, },
plugins: [ plugins: [
new MiniCssExtractPlugin({ new MiniCssExtractPlugin(),
filename: '../dist_css/[name].css' new webpack.ProgressPlugin(genBuildHook('gateway')),
}),
//new BundleAnalyzerPlugin() //new BundleAnalyzerPlugin()
], ],
cache: { cache: {
@@ -389,10 +387,22 @@ module.exports = (env, argv) => {
}, },
}; };
if (target == 'hwe') { if(env.WEBPACK_WATCH || !versionValue){
return [gateway, ingame_vue, ingame]; return [gateway, ingame_vue, ingame];
} }
else {
return [ingame_vue, ingame]; const buildConfList = [];
if (target == 'hwe' && !fs.existsSync(resolve(outputPath, `build_gateway.txt`))) {
buildConfList.push(gateway);
} }
if (!fs.existsSync(resolve(outputPath, `build_vue.txt`))) {
buildConfList.push(ingame_vue);
}
if (!fs.existsSync(resolve(outputPath, `build_ts.txt`))) {
buildConfList.push(ingame);
}
return buildConfList;
} }