Refactoring

This commit is contained in:
syuilo 2017-03-23 00:41:11 +09:00
parent ef8b09a690
commit 8a369c994b
3 changed files with 86 additions and 100 deletions

View file

@ -20,7 +20,7 @@ import imagemin = require('gulp-imagemin');
import * as rename from 'gulp-rename'; import * as rename from 'gulp-rename';
import * as mocha from 'gulp-mocha'; import * as mocha from 'gulp-mocha';
import * as replace from 'gulp-replace'; import * as replace from 'gulp-replace';
import getVersion from './src/version'; import version from './src/version';
const env = process.env.NODE_ENV; const env = process.env.NODE_ENV;
const isProduction = env === 'production'; const isProduction = env === 'production';
@ -129,21 +129,16 @@ gulp.task('build:client', [
'copy:client' 'copy:client'
]); ]);
gulp.task('build:client:scripts', done => { gulp.task('build:client:scripts', () =>
getVersion.then(version => { es.merge(
require('./webpack.config').then(webpackOptions => { webpack(require('./webpack.config'), require('webpack'))
es.merge( .pipe(gulp.dest('./built/web/assets/')) as any,
webpack(webpackOptions, require('webpack')) gulp.src('./src/web/app/client/script.js')
.pipe(gulp.dest('./built/web/assets/')) as any, .pipe(replace('VERSION', JSON.stringify(version)))
gulp.src('./src/web/app/client/script.js') //.pipe(isProduction ? uglify() : gutil.noop())
.pipe(replace('VERSION', JSON.stringify(version))) .pipe(gulp.dest('./built/web/assets/client/')) as any
//.pipe(isProduction ? uglify() : gutil.noop()) )
.pipe(gulp.dest('./built/web/assets/client/')) as any );
);
done();
});
});
});
gulp.task('build:client:styles', () => gulp.task('build:client:styles', () =>
gulp.src('./src/web/app/init.css') gulp.src('./src/web/app/init.css')
@ -172,16 +167,13 @@ gulp.task('build:client:pug', [
'copy:client', 'copy:client',
'build:client:scripts', 'build:client:scripts',
'build:client:styles' 'build:client:styles'
], done => { ], () =>
getVersion.then(version => { gulp.src('./src/web/app/*/view.pug')
gulp.src('./src/web/app/*/view.pug') .pipe(pug({
.pipe(pug({ locals: {
locals: { version: version,
version: version, themeColor: constants.themeColor
themeColor: constants.themeColor }
} }))
})) .pipe(gulp.dest('./built/web/app/'))
.pipe(gulp.dest('./built/web/app/')); );
done();
});
});

View file

@ -1,9 +1,7 @@
const getVersion = new Promise<string>(async resolve => { /**
const = require('../package.json'); * Version
*/
const version = .version; const meta = require('../package.json');
resolve(version); export default meta.version as string;
});
export default getVersion;

View file

@ -4,77 +4,73 @@
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 getVersion from './src/version'; import version from './src/version';
const constants = require('./src/const.json'); const constants = require('./src/const.json');
const env = process.env.NODE_ENV; const env = process.env.NODE_ENV;
const isProduction = env === 'production'; const isProduction = env === 'production';
module.exports = new Promise(async resolve => { const pack: webpack.Configuration = {
const version = await getVersion.then(); entry: {
'desktop': './src/web/app/desktop/script.js',
const pack: webpack.Configuration = { 'mobile': './src/web/app/mobile/script.js',
entry: { 'dev': './src/web/app/dev/script.js',
'desktop': './src/web/app/desktop/script.js', 'auth': './src/web/app/auth/script.js'
'mobile': './src/web/app/mobile/script.js', },
'dev': './src/web/app/dev/script.js', module: {
'auth': './src/web/app/auth/script.js' rules: [
}, {
module: { enforce: 'pre',
rules: [ test: /\.tag$/,
{ exclude: /node_modules/,
enforce: 'pre', loader: StringReplacePlugin.replace({
test: /\.tag$/, replacements: [
exclude: /node_modules/, { pattern: /\$theme\-color\-foreground/g, replacement: () => constants.themeColorForeground },
loader: StringReplacePlugin.replace({ { pattern: /\$theme\-color/g, replacement: () => constants.themeColor },
replacements: [ ]
{ pattern: /\$theme\-color\-foreground/g, replacement: () => constants.themeColorForeground }, })
{ pattern: /\$theme\-color/g, replacement: () => constants.themeColor }, },
] {
}) test: /\.tag$/,
}, exclude: /node_modules/,
{ loader: 'riot-tag-loader',
test: /\.tag$/, query: {
exclude: /node_modules/, hot: false,
loader: 'riot-tag-loader', style: 'stylus',
query: { expr: false,
hot: false, compact: true,
style: 'stylus', parserOptions: {
expr: false, style: {
compact: true, compress: true
parserOptions: {
style: {
compress: true
}
} }
} }
},
{
test: /\.styl$/,
exclude: /node_modules/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'stylus-loader' }
]
} }
] },
}, {
plugins: [ test: /\.styl$/,
new webpack.DefinePlugin({ exclude: /node_modules/,
VERSION: JSON.stringify(version), use: [
THEME_COLOR: JSON.stringify(constants.themeColor) { loader: 'style-loader' },
}), { loader: 'css-loader' },
new StringReplacePlugin() { loader: 'stylus-loader' }
], ]
output: { }
filename: `[name]/script.${version}.js` ]
} },
}; plugins: [
new webpack.DefinePlugin({
if (isProduction) { VERSION: JSON.stringify(version),
//pack.plugins.push(new webpack.optimize.UglifyJsPlugin()); THEME_COLOR: JSON.stringify(constants.themeColor)
}),
new StringReplacePlugin()
],
output: {
filename: `[name]/script.${version}.js`
} }
};
resolve(pack); if (isProduction) {
}); //pack.plugins.push(new webpack.optimize.UglifyJsPlugin());
}
module.exports = pack;