Introduce common JavaScript file (#2981)

* Create common chunk rather than vendor chunk

vendor chunk is a set of modules provided by external vendors, but now we
can have a chunk as a set of modules shared by multiple entry points,
which could be more efficent than having vendor chunk.

* Start rails-ujs in common.js

This is used by /settings/two_factor_authentication.
This commit is contained in:
Akihiko Odaki 2017-05-16 03:20:10 +09:00 committed by Eugen Rochko
parent 6ee3a10f17
commit 85c9496340
5 changed files with 5 additions and 10 deletions

View File

@ -17,11 +17,8 @@ function main() {
const Mastodon = require('mastodon/containers/mastodon').default; const Mastodon = require('mastodon/containers/mastodon').default;
const React = require('react'); const React = require('react');
const ReactDOM = require('react-dom'); const ReactDOM = require('react-dom');
const Rails = require('rails-ujs');
window.Perf = require('react-addons-perf'); window.Perf = require('react-addons-perf');
Rails.start();
require.context('../images/', true); require.context('../images/', true);
// import customization styles // import customization styles

View File

@ -0,0 +1,2 @@
import { start } from 'rails-ujs';
start();

View File

@ -3,12 +3,9 @@ import { length } from 'stringz';
import { default as dateFormat } from 'date-fns/format'; import { default as dateFormat } from 'date-fns/format';
import distanceInWordsStrict from 'date-fns/distance_in_words_strict'; import distanceInWordsStrict from 'date-fns/distance_in_words_strict';
import { delegate } from 'rails-ujs'; import { delegate } from 'rails-ujs';
import Rails from 'rails-ujs';
require.context('../images/', true); require.context('../images/', true);
Rails.start();
const parseFormat = (format) => format.replace(/%(\w)/g, (_, modifier) => { const parseFormat = (format) => format.replace(/%(\w)/g, (_, modifier) => {
switch (modifier) { switch (modifier) {
case '%': case '%':

View File

@ -18,9 +18,8 @@
= ' - ' = ' - '
= title = title
= stylesheet_pack_tag 'vendor', media: 'all'
= stylesheet_pack_tag 'application', media: 'all' = stylesheet_pack_tag 'application', media: 'all'
= javascript_pack_tag 'vendor', integrity: true, crossorigin: 'anonymous' = javascript_pack_tag 'common', integrity: true, crossorigin: 'anonymous'
= csrf_meta_tags = csrf_meta_tags
= yield :header_tags = yield :header_tags

View File

@ -40,8 +40,8 @@ module.exports = {
new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'), new ExtractTextPlugin(env.NODE_ENV === 'production' ? '[name]-[hash].css' : '[name].css'),
new ManifestPlugin({ fileName: paths.manifest, publicPath, writeToFileEmit: true }), new ManifestPlugin({ fileName: paths.manifest, publicPath, writeToFileEmit: true }),
new webpack.optimize.CommonsChunkPlugin({ new webpack.optimize.CommonsChunkPlugin({
name: 'vendor', name: 'common',
minChunks: ({ resource }) => /node_modules/.test(resource) minChunks: 2
}) })
], ],