summaryrefslogtreecommitdiff
path: root/webpack
diff options
context:
space:
mode:
authorこぴなたみぽ <Syuilotan@yahoo.co.jp>2017-11-06 19:11:23 +0900
committerGitHub <noreply@github.com>2017-11-06 19:11:23 +0900
commitcb7e70dee3aa47807d33757d4ecd07e2793540d0 (patch)
treec6795a6c0aa200195748c364d4ab990c6a160150 /webpack
parentchore(package): update @types/rimraf to version 2.0.2 (diff)
parentMerge pull request #871 from syuilo/greenkeeper/@types/elasticsearch-5.0.17 (diff)
downloadmisskey-cb7e70dee3aa47807d33757d4ecd07e2793540d0.tar.gz
misskey-cb7e70dee3aa47807d33757d4ecd07e2793540d0.tar.bz2
misskey-cb7e70dee3aa47807d33757d4ecd07e2793540d0.zip
Merge branch 'master' into greenkeeper/@types/rimraf-2.0.2
Diffstat (limited to 'webpack')
-rw-r--r--webpack/module/rules/base64.ts19
-rw-r--r--webpack/module/rules/i18n.ts70
-rw-r--r--webpack/module/rules/index.ts6
-rw-r--r--webpack/module/rules/typescript.ts8
-rw-r--r--webpack/plugins/const.ts3
-rw-r--r--webpack/plugins/index.ts12
-rw-r--r--webpack/plugins/minify.ts4
-rw-r--r--webpack/webpack.config.ts3
8 files changed, 84 insertions, 41 deletions
diff --git a/webpack/module/rules/base64.ts b/webpack/module/rules/base64.ts
new file mode 100644
index 0000000000..529816bd20
--- /dev/null
+++ b/webpack/module/rules/base64.ts
@@ -0,0 +1,19 @@
+/**
+ * Replace base64 symbols
+ */
+
+import * as fs from 'fs';
+const StringReplacePlugin = require('string-replace-webpack-plugin');
+
+export default () => ({
+ enforce: 'pre',
+ test: /\.(tag|js)$/,
+ exclude: /node_modules/,
+ loader: StringReplacePlugin.replace({
+ replacements: [{
+ pattern: /%base64:(.+?)%/g, replacement: (_, key) => {
+ return fs.readFileSync(__dirname + '/../../../src/web/' + key, 'base64');
+ }
+ }]
+ })
+});
diff --git a/webpack/module/rules/i18n.ts b/webpack/module/rules/i18n.ts
index 3023253cab..9a4acde686 100644
--- a/webpack/module/rules/i18n.ts
+++ b/webpack/module/rules/i18n.ts
@@ -4,34 +4,46 @@
const StringReplacePlugin = require('string-replace-webpack-plugin');
-export default (lang, locale) => ({
- enforce: 'pre',
- test: /\.(tag|js)$/,
- exclude: /node_modules/,
- loader: StringReplacePlugin.replace({
- replacements: [
- {
+export default (lang, locale) => {
+ function get(key: string) {
+ let text = locale;
+
+ // Check the key existance
+ const error = key.split('.').some(k => {
+ if (text.hasOwnProperty(k)) {
+ text = text[k];
+ return false;
+ } else {
+ return true;
+ }
+ });
+
+ if (error) {
+ console.warn(`key '${key}' not found in '${lang}'`);
+ return key; // Fallback
+ } else {
+ return text;
+ }
+ }
+
+ return {
+ enforce: 'pre',
+ test: /\.(tag|js)$/,
+ exclude: /node_modules/,
+ loader: StringReplacePlugin.replace({
+ replacements: [{
+ pattern: /"%i18n:(.+?)%"/g, replacement: (_, key) => {
+ return '"' + get(key).replace(/"/g, '\\"') + '"';
+ }
+ }, {
+ pattern: /'%i18n:(.+?)%'/g, replacement: (_, key) => {
+ return '\'' + get(key).replace(/'/g, '\\\'') + '\'';
+ }
+ }, {
pattern: /%i18n:(.+?)%/g, replacement: (_, key) => {
- let text = locale;
-
- // Check the key existance
- const error = key.split('.').some(k => {
- if (text.hasOwnProperty(k)) {
- text = text[k];
- return false;
- } else {
- return true;
- }
- });
-
- if (error) {
- console.warn(`key '${key}' not found in '${lang}'`);
- return key; // Fallback
- } else {
- return text.replace(/'/g, '\\\'').replace(/"/g, '\\"');
- }
+ return get(key);
}
- }
- ]
- })
-});
+ }]
+ })
+ };
+};
diff --git a/webpack/module/rules/index.ts b/webpack/module/rules/index.ts
index 2308f4e535..9c1262b3d6 100644
--- a/webpack/module/rules/index.ts
+++ b/webpack/module/rules/index.ts
@@ -1,11 +1,15 @@
import i18n from './i18n';
+import base64 from './base64';
import themeColor from './theme-color';
import tag from './tag';
import stylus from './stylus';
+import typescript from './typescript';
export default (lang, locale) => [
i18n(lang, locale),
+ base64(),
themeColor(),
tag(),
- stylus()
+ stylus(),
+ typescript()
];
diff --git a/webpack/module/rules/typescript.ts b/webpack/module/rules/typescript.ts
new file mode 100644
index 0000000000..eb2b279a55
--- /dev/null
+++ b/webpack/module/rules/typescript.ts
@@ -0,0 +1,8 @@
+/**
+ * TypeScript
+ */
+
+export default () => ({
+ test: /\.ts$/,
+ use: 'awesome-typescript-loader'
+});
diff --git a/webpack/plugins/const.ts b/webpack/plugins/const.ts
index ccfcb45260..f64160b01a 100644
--- a/webpack/plugins/const.ts
+++ b/webpack/plugins/const.ts
@@ -7,7 +7,8 @@ import * as webpack from 'webpack';
import version from '../../src/version';
const constants = require('../../src/const.json');
-export default () => new webpack.DefinePlugin({
+export default lang => new webpack.DefinePlugin({
VERSION: JSON.stringify(version),
+ LANG: JSON.stringify(lang),
THEME_COLOR: JSON.stringify(constants.themeColor)
});
diff --git a/webpack/plugins/index.ts b/webpack/plugins/index.ts
index 99b16c2b05..345af7df9e 100644
--- a/webpack/plugins/index.ts
+++ b/webpack/plugins/index.ts
@@ -2,25 +2,23 @@ const StringReplacePlugin = require('string-replace-webpack-plugin');
import constant from './const';
import hoist from './hoist';
-//import minify from './minify';
+import minify from './minify';
import banner from './banner';
-/*
const env = process.env.NODE_ENV;
const isProduction = env === 'production';
-*/
-export default version => {
+export default (version, lang) => {
const plugins = [
- constant(),
+ constant(lang),
new StringReplacePlugin(),
hoist()
];
-/*
+
if (isProduction) {
plugins.push(minify());
}
-*/
+
plugins.push(banner(version));
return plugins;
diff --git a/webpack/plugins/minify.ts b/webpack/plugins/minify.ts
index ec4c9b3405..e46d4c5a10 100644
--- a/webpack/plugins/minify.ts
+++ b/webpack/plugins/minify.ts
@@ -1,3 +1,3 @@
-const UglifyEsPlugin = require('uglify-es-webpack-plugin');
+const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
-export default () => new UglifyEsPlugin();
+export default () => new UglifyJsPlugin();
diff --git a/webpack/webpack.config.ts b/webpack/webpack.config.ts
index 5199285d55..97782a4102 100644
--- a/webpack/webpack.config.ts
+++ b/webpack/webpack.config.ts
@@ -16,6 +16,7 @@ module.exports = langs.map(([lang, locale]) => {
const entry = {
desktop: './src/web/app/desktop/script.js',
mobile: './src/web/app/mobile/script.js',
+ ch: './src/web/app/ch/script.js',
stats: './src/web/app/stats/script.js',
status: './src/web/app/status/script.js',
dev: './src/web/app/dev/script.js',
@@ -31,7 +32,7 @@ module.exports = langs.map(([lang, locale]) => {
name,
entry,
module: module_(lang, locale),
- plugins: plugins(version),
+ plugins: plugins(version, lang),
output
};
});