From 7609892c1fad5cd7aaf08da0e2d64c836e83ccc3 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 19 Feb 2017 14:11:45 +0900 Subject: [PATCH 1/2] :v: --- gulpfile.ts | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/gulpfile.ts b/gulpfile.ts index 331d7d6811..12f4cb6e1e 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -159,7 +159,7 @@ gulp.task('build:client:scripts', () => new Promise(async (ok) => { const StringReplacePlugin = require('string-replace-webpack-plugin'); /* webpack options */ - const pack = { + const pack: Webpack.Configuration = { entry: { 'client': './src/web/app/client/script.js', 'desktop': './src/web/app/desktop/script.js', @@ -170,22 +170,14 @@ gulp.task('build:client:scripts', () => new Promise(async (ok) => { module: { preLoaders: [ { - test: /\.(tag|js|styl)$/, + test: /\.tag$/, exclude: /node_modules/, loader: StringReplacePlugin.replace({ replacements: [ - { pattern: /VERSION/g, replacement: () => `'${commit ? commit.hash : 'null'}'` }, { pattern: /\$theme\-color\-foreground/g, replacement: () => '#fff' }, { pattern: /\$theme\-color/g, replacement: () => config.themeColor }, - { pattern: /CONFIG\.theme\-color/g, replacement: () => `'${config.themeColor}'` }, - { pattern: /CONFIG\.themeColor/g, replacement: () => `'${config.themeColor}'` }, - { pattern: /CONFIG\.api\.url/g, replacement: () => `'${config.api_url}'` }, - { pattern: /CONFIG\.urls\.about/g, replacement: () => `'${config.about_url}'` }, - { pattern: /CONFIG\.urls\.dev/g, replacement: () => `'${config.dev_url}'` }, - { pattern: /CONFIG\.url/g, replacement: () => `'${config.url}'` }, - { pattern: /CONFIG\.host/g, replacement: () => `'${config.host}'` }, - { pattern: /CONFIG\.recaptcha\.siteKey/g, replacement: () => `'${config.recaptcha.siteKey}'` }, - ]}) + ] + }) }, ], loaders: [ @@ -208,12 +200,27 @@ gulp.task('build:client:scripts', () => new Promise(async (ok) => { }, { test: /\.styl$/, + exclude: /node_modules/, loaders: ['style', 'css', 'stylus'] } ] }, plugins: [ - new StringReplacePlugin() + new Webpack.DefinePlugin({ + VERSION: JSON.stringify(commit ? commit.hash : null), + CONFIG: { + themeColor: JSON.stringify(config.themeColor), + apiUrl: JSON.stringify(config.api_url), + aboutUrl: JSON.stringify(config.about_url), + devUrl: JSON.stringify(config.dev_url), + host: JSON.stringify(config.host), + url: JSON.stringify(config.url), + recaptcha: { + siteKey: JSON.stringify(config.recaptcha.siteKey), + } + } + }), + new StringReplacePlugin(), ], output: { filename: '[name]/script.js' From d392da64ab48a6c930d7f523dd9f844b0db2bd0b Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 19 Feb 2017 15:32:10 +0900 Subject: [PATCH 2/2] :tada: --- gulpfile.ts | 19 ++++++++++++++----- src/web/app/boot.js | 7 ++++++- src/web/app/common/scripts/api.js | 2 +- .../app/common/scripts/messaging-stream.js | 2 +- src/web/app/common/scripts/stream.js | 2 +- src/web/app/common/tags/introduction.tag | 2 +- src/web/app/common/tags/signup.tag | 2 +- src/web/app/common/tags/twitter-setting.tag | 6 +++--- src/web/app/common/tags/uploader.tag | 2 +- src/web/app/desktop/scripts/update-avatar.js | 2 +- src/web/app/desktop/scripts/update-banner.js | 2 +- src/web/app/desktop/tags/home-widgets/nav.tag | 2 +- .../desktop/tags/pages/entrance/signin.tag | 2 +- src/web/app/mobile/tags/ui-nav.tag | 2 +- 14 files changed, 34 insertions(+), 20 deletions(-) diff --git a/gulpfile.ts b/gulpfile.ts index 12f4cb6e1e..65c05d1f98 100644 --- a/gulpfile.ts +++ b/gulpfile.ts @@ -168,8 +168,9 @@ gulp.task('build:client:scripts', () => new Promise(async (ok) => { 'auth': './src/web/app/auth/script.js' }, module: { - preLoaders: [ + rules: [ { + enforce: 'pre', test: /\.tag$/, exclude: /node_modules/, loader: StringReplacePlugin.replace({ @@ -179,8 +180,6 @@ gulp.task('build:client:scripts', () => new Promise(async (ok) => { ] }) }, - ], - loaders: [ { test: /\.tag$/, exclude: /node_modules/, @@ -201,7 +200,17 @@ gulp.task('build:client:scripts', () => new Promise(async (ok) => { { test: /\.styl$/, exclude: /node_modules/, - loaders: ['style', 'css', 'stylus'] + use: [ + { + loader: 'style-loader' + }, + { + loader: 'css-loader' + }, + { + loader: 'stylus-loader' + } + ] } ] }, @@ -233,7 +242,7 @@ gulp.task('build:client:scripts', () => new Promise(async (ok) => { //pack.plugins.push(new Webpack.optimize.UglifyJsPlugin()) } - let stream = webpack(pack); + let stream = webpack(pack, Webpack); // TODO: remove this block if (isProduction) { diff --git a/src/web/app/boot.js b/src/web/app/boot.js index b98602d402..c5dc6845af 100644 --- a/src/web/app/boot.js +++ b/src/web/app/boot.js @@ -17,6 +17,11 @@ require('./common/tags'); document.domain = CONFIG.host; +// Set global configration +riot.mixin({ + CONFIG: CONFIG +}); + // ↓ iOS待ちPolyfill (SEE: http://caniuse.com/#feat=fetch) require('whatwg-fetch'); @@ -109,7 +114,7 @@ function fetchme(token, cb) { } // Fetch user - fetch(CONFIG.api.url + '/i', { + fetch(CONFIG.apiUrl + '/i', { method: 'POST', body: JSON.stringify({ i: token diff --git a/src/web/app/common/scripts/api.js b/src/web/app/common/scripts/api.js index 924d697ebc..b549fe47b9 100644 --- a/src/web/app/common/scripts/api.js +++ b/src/web/app/common/scripts/api.js @@ -24,7 +24,7 @@ module.exports = (i, endpoint, data = {}) => { return new Promise((resolve, reject) => { // Send request - fetch(endpoint.indexOf('://') > -1 ? endpoint : `${CONFIG.api.url}/${endpoint}`, { + fetch(endpoint.indexOf('://') > -1 ? endpoint : `${CONFIG.apiUrl}/${endpoint}`, { method: 'POST', body: JSON.stringify(data), credentials: endpoint === 'signin' ? 'include' : 'omit' diff --git a/src/web/app/common/scripts/messaging-stream.js b/src/web/app/common/scripts/messaging-stream.js index 17634c0707..2c00c24024 100644 --- a/src/web/app/common/scripts/messaging-stream.js +++ b/src/web/app/common/scripts/messaging-stream.js @@ -12,7 +12,7 @@ class Connection { this.event = riot.observable(); this.me = me; - const host = CONFIG.api.url.replace('http', 'ws'); + const host = CONFIG.apiUrl.replace('http', 'ws'); this.socket = new ReconnectingWebSocket(`${host}/messaging?i=${me.token}&otherparty=${otherparty}`); this.socket.addEventListener('open', this.onOpen); this.socket.addEventListener('message', this.onMessage); diff --git a/src/web/app/common/scripts/stream.js b/src/web/app/common/scripts/stream.js index 5c8c3e1073..34ddc8447d 100644 --- a/src/web/app/common/scripts/stream.js +++ b/src/web/app/common/scripts/stream.js @@ -5,7 +5,7 @@ module.exports = me => { let state = 'initializing'; const stateEv = riot.observable(); const event = riot.observable(); - const host = CONFIG.api.url.replace('http', 'ws'); + const host = CONFIG.apiUrl.replace('http', 'ws'); const socket = new ReconnectingWebSocket(`${host}?i=${me.token}`); socket.onopen = () => { diff --git a/src/web/app/common/tags/introduction.tag b/src/web/app/common/tags/introduction.tag index 7950586a27..24fe86e997 100644 --- a/src/web/app/common/tags/introduction.tag +++ b/src/web/app/common/tags/introduction.tag @@ -3,7 +3,7 @@

Misskeyとは?

Misskeyみすきーは、syuiloが2014年くらいからオープンソースで開発・運営を行っている、ミニブログベースのSNSです。

Twitter, Facebook, LINE, Google+ などをパクって参考にしています。

無料で誰でも利用でき、広告は一切掲載していません。

-

もっと知りたい方はこちら

+

もっと知りたい方はこちら