✌️
This commit is contained in:
parent
a94c0460ee
commit
cada902e7a
4 changed files with 20 additions and 13 deletions
|
@ -17,5 +17,10 @@
|
|||
"no-console": 0,
|
||||
"no-unused-vars": 0,
|
||||
"no-empty": 0
|
||||
},
|
||||
"globals": {
|
||||
"ENV": true,
|
||||
"VERSION": true,
|
||||
"API": true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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())
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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'
|
||||
|
|
Loading…
Reference in a new issue