]> cat aescling's git repositories - mastodon.git/commitdiff
Use RegExp for require.context to filter custom stylesheets (#2950)
authorAkihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>
Tue, 9 May 2017 17:51:45 +0000 (02:51 +0900)
committerEugen Rochko <eugen@zeonfederated.com>
Tue, 9 May 2017 17:51:45 +0000 (19:51 +0200)
ExtractTextWebpackPlugin extracts the content of loaded files, which means
it loads files loaded by require.context but not required after that.
However the former implementation is not aware of that.

require.context can have a RegExp to filter files to load. This change
gives a RegExp which matches with SCSSes with 'custom' prefix to
require.context to take advantage of the feature.

app/javascript/packs/application.js

index 247ac3922f276b199c1898011f28c70ce0d35d4f..367b7e76a935e5653987bbd3741497ecce6f9aab 100644 (file)
@@ -15,12 +15,7 @@ window.Perf = require('react-addons-perf');
 Rails.start();
 
 require.context('../images/', true);
-
-const customContext = require.context('../../assets/stylesheets/', false);
-
-if (customContext.keys().indexOf('./custom.scss') !== -1) {
-  customContext('./custom.scss');
-}
+require.context('../../assets/stylesheets/', false, /custom.*\.scss$/);
 
 document.addEventListener('DOMContentLoaded', () => {
   const mountNode = document.getElementById('mastodon');