✌️
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-console": 0,
|
||||||
"no-unused-vars": 0,
|
"no-unused-vars": 0,
|
||||||
"no-empty": 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 uglify = uglifyComposer(uglifyes, console);
|
||||||
|
|
||||||
const env = process.env.NODE_ENV;
|
const env = process.env.NODE_ENV || 'development';
|
||||||
const isProduction = env === 'production';
|
const isProduction = env === 'production';
|
||||||
const isDebug = !isProduction;
|
const isDebug = !isProduction;
|
||||||
|
|
||||||
|
@ -123,6 +123,7 @@ gulp.task('build:client:script', () =>
|
||||||
gulp.src(['./src/web/app/boot.js', './src/web/app/safe.js'])
|
gulp.src(['./src/web/app/boot.js', './src/web/app/safe.js'])
|
||||||
.pipe(replace('VERSION', JSON.stringify(version)))
|
.pipe(replace('VERSION', JSON.stringify(version)))
|
||||||
.pipe(replace('API', JSON.stringify(config.api_url)))
|
.pipe(replace('API', JSON.stringify(config.api_url)))
|
||||||
|
.pipe(replace('ENV', JSON.stringify(env)))
|
||||||
.pipe(isProduction ? uglify({
|
.pipe(isProduction ? uglify({
|
||||||
toplevel: true
|
toplevel: true
|
||||||
} as any) : gutil.noop())
|
} as any) : gutil.noop())
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
let lang = navigator.language.split('-')[0];
|
let lang = navigator.language.split('-')[0];
|
||||||
if (!/^(en|ja)$/.test(lang)) lang = 'en';
|
if (!/^(en|ja)$/.test(lang)) lang = 'en';
|
||||||
if (localStorage.getItem('lang')) lang = localStorage.getItem('lang');
|
if (localStorage.getItem('lang')) lang = localStorage.getItem('lang');
|
||||||
|
if (ENV != 'production') lang = 'ja';
|
||||||
|
|
||||||
// Detect the user agent
|
// Detect the user agent
|
||||||
const ua = navigator.userAgent.toLowerCase();
|
const ua = navigator.userAgent.toLowerCase();
|
||||||
|
@ -69,7 +70,8 @@
|
||||||
const isDebug = localStorage.getItem('debug') == 'true';
|
const isDebug = localStorage.getItem('debug') == 'true';
|
||||||
|
|
||||||
// Whether use raw version script
|
// 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
|
// Load an app script
|
||||||
// Note: 'async' make it possible to load the script asyncly.
|
// Note: 'async' make it possible to load the script asyncly.
|
||||||
|
|
|
@ -21,7 +21,7 @@ import locales from './locales';
|
||||||
const meta = require('./package.json');
|
const meta = require('./package.json');
|
||||||
const version = meta.version;
|
const version = meta.version;
|
||||||
|
|
||||||
const env = process.env.NODE_ENV;
|
const env = process.env.NODE_ENV || 'development';
|
||||||
const isProduction = env === 'production';
|
const isProduction = env === 'production';
|
||||||
|
|
||||||
//#region Replacer definitions
|
//#region Replacer definitions
|
||||||
|
@ -42,11 +42,12 @@ global['base64replacement'] = (_, key) => {
|
||||||
|
|
||||||
const langs = Object.keys(locales);
|
const langs = Object.keys(locales);
|
||||||
|
|
||||||
let entries = langs.map(l => [l, false]);
|
const entries = isProduction
|
||||||
entries = entries.concat(langs.map(l => [l, true]));
|
? langs.map(l => [l, false]).concat(langs.map(l => [l, true]))
|
||||||
|
: [['ja', false]];
|
||||||
|
|
||||||
module.exports = entries.map(x => {
|
module.exports = entries.map(x => {
|
||||||
const [lang, doMinify] = x;
|
const [lang, shouldOptimize] = x;
|
||||||
|
|
||||||
// Chunk name
|
// Chunk name
|
||||||
const name = lang;
|
const name = lang;
|
||||||
|
@ -65,7 +66,7 @@ module.exports = entries.map(x => {
|
||||||
|
|
||||||
const output = {
|
const output = {
|
||||||
path: __dirname + '/built/web/assets',
|
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);
|
const i18nReplacer = new I18nReplacer(lang as string);
|
||||||
|
@ -106,9 +107,7 @@ module.exports = entries.map(x => {
|
||||||
}),
|
}),
|
||||||
new webpack.DefinePlugin(_consts),
|
new webpack.DefinePlugin(_consts),
|
||||||
new webpack.DefinePlugin({
|
new webpack.DefinePlugin({
|
||||||
'process.env': {
|
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV)
|
||||||
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
new WebpackOnBuildPlugin(stats => {
|
new WebpackOnBuildPlugin(stats => {
|
||||||
fs.writeFileSync('./version.json', JSON.stringify({
|
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());
|
plugins.push(new webpack.optimize.ModuleConcatenationPlugin());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -243,10 +242,10 @@ module.exports = entries.map(x => {
|
||||||
cache: true,
|
cache: true,
|
||||||
devtool: false, //'source-map',
|
devtool: false, //'source-map',
|
||||||
optimization: {
|
optimization: {
|
||||||
minimize: isProduction && doMinify
|
minimize: isProduction && shouldOptimize
|
||||||
},
|
},
|
||||||
mode: isProduction
|
mode: isProduction
|
||||||
? doMinify
|
? shouldOptimize
|
||||||
? 'production'
|
? 'production'
|
||||||
: 'development'
|
: 'development'
|
||||||
: 'development'
|
: 'development'
|
||||||
|
|
Loading…
Reference in a new issue