From cada902e7a567575fd250db804e5f8bc05c0cd92 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 16 Mar 2018 05:45:28 +0900 Subject: [PATCH] :v: --- .eslintrc | 5 +++++ gulpfile.ts | 3 ++- src/web/app/boot.js | 4 +++- webpack.config.ts | 21 ++++++++++----------- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.eslintrc b/.eslintrc index 0d854fc2c..7a74d6ef9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -17,5 +17,10 @@ "no-console": 0, "no-unused-vars": 0, "no-empty": 0 + }, + "globals": { + "ENV": true, + "VERSION": true, + "API": true } } diff --git a/gulpfile.ts b/gulpfile.ts index df7f7e329..b70e5d8bc 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -28,7 +28,7 @@ import config from './src/conf'; const uglify = uglifyComposer(uglifyes, console); -const env = process.env.NODE_ENV; +const env = process.env.NODE_ENV || 'development'; const isProduction = env === 'production'; const isDebug = !isProduction; @@ -123,6 +123,7 @@ gulp.task('build:client:script', () => gulp.src(['./src/web/app/boot.js', './src/web/app/safe.js']) .pipe(replace('VERSION', JSON.stringify(version))) .pipe(replace('API', JSON.stringify(config.api_url))) + .pipe(replace('ENV', JSON.stringify(env))) .pipe(isProduction ? uglify({ toplevel: true } as any) : gutil.noop()) diff --git a/src/web/app/boot.js b/src/web/app/boot.js index 4b7d67942..2ee61745b 100644 --- a/src/web/app/boot.js +++ b/src/web/app/boot.js @@ -36,6 +36,7 @@ let lang = navigator.language.split('-')[0]; if (!/^(en|ja)$/.test(lang)) lang = 'en'; if (localStorage.getItem('lang')) lang = localStorage.getItem('lang'); + if (ENV != 'production') lang = 'ja'; // Detect the user agent const ua = navigator.userAgent.toLowerCase(); @@ -69,7 +70,8 @@ const isDebug = localStorage.getItem('debug') == 'true'; // Whether use raw version script - const raw = localStorage.getItem('useRawScript') == 'true' && isDebug; + const raw = (localStorage.getItem('useRawScript') == 'true' && isDebug) + || ENV != 'production'; // Load an app script // Note: 'async' make it possible to load the script asyncly. diff --git a/webpack.config.ts b/webpack.config.ts index 873251087..05ecd9677 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -21,7 +21,7 @@ import locales from './locales'; const meta = require('./package.json'); const version = meta.version; -const env = process.env.NODE_ENV; +const env = process.env.NODE_ENV || 'development'; const isProduction = env === 'production'; //#region Replacer definitions @@ -42,11 +42,12 @@ global['base64replacement'] = (_, key) => { const langs = Object.keys(locales); -let entries = langs.map(l => [l, false]); -entries = entries.concat(langs.map(l => [l, true])); +const entries = isProduction + ? langs.map(l => [l, false]).concat(langs.map(l => [l, true])) + : [['ja', false]]; module.exports = entries.map(x => { - const [lang, doMinify] = x; + const [lang, shouldOptimize] = x; // Chunk name const name = lang; @@ -65,7 +66,7 @@ module.exports = entries.map(x => { const output = { path: __dirname + '/built/web/assets', - filename: `[name].${version}.${lang}.${doMinify ? 'min' : 'raw'}.js` + filename: `[name].${version}.${lang}.${shouldOptimize ? 'min' : 'raw'}.js` }; const i18nReplacer = new I18nReplacer(lang as string); @@ -106,9 +107,7 @@ module.exports = entries.map(x => { }), new webpack.DefinePlugin(_consts), new webpack.DefinePlugin({ - 'process.env': { - NODE_ENV: JSON.stringify(process.env.NODE_ENV) - } + 'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV) }), new WebpackOnBuildPlugin(stats => { fs.writeFileSync('./version.json', JSON.stringify({ @@ -117,7 +116,7 @@ module.exports = entries.map(x => { }) ]; - if (doMinify) { + if (shouldOptimize) { plugins.push(new webpack.optimize.ModuleConcatenationPlugin()); } @@ -243,10 +242,10 @@ module.exports = entries.map(x => { cache: true, devtool: false, //'source-map', optimization: { - minimize: isProduction && doMinify + minimize: isProduction && shouldOptimize }, mode: isProduction - ? doMinify + ? shouldOptimize ? 'production' : 'development' : 'development'