From 45cb5cec04e4e6eb968bc4d1b54e8daf54b404ae Mon Sep 17 00:00:00 2001 From: syuilo Date: Thu, 15 Mar 2018 12:56:50 +0900 Subject: [PATCH] #1239 --- package.json | 1 - src/web/app/boot.js | 6 ++++- .../app/desktop/views/components/settings.vue | 11 ++++++-- src/web/assets/404.js | 2 ++ webpack.config.ts | 27 ++++++++++++------- 5 files changed, 34 insertions(+), 13 deletions(-) diff --git a/package.json b/package.json index 27af69a4c..c75e0e111 100644 --- a/package.json +++ b/package.json @@ -184,7 +184,6 @@ "typescript": "2.7.2", "typescript-eslint-parser": "14.0.0", "uglify-es": "3.3.9", - "uglifyjs-webpack-plugin": "1.2.3", "url-loader": "1.0.1", "uuid": "3.2.1", "v-animate-css": "0.0.2", diff --git a/src/web/app/boot.js b/src/web/app/boot.js index 2d2e27df3..41685aadc 100644 --- a/src/web/app/boot.js +++ b/src/web/app/boot.js @@ -62,13 +62,17 @@ app = isMobile ? 'mobile' : 'desktop'; } + // Script version const ver = localStorage.getItem('v') || VERSION; + // Whether use raw version script + const raw = localStorage.getItem('useRawScript') == 'true'; + // Load an app script // Note: 'async' make it possible to load the script asyncly. // 'defer' make it possible to run the script when the dom loaded. const script = document.createElement('script'); - script.setAttribute('src', `/assets/${app}.${ver}.${lang}.js`); + script.setAttribute('src', `/assets/${app}.${ver}.${lang}.${raw ? 'raw' : 'min'}.js`); script.setAttribute('async', 'true'); script.setAttribute('defer', 'true'); head.appendChild(script); diff --git a/src/web/app/desktop/views/components/settings.vue b/src/web/app/desktop/views/components/settings.vue index 39d9be01d..5627da1cc 100644 --- a/src/web/app/desktop/views/components/settings.vue +++ b/src/web/app/desktop/views/components/settings.vue @@ -160,10 +160,13 @@

高度な設定

- この設定はアカウントに保存されません。 + この設定はブラウザに記憶されます。 - この設定はアカウントに保存されません。実験的機能を有効にするとMisskeyの動作が不安定になる可能性があります。 + 実験的機能を有効にするとMisskeyの動作が不安定になる可能性があります。この設定はブラウザに記憶されます。 + + + 圧縮されていない「生の」スクリプトを使用します。サイズが大きいため、読み込みに時間がかかる場合があります。この設定はブラウザに記憶されます。
@@ -214,6 +217,7 @@ export default Vue.extend({ lang: localStorage.getItem('lang') || '', preventUpdate: localStorage.getItem('preventUpdate') == 'true', debug: localStorage.getItem('debug') == 'true', + useRawScript: localStorage.getItem('useRawScript') == 'true', enableExperimental: localStorage.getItem('enableExperimental') == 'true' }; }, @@ -236,6 +240,9 @@ export default Vue.extend({ debug() { localStorage.setItem('debug', this.debug ? 'true' : 'false'); }, + useRawScript() { + localStorage.setItem('useRawScript', this.useRawScript ? 'true' : 'false'); + }, enableExperimental() { localStorage.setItem('enableExperimental', this.enableExperimental ? 'true' : 'false'); } diff --git a/src/web/assets/404.js b/src/web/assets/404.js index 285704d11..f897f0db6 100644 --- a/src/web/assets/404.js +++ b/src/web/assets/404.js @@ -13,6 +13,8 @@ if (yn) { console.error(e); } + localStorage.removeItem('v'); + location.reload(true); } else { alert('問題が解決しない場合はサーバー管理者までお問い合せください。'); diff --git a/webpack.config.ts b/webpack.config.ts index e3684f9d8..0fb63499c 100644 --- a/webpack.config.ts +++ b/webpack.config.ts @@ -6,7 +6,7 @@ import * as fs from 'fs'; import * as webpack from 'webpack'; import chalk from 'chalk'; import jsonImporter from 'node-sass-json-importer'; -const minify = require('html-minifier').minify; +const minifyHtml = require('html-minifier').minify; const WebpackOnBuildPlugin = require('on-build-webpack'); const HardSourceWebpackPlugin = require('hard-source-webpack-plugin'); const ProgressBarPlugin = require('progress-bar-webpack-plugin'); @@ -17,7 +17,7 @@ const constants = require('./src/const.json'); import config from './src/conf'; import { licenseHtml } from './src/common/build/license'; -import langs from './locales'; +import locales from './locales'; const meta = require('./package.json'); const version = meta.version; @@ -28,7 +28,7 @@ const isProduction = env === 'production'; global['faReplacement'] = faReplacement; global['collapseSpacesReplacement'] = html => { - return minify(html, { + return minifyHtml(html, { collapseWhitespace: true, collapseInlineTagWhitespace: true, keepClosingSlash: true @@ -40,7 +40,14 @@ global['base64replacement'] = (_, key) => { }; //#endregion -module.exports = Object.keys(langs).map(lang => { +const langs = Object.keys(locales); + +let entries = langs.map(l => [l, false]); +entries = entries.concat(langs.map(l => [l, true])); + +module.exports = entries.map(x => { + const [lang, doMinify] = x; + // Chunk name const name = lang; @@ -58,10 +65,10 @@ module.exports = Object.keys(langs).map(lang => { const output = { path: __dirname + '/built/web/assets', - filename: `[name].${version}.${lang}.js` + filename: `[name].${version}.${lang}.${doMinify ? 'min' : 'raw'}.js` }; - const i18nReplacer = new I18nReplacer(lang); + const i18nReplacer = new I18nReplacer(lang as string); global['i18nReplacement'] = i18nReplacer.replacement; //#region Define consts @@ -110,9 +117,8 @@ module.exports = Object.keys(langs).map(lang => { }) ]; - if (isProduction) { + if (doMinify) { plugins.push(new webpack.optimize.ModuleConcatenationPlugin()); - plugins.push(minify()); } return { @@ -235,6 +241,9 @@ module.exports = Object.keys(langs).map(lang => { modules: ['node_modules', './webpack/loaders'] }, cache: true, - devtool: 'source-map' + devtool: 'source-map', + optimization: { + minimize: doMinify + } }; });