wip #313
This commit is contained in:
parent
4e387cf7d0
commit
abb8e021ba
25
gulpfile.ts
25
gulpfile.ts
@ -2,6 +2,7 @@
|
|||||||
* Gulp tasks
|
* Gulp tasks
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import * as childProcess from 'child_process';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as Path from 'path';
|
import * as Path from 'path';
|
||||||
import * as gulp from 'gulp';
|
import * as gulp from 'gulp';
|
||||||
@ -10,7 +11,6 @@ import * as ts from 'gulp-typescript';
|
|||||||
import tslint from 'gulp-tslint';
|
import tslint from 'gulp-tslint';
|
||||||
import * as glob from 'glob';
|
import * as glob from 'glob';
|
||||||
import * as es from 'event-stream';
|
import * as es from 'event-stream';
|
||||||
import * as webpack from 'webpack-stream';
|
|
||||||
import cssnano = require('gulp-cssnano');
|
import cssnano = require('gulp-cssnano');
|
||||||
//import * as uglify from 'gulp-uglify';
|
//import * as uglify from 'gulp-uglify';
|
||||||
import pug = require('gulp-pug');
|
import pug = require('gulp-pug');
|
||||||
@ -123,21 +123,25 @@ gulp.task('cleanall', ['clean'], cb =>
|
|||||||
gulp.task('default', ['build']);
|
gulp.task('default', ['build']);
|
||||||
|
|
||||||
gulp.task('build:client', [
|
gulp.task('build:client', [
|
||||||
'build:ts', 'build:js',
|
'build:ts',
|
||||||
'build:client:scripts',
|
'build:js',
|
||||||
|
'webpack',
|
||||||
|
'build:client:script',
|
||||||
'build:client:pug',
|
'build:client:pug',
|
||||||
'copy:client'
|
'copy:client'
|
||||||
]);
|
]);
|
||||||
|
|
||||||
gulp.task('build:client:scripts', () =>
|
gulp.task('webpack', done => {
|
||||||
es.merge(
|
const output = childProcess.execSync(Path.join('.', 'node_modules', '.bin', 'webpack') + ' --config webpack.config.ts', );
|
||||||
webpack(require('./webpack.config'), require('webpack'))
|
console.log(output.toString());
|
||||||
.pipe(gulp.dest('./built/web/assets/')) as any,
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('build:client:script', () =>
|
||||||
gulp.src('./src/web/app/client/script.js')
|
gulp.src('./src/web/app/client/script.js')
|
||||||
.pipe(replace('VERSION', JSON.stringify(version)))
|
.pipe(replace('VERSION', JSON.stringify(version)))
|
||||||
//.pipe(isProduction ? uglify() : gutil.noop())
|
//.pipe(isProduction ? uglify() : gutil.noop())
|
||||||
.pipe(gulp.dest('./built/web/assets/client/')) as any
|
.pipe(gulp.dest('./built/web/assets/client/')) as any
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
gulp.task('build:client:styles', () =>
|
gulp.task('build:client:styles', () =>
|
||||||
@ -149,7 +153,8 @@ gulp.task('build:client:styles', () =>
|
|||||||
);
|
);
|
||||||
|
|
||||||
gulp.task('copy:client', [
|
gulp.task('copy:client', [
|
||||||
'build:client:scripts'
|
'build:client:script',
|
||||||
|
'webpack'
|
||||||
], () =>
|
], () =>
|
||||||
gulp.src([
|
gulp.src([
|
||||||
'./assets/**/*',
|
'./assets/**/*',
|
||||||
@ -165,7 +170,7 @@ gulp.task('copy:client', [
|
|||||||
|
|
||||||
gulp.task('build:client:pug', [
|
gulp.task('build:client:pug', [
|
||||||
'copy:client',
|
'copy:client',
|
||||||
'build:client:scripts',
|
'build:client:script',
|
||||||
'build:client:styles'
|
'build:client:styles'
|
||||||
], () =>
|
], () =>
|
||||||
gulp.src('./src/web/app/*/view.pug')
|
gulp.src('./src/web/app/*/view.pug')
|
||||||
|
3
locales/en.json
Normal file
3
locales/en.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"home": "Home"
|
||||||
|
}
|
3
locales/ja.json
Normal file
3
locales/ja.json
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"home": "ホーム"
|
||||||
|
}
|
@ -144,7 +144,6 @@
|
|||||||
"uuid": "3.0.1",
|
"uuid": "3.0.1",
|
||||||
"vhost": "3.0.2",
|
"vhost": "3.0.2",
|
||||||
"webpack": "2.3.1",
|
"webpack": "2.3.1",
|
||||||
"webpack-stream": "3.2.0",
|
|
||||||
"websocket": "1.0.24",
|
"websocket": "1.0.24",
|
||||||
"whatwg-fetch": "2.0.3",
|
"whatwg-fetch": "2.0.3",
|
||||||
"xml2json": "0.11.0"
|
"xml2json": "0.11.0"
|
||||||
|
@ -4,6 +4,10 @@
|
|||||||
(() => {
|
(() => {
|
||||||
const head = document.getElementsByTagName('head')[0];
|
const head = document.getElementsByTagName('head')[0];
|
||||||
|
|
||||||
|
// Detect user language
|
||||||
|
let lang = (navigator.languages && navigator.languages[0]) || navigator.language;
|
||||||
|
if (!/en|en\-US|ja/.test(lang)) lang = 'en';
|
||||||
|
|
||||||
// Detect user agent
|
// Detect user agent
|
||||||
const ua = navigator.userAgent.toLowerCase();
|
const ua = navigator.userAgent.toLowerCase();
|
||||||
const isMobile = /mobile|iphone|ipad|android/.test(ua);
|
const isMobile = /mobile|iphone|ipad|android/.test(ua);
|
||||||
@ -15,7 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
function mountDesktop() {
|
function mountDesktop() {
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
script.setAttribute('src', `/assets/desktop/script.${VERSION}.js`);
|
script.setAttribute('src', `/assets/desktop/script.${VERSION}.${lang}.js`);
|
||||||
script.setAttribute('async', 'true');
|
script.setAttribute('async', 'true');
|
||||||
script.setAttribute('defer', 'true');
|
script.setAttribute('defer', 'true');
|
||||||
head.appendChild(script);
|
head.appendChild(script);
|
||||||
@ -31,7 +35,7 @@
|
|||||||
head.appendChild(meta);
|
head.appendChild(meta);
|
||||||
|
|
||||||
const script = document.createElement('script');
|
const script = document.createElement('script');
|
||||||
script.setAttribute('src', `/assets/mobile/script.${VERSION}.js`);
|
script.setAttribute('src', `/assets/mobile/script.${VERSION}.${lang}.js`);
|
||||||
script.setAttribute('async', 'true');
|
script.setAttribute('async', 'true');
|
||||||
script.setAttribute('defer', 'true');
|
script.setAttribute('defer', 'true');
|
||||||
head.appendChild(script);
|
head.appendChild(script);
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<li class="home { active: page == 'home' }">
|
<li class="home { active: page == 'home' }">
|
||||||
<a href={ CONFIG.url }>
|
<a href={ CONFIG.url }>
|
||||||
<i class="fa fa-home"></i>
|
<i class="fa fa-home"></i>
|
||||||
<p>ホーム</p>
|
<p>'i18n:home'</p>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
<li class="messaging">
|
<li class="messaging">
|
||||||
|
@ -4,13 +4,22 @@
|
|||||||
|
|
||||||
import * as webpack from 'webpack';
|
import * as webpack from 'webpack';
|
||||||
const StringReplacePlugin = require('string-replace-webpack-plugin');
|
const StringReplacePlugin = require('string-replace-webpack-plugin');
|
||||||
|
|
||||||
import version from './src/version';
|
import version from './src/version';
|
||||||
const constants = require('./src/const.json');
|
const constants = require('./src/const.json');
|
||||||
|
|
||||||
|
const languages = {
|
||||||
|
'en': require('./locales/en.json'),
|
||||||
|
'en-US': require('./locales/en.json'),
|
||||||
|
'ja': require('./locales/ja.json')
|
||||||
|
};
|
||||||
|
|
||||||
const env = process.env.NODE_ENV;
|
const env = process.env.NODE_ENV;
|
||||||
const isProduction = env === 'production';
|
const isProduction = env === 'production';
|
||||||
|
|
||||||
const pack: webpack.Configuration = {
|
module.exports = (Object as any).entries(languages).map(([lang, locale]) => {
|
||||||
|
const pack /*: webpack.Configuration ← fuck wrong type definition!!! */ = {
|
||||||
|
name: lang,
|
||||||
entry: {
|
entry: {
|
||||||
'desktop': './src/web/app/desktop/script.js',
|
'desktop': './src/web/app/desktop/script.js',
|
||||||
'mobile': './src/web/app/mobile/script.js',
|
'mobile': './src/web/app/mobile/script.js',
|
||||||
@ -19,6 +28,16 @@ const pack: webpack.Configuration = {
|
|||||||
},
|
},
|
||||||
module: {
|
module: {
|
||||||
rules: [
|
rules: [
|
||||||
|
{
|
||||||
|
enforce: 'pre',
|
||||||
|
test: /\.*$/,
|
||||||
|
exclude: /node_modules/,
|
||||||
|
loader: StringReplacePlugin.replace({
|
||||||
|
replacements: [
|
||||||
|
{ pattern: /'i18n:(.+?)'/g, replacement: (_, text) => locale[text] }
|
||||||
|
]
|
||||||
|
})
|
||||||
|
},
|
||||||
{
|
{
|
||||||
enforce: 'pre',
|
enforce: 'pre',
|
||||||
test: /\.tag$/,
|
test: /\.tag$/,
|
||||||
@ -65,7 +84,8 @@ const pack: webpack.Configuration = {
|
|||||||
new StringReplacePlugin()
|
new StringReplacePlugin()
|
||||||
],
|
],
|
||||||
output: {
|
output: {
|
||||||
filename: `[name]/script.${version}.js`
|
path: __dirname + '/built/web/assets',
|
||||||
|
filename: `[name]/script.${version}.${lang}.js`
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -73,4 +93,5 @@ if (isProduction) {
|
|||||||
//pack.plugins.push(new webpack.optimize.UglifyJsPlugin());
|
//pack.plugins.push(new webpack.optimize.UglifyJsPlugin());
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = pack;
|
return pack;
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user