Skip to content

Commit 6f7988b

Browse files
committed
Copyless setup of react source
1 parent 0faa0f6 commit 6f7988b

File tree

1 file changed

+6
-26
lines changed

1 file changed

+6
-26
lines changed

lib/react/rails/railtie.rb

+6-26
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,14 @@ class Railtie < ::Rails::Railtie
2929
end
3030

3131
initializer "react_rails.setup_vendor", group: :all do |app|
32-
# Mimic behavior of ember-rails...
33-
# We want to include different files in dev/prod. The unminified builds
32+
# We want to include different files in dev/prod. The development builds
3433
# contain console logging for invariants and logging to help catch
35-
# common mistakes. These are all stripped out in the minified build.
34+
# common mistakes. These are all stripped out in the production build.
3635

37-
# Copy over the variant into a path that sprockets will pick up.
38-
# We'll always copy to 'react.js' so that no includes need to change.
39-
# We'll also always copy of JSXTransformer.js
40-
tmp_path = app.root.join('tmp/react-rails')
41-
filename = 'react' +
42-
(app.config.react.addons ? '-with-addons' : '') +
43-
(app.config.react.variant == :production ? '.min.js' : '.js')
44-
FileUtils.mkdir_p(tmp_path)
45-
FileUtils.cp(::React::Source.bundled_path_for(filename),
46-
tmp_path.join('react.js'))
47-
FileUtils.cp(::React::Source.bundled_path_for('JSXTransformer.js'),
48-
tmp_path.join('JSXTransformer.js'))
49-
app.assets.prepend_path tmp_path
50-
51-
# Allow overriding react files that are not based on environment
52-
# e.g. /vendor/assets/react/JSXTransformer.js
53-
dropin_path = app.root.join("vendor/assets/react")
54-
app.assets.prepend_path dropin_path if dropin_path.exist?
55-
56-
# Allow overriding react files that are based on environment
57-
# e.g. /vendor/assets/react/development/react.js
58-
dropin_path_env = app.root.join("vendor/assets/react/#{app.config.react.variant}")
59-
app.assets.prepend_path dropin_path_env if dropin_path_env.exist?
36+
directory = (app.config.react.variant || :production).to_s
37+
directory += 'with-addons' if app.config.react.addons
38+
app.assets.prepend_path ::React::Source.bundled_path_for(directory)
39+
app.assets.prepend_path ::React::Source.bundled_path_for('') # JSXTransformer.js
6040
end
6141

6242

0 commit comments

Comments
 (0)