0
0
This commit is contained in:
syuilo 2018-03-15 05:26:24 +09:00
parent c930e9f145
commit 94b5729c84
7 changed files with 74 additions and 121 deletions

View File

@ -13,8 +13,8 @@
"start": "node ./built", "start": "node ./built",
"debug": "DEBUG=misskey:* node ./built", "debug": "DEBUG=misskey:* node ./built",
"swagger": "node ./swagger.js", "swagger": "node ./swagger.js",
"build": "./node_modules/.bin/webpack --config ./webpack/webpack.config.ts && gulp build", "build": "./node_modules/.bin/webpack && gulp build",
"webpack": "./node_modules/.bin/webpack --config ./webpack/webpack.config.ts", "webpack": "./node_modules/.bin/webpack",
"gulp": "gulp build", "gulp": "gulp build",
"rebuild": "gulp rebuild", "rebuild": "gulp rebuild",
"clean": "gulp clean", "clean": "gulp clean",

View File

@ -3,18 +3,26 @@
*/ */
import * as fs from 'fs'; import * as fs from 'fs';
import * as webpack from 'webpack';
import chalk from 'chalk';
import jsonImporter from 'node-sass-json-importer'; import jsonImporter from 'node-sass-json-importer';
const minify = require('html-minifier').minify; const minify = require('html-minifier').minify;
import I18nReplacer from '../src/common/build/i18n'; const WebpackOnBuildPlugin = require('on-build-webpack');
import { pattern as faPattern, replacement as faReplacement } from '../src/common/build/fa'; const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const constants = require('../src/const.json'); const ProgressBarPlugin = require('progress-bar-webpack-plugin');
import I18nReplacer from './src/common/build/i18n';
import { pattern as faPattern, replacement as faReplacement } from './src/common/build/fa';
const constants = require('./src/const.json');
import config from './src/conf';
import { licenseHtml } from './src/common/build/license';
import plugins from './plugins'; import langs from './locales';
const meta = require('./package.json');
import langs from '../locales';
const meta = require('../package.json');
const version = meta.version; const version = meta.version;
const env = process.env.NODE_ENV;
const isProduction = env === 'production';
global['faReplacement'] = faReplacement; global['faReplacement'] = faReplacement;
global['collapseSpacesReplacement'] = html => { global['collapseSpacesReplacement'] = html => {
@ -26,7 +34,7 @@ global['collapseSpacesReplacement'] = html => {
}; };
global['base64replacement'] = (_, key) => { global['base64replacement'] = (_, key) => {
return fs.readFileSync(__dirname + '/../src/web/' + key, 'base64'); return fs.readFileSync(__dirname + '/src/web/' + key, 'base64');
}; };
module.exports = Object.keys(langs).map(lang => { module.exports = Object.keys(langs).map(lang => {
@ -46,13 +54,64 @@ module.exports = Object.keys(langs).map(lang => {
}; };
const output = { const output = {
path: __dirname + '/../built/web/assets', path: __dirname + '/built/web/assets',
filename: `[name].${version}.${lang}.js` filename: `[name].${version}.${lang}.js`
}; };
const i18nReplacer = new I18nReplacer(lang); const i18nReplacer = new I18nReplacer(lang);
global['i18nReplacement'] = i18nReplacer.replacement; global['i18nReplacement'] = i18nReplacer.replacement;
//#region Define consts
const consts = {
_RECAPTCHA_SITEKEY_: config.recaptcha.site_key,
_SW_PUBLICKEY_: config.sw ? config.sw.public_key : null,
_THEME_COLOR_: constants.themeColor,
_COPYRIGHT_: constants.copyright,
_VERSION_: version,
_STATUS_URL_: config.status_url,
_STATS_URL_: config.stats_url,
_DOCS_URL_: config.docs_url,
_API_URL_: config.api_url,
_DEV_URL_: config.dev_url,
_CH_URL_: config.ch_url,
_LANG_: lang,
_HOST_: config.host,
_URL_: config.url,
_LICENSE_: licenseHtml,
_GOOGLE_MAPS_API_KEY_: config.google_maps_api_key
};
const _consts = {};
Object.keys(consts).forEach(key => {
_consts[key] = JSON.stringify(consts[key]);
});
//#endregion
const plugins = [
new HardSourceWebpackPlugin(),
new ProgressBarPlugin({
format: chalk` {cyan.bold yes we can} {bold [}:bar{bold ]} {green.bold :percent} {gray (:current/:total)} :elapseds`,
clear: false
}),
new webpack.DefinePlugin(_consts),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
}),
new WebpackOnBuildPlugin(stats => {
fs.writeFileSync('./version.json', JSON.stringify({
version
}), 'utf-8');
})
];
if (isProduction) {
plugins.push(new webpack.optimize.ModuleConcatenationPlugin());
plugins.push(minify());
}
return { return {
name, name,
entry, entry,
@ -159,19 +218,20 @@ module.exports = Object.keys(langs).map(lang => {
}] }]
}] }]
}, },
plugins: plugins(version, lang), plugins,
output, output,
resolve: { resolve: {
extensions: [ extensions: [
'.js', '.ts', '.json' '.js', '.ts', '.json'
], ],
alias: { alias: {
'const.styl': __dirname + '/../src/web/const.styl' 'const.styl': __dirname + '/src/web/const.styl'
} }
}, },
resolveLoader: { resolveLoader: {
modules: ['node_modules', './webpack/loaders'] modules: ['node_modules', './webpack/loaders']
}, },
cache: true cache: true,
devtool: 'source-map'
}; };
}); });

