From b3904c25539fcadbd127a3e44b32076c1a8ec2a0 Mon Sep 17 00:00:00 2001 From: kibigo! Date: Thu, 22 Jun 2017 20:15:11 -0700 Subject: [PATCH] MORE FRONTENDS (EASY MODE) WIN!!! --- app/controllers/home_controller.rb | 1 + app/javascript/modules/.keep | 0 app/javascript/packs/common.js | 1 + app/javascript/packs/frontends/mastodon.js | 6 ++++++ app/views/home/index.html.haml | 5 ++++- app/views/layouts/application.html.haml | 4 +++- config/webpack/shared.js | 13 +------------ 7 files changed, 16 insertions(+), 14 deletions(-) create mode 100644 app/javascript/modules/.keep create mode 100644 app/javascript/packs/frontends/mastodon.js diff --git a/app/controllers/home_controller.rb b/app/controllers/home_controller.rb index 1d41892cdd..a526e25ece 100644 --- a/app/controllers/home_controller.rb +++ b/app/controllers/home_controller.rb @@ -9,6 +9,7 @@ class HomeController < ApplicationController @web_settings = Web::Setting.find_by(user: current_user)&.data || {} @admin = Account.find_local(Setting.site_contact_username) @streaming_api_base_url = Rails.configuration.x.streaming_api_base_url + @frontend = (params[:frontend] and Rails.root.join('app', 'javascript', 'packs', 'frontends', '#{params[:frontend]}.js')) ? params[:frontend] : 'mastodon' end private diff --git a/app/javascript/modules/.keep b/app/javascript/modules/.keep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/app/javascript/packs/common.js b/app/javascript/packs/common.js index 9d63d8f982..805f3c6276 100644 --- a/app/javascript/packs/common.js +++ b/app/javascript/packs/common.js @@ -1,2 +1,3 @@ import { start } from 'rails-ujs'; +require('../mastodon/locales'); start(); diff --git a/app/javascript/packs/frontends/mastodon.js b/app/javascript/packs/frontends/mastodon.js new file mode 100644 index 0000000000..375da17ad4 --- /dev/null +++ b/app/javascript/packs/frontends/mastodon.js @@ -0,0 +1,6 @@ +import main from '../../mastodon/main'; +import loadPolyfills from '../../mastodon/load_polyfills'; + +loadPolyfills().then(main).catch(e => { + console.error(e); +}); diff --git a/app/views/home/index.html.haml b/app/views/home/index.html.haml index 33c978c891..01e71780dd 100644 --- a/app/views/home/index.html.haml +++ b/app/views/home/index.html.haml @@ -1,7 +1,10 @@ - content_for :header_tags do %script#initial-state{ type: 'application/json' }!= json_escape(render(file: 'home/initial_state', formats: :json)) - = javascript_pack_tag 'application', integrity: true, crossorigin: 'anonymous' + = javascript_pack_tag "frontends/#{@frontend}", integrity: true, crossorigin: 'anonymous' + = stylesheet_pack_tag "frontends/#{@frontend}", integrity: true, media: 'all' + + %script{ type: 'text/html' }!=@frontendp .app-holder#mastodon{ data: { props: Oj.dump(default_props) } } %noscript diff --git a/app/views/layouts/application.html.haml b/app/views/layouts/application.html.haml index f991bc74f5..c2873011e7 100755 --- a/app/views/layouts/application.html.haml +++ b/app/views/layouts/application.html.haml @@ -18,11 +18,13 @@ = ' - ' = title - = stylesheet_pack_tag 'application', media: 'all' = javascript_pack_tag 'common', integrity: true, crossorigin: 'anonymous' = javascript_pack_tag "locale_#{I18n.locale}", integrity: true, crossorigin: 'anonymous' = csrf_meta_tags + - if controller_name != 'home' + = stylesheet_pack_tag 'application', integrity: true, media: 'all' + = yield :header_tags - body_classes ||= @body_classes diff --git a/config/webpack/shared.js b/config/webpack/shared.js index 4d865b8163..777d6bb123 100644 --- a/config/webpack/shared.js +++ b/config/webpack/shared.js @@ -51,18 +51,7 @@ module.exports = { }), new webpack.optimize.CommonsChunkPlugin({ name: 'common', - minChunks: (module, count) => { - const reactIntlPathRegexp = new RegExp(`node_modules\\${sep}react-intl`); - - if (module.resource && reactIntlPathRegexp.test(module.resource)) { - // skip react-intl because it's useless to put in the common chunk, - // e.g. because "shared" modules between zh-TW and zh-CN will never - // be loaded together - return false; - } - - return count >= 2; - }, + minChunks: Infinity }), ],