summaryrefslogtreecommitdiff
path: root/webpack
diff options
context:
space:
mode:
authorsyuilo <syuilotan@yahoo.co.jp>2017-11-23 05:43:00 +0900
committersyuilo <syuilotan@yahoo.co.jp>2017-11-23 05:43:00 +0900
commit3f8ebac466ece8e9598432f3f574ec44e420c03b (patch)
tree05114fce9728d6ce1deecc1f2eb8a903a22b0100 /webpack
parent:v: (diff)
downloadmisskey-3f8ebac466ece8e9598432f3f574ec44e420c03b.tar.gz
misskey-3f8ebac466ece8e9598432f3f574ec44e420c03b.tar.bz2
misskey-3f8ebac466ece8e9598432f3f574ec44e420c03b.zip
なんかもうめっちゃ変えた
Closes #940
Diffstat (limited to 'webpack')
-rw-r--r--webpack/module/rules/consts.ts36
-rw-r--r--webpack/module/rules/index.ts2
-rw-r--r--webpack/plugins/const.ts14
-rw-r--r--webpack/plugins/index.ts2
4 files changed, 38 insertions, 16 deletions
diff --git a/webpack/module/rules/consts.ts b/webpack/module/rules/consts.ts
new file mode 100644
index 0000000000..2469ecf345
--- /dev/null
+++ b/webpack/module/rules/consts.ts
@@ -0,0 +1,36 @@
+/**
+ * Replace consts
+ */
+
+const StringReplacePlugin = require('string-replace-webpack-plugin');
+
+import version from '../../../src/version';
+const constants = require('../../../src/const.json');
+import config from '../../../src/conf';
+
+export default lang => {
+ // 置換の誤爆を防ぐため文字数の多い順に並べてください
+ const consts = {
+ _RECAPTCHA_SITEKEY_: JSON.stringify(config.recaptcha.site_key),
+ _SW_PUBLICKEY_: JSON.stringify(config.sw.public_key),
+ _THEME_COLOR_: JSON.stringify(constants.themeColor),
+ _VERSION_: JSON.stringify(version),
+ _API_URL_: JSON.stringify(config.api_url),
+ _LANG_: JSON.stringify(lang),
+ _HOST_: JSON.stringify(config.host),
+ _URL_: JSON.stringify(config.url),
+ };
+
+ const replacements = Object.keys(consts).map(key => ({
+ pattern: new RegExp(key, 'g'), replacement: () => consts[key]
+ }));
+
+ return {
+ enforce: 'post',
+ test: /\.(tag|js|ts)$/,
+ exclude: /node_modules/,
+ loader: StringReplacePlugin.replace({
+ replacements: replacements
+ })
+ };
+};
diff --git a/webpack/module/rules/index.ts b/webpack/module/rules/index.ts
index 9c1262b3d6..0006f622d2 100644
--- a/webpack/module/rules/index.ts
+++ b/webpack/module/rules/index.ts
@@ -1,4 +1,5 @@
import i18n from './i18n';
+import consts from './consts';
import base64 from './base64';
import themeColor from './theme-color';
import tag from './tag';
@@ -7,6 +8,7 @@ import typescript from './typescript';
export default (lang, locale) => [
i18n(lang, locale),
+ consts(lang),
base64(),
themeColor(),
tag(),
diff --git a/webpack/plugins/const.ts b/webpack/plugins/const.ts
deleted file mode 100644
index f64160b01a..0000000000
--- a/webpack/plugins/const.ts
+++ /dev/null
@@ -1,14 +0,0 @@
-/**
- * Constant Replacer
- */
-
-import * as webpack from 'webpack';
-
-import version from '../../src/version';
-const constants = require('../../src/const.json');
-
-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 d37047b672..24782a1de6 100644
--- a/webpack/plugins/index.ts
+++ b/webpack/plugins/index.ts
@@ -1,6 +1,5 @@
const StringReplacePlugin = require('string-replace-webpack-plugin');
-import constant from './const';
import hoist from './hoist';
//import minify from './minify';
import banner from './banner';
@@ -10,7 +9,6 @@ const isProduction = env === 'production';
export default (version, lang) => {
const plugins = [
- constant(lang),
new StringReplacePlugin(),
hoist()
];