View File

@ -1,19 +0,0 @@
import * as fs from 'fs';
const minify = require('html-minifier').minify;
export default () => ({
enforce: 'pre',
test: /\.vue$/,
exclude: /node_modules/,
loader: 'string-replace-loader',
query: {
search: /^<template>([\s\S]+?)\r?\n<\/template>/,
replace: html => {
return minify(html, {
collapseWhitespace: true,
collapseInlineTagWhitespace: true,
keepClosingSlash: true
});
}
}
});

View File

@ -1,41 +0,0 @@
/**
* Constant Replacer
*/
import * as webpack from 'webpack';
const meta = require('../../package.json');
const version = meta.version;
const constants = require('../../src/const.json');
import config from '../../src/conf';
import { licenseHtml } from '../../src/common/build/license';
export default lang => {
const consts = {
_RECAPTCHA_SITEKEY_: config.recaptcha.site_key,
_SW_PUBLICKEY_: config.sw ? config.sw.public_key : null,
_THEME_COLOR_: constants.themeColor,
_COPYRIGHT_: constants.copyright,
_VERSION_: version,
_STATUS_URL_: config.status_url,
_STATS_URL_: config.stats_url,
_DOCS_URL_: config.docs_url,
_API_URL_: config.api_url,
_DEV_URL_: config.dev_url,
_CH_URL_: config.ch_url,
_LANG_: lang,
_HOST_: config.host,
_URL_: config.url,
_LICENSE_: licenseHtml,
_GOOGLE_MAPS_API_KEY_: config.google_maps_api_key
};
const _consts = {};
Object.keys(consts).forEach(key => {
_consts[key] = JSON.stringify(consts[key]);
});
return new webpack.DefinePlugin(_consts);
};

View File

@ -1,3 +0,0 @@
import * as webpack from 'webpack';
export default () => new webpack.optimize.ModuleConcatenationPlugin();

View File

@ -1,41 +0,0 @@
import * as fs from 'fs';
import * as webpack from 'webpack';
const WebpackOnBuildPlugin = require('on-build-webpack');
const HardSourceWebpackPlugin = require('hard-source-webpack-plugin');
const ProgressBarPlugin = require('progress-bar-webpack-plugin');
import chalk from 'chalk';
import consts from './consts';
import hoist from './hoist';
import minify from './minify';
const env = process.env.NODE_ENV;
const isProduction = env === 'production';
export default (version, lang) => {
const plugins = [
new HardSourceWebpackPlugin(),
new ProgressBarPlugin({
format: chalk` {cyan.bold yes we can} {bold [}:bar{bold ]} {green.bold :percent} {gray (:current/:total)} :elapseds`,
clear: false
}),
consts(lang),
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: JSON.stringify(process.env.NODE_ENV)
}
}),
new WebpackOnBuildPlugin(stats => {
fs.writeFileSync('./version.json', JSON.stringify({
version
}), 'utf-8');
})
];
if (isProduction) {
plugins.push(hoist());
plugins.push(minify());
}
return plugins;
};

View File

@ -1,3 +0,0 @@
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
export default () => new UglifyJsPlugin();