diff --git a/app/helpers/react_on_rails_helper.rb b/app/helpers/react_on_rails_helper.rb
index e33a2287fa..2f1382236c 100644
--- a/app/helpers/react_on_rails_helper.rb
+++ b/app/helpers/react_on_rails_helper.rb
@@ -270,7 +270,7 @@ def server_rendered_react_component_html(props, react_component_name, dom_id,
# On server `location` option is added (`location = request.fullpath`)
# React Router needs this to match the current route
- # Make sure that we use up-to-date server-bundle
+ # Make sure that we use up-to-date webpack-bundle
ReactOnRails::ServerRenderingPool.reset_pool_if_server_bundle_was_modified
# Since this code is not inserted on a web page, we don't need to escape props
diff --git a/lib/generators/USAGE b/lib/generators/USAGE
index 3dcbd689ac..6ca9ce66fc 100644
--- a/lib/generators/USAGE
+++ b/lib/generators/USAGE
@@ -1,10 +1,6 @@
Description:
-The react_on_rails:install generator combined with the example pull requests of
-generator runs will get you up and running efficiently. There's a fair bit of
-setup involved when integrating Webpack with Rails. Defaults for options
-are such that the default is for the flag to be off. For example, the default for
-`-R` is that redux is off, and the default of -b is that skip-bootstrap is off.
+The react_on_rails:install generator integrates webpack with rails with ease. You can pass the redux option if you'd like to have redux setup for you automatically.
* Redux
@@ -12,88 +8,6 @@ are such that the default is for the flag to be off. For example, the default fo
to integrate the Redux state container framework. The necessary node modules
will be automatically included for you.
- The generator uses the organizational `paradigm of "bundles"`. These are like
- application domains and are used for grouping your code into webpack bundles
- in case you decide to create different bundles for deployment. This is also
- useful for separating out logical parts of your application. We recommend that
- that each bundle will have it's own Redux store. If you have code that you
- want to reuse across bundles, such as middleware or common utilities, place them
- under `/client/app/lib`. You can then import them in your client code:
- `import MyModule from 'lib/MyModule'`; since we have configured webpack to
- automatically resolve the word lib to point to this folder.
-
-* Using Images and Fonts
-
- The generator has amended the folders created in `client/assets/` to Rails's
- asset path. We recommend that if you have any existing assets that you want
- to use with your client code, you should move them to these folders and use
- webpack as normal. This allows webpack's development server to have access
- to your assets, as it will not be able to see any assets in the default Rails
- directories which are above the `/client` directory.
-
- Alternatively, if you have many existing assets and don't wish to move them,
- you could consider creating symlinks from `client/assets` that point to your
- Rails assets folders inside of `app/assets/`. The assets there will then be
- visible to both Rails and webpack.
-
-* Bootstrap Integration
-
- React on Rails ships with Twitter Bootstrap already integrated into the build.
- Note that the generator removes require_tree in both the application.js and
- application.css.scss files. This is to ensure the correct load order for the
- bootstrap integration, and is usually a good idea in general. You will therefore
- need to explicitly require your files.
-
- How the Bootstrap library is loaded depends upon whether one is using the Rails
- server or the HMR development server.
-
- 1. Bootstrap via Rails Server
-
- The Rails server loads bootstrap-sprockets, provided
- by the bootstrap-sass ruby gem (added automatically to your Gemfile by
- the generator), via the `app/assets/stylesheets/_bootstrap-custom.scss`
- partial.
-
- This allows for using Bootstrap in your regular Rails stylesheets. If you
- wish to customize any of the Bootstrap variables, you can do so via the
- `client/assets/stylesheets/_pre-bootstrap.scss` partial.
-
- 2. Bootstrap via Webpack Dev Server
-
- The webpack dev server does not go through Rails but instead loads bootstrap
- via the `bootstrap-sass-loader` webpack loader. You can configure the loader
- via the `client/bootstrap-sass-config.js` file.
-
- 3. Keeping Custom Bootstrap Configurations Synced
-
- Because the webpack dev server and Rails each load Bootstrap via a different
- file (explained in the two sections immediately above), any changes to
- the way components are loaded in one file must also be made to the other
- file in order to keep styling consistent between the two. For example,
- if an import is excluded in _bootstrap-custom.scss, the same import should
- be excluded in `bootstrap-sass-config.js` so that styling in the Rails
- server and the webpack dev server will be the same.
-
- 4. Skip Bootstrap Integration
-
- Bootstrap integration is enabled by default, but can be disabled by passing
- the --skip-bootstrap flag (alias -b). When you don't need Bootstrap in your
- existing project, just skip it as needed.
-
-* JavaScript Linters
-
- JavaScript linters are enabled by default, but can be disabled by passing the
- --skip-js-linters flag (alias j), and those that run in Node have been added to
- `client/package.json` under devDependencies.
-
-* Ruby Linters
-
- Ruby linters are disabled by default, but can be enabled by passing the
- `--ruby-linters` flag when generating. These linters have been added to your
- Gemfile in addition to the the appropriate Rake tasks.
-
- We really love using all the linters! Give them a try.
-
*******************************************************************************
After running the generator, you will want to:
@@ -102,14 +16,7 @@ After running the generator, you will want to:
Then you may run
- npm run
-
-And you will see several useful commands:
-
- express-server
- echo 'visit http://localhost:4000' && cd client && npm start
- rails-server
- echo 'visit http://localhost:3000/hello_world' && foreman start -f Procfile.dev
+ foreman start -f Procfile.dev
More Details:
diff --git a/lib/generators/react_on_rails/base_generator.rb b/lib/generators/react_on_rails/base_generator.rb
index 884f72e9b5..87ca28bc4e 100644
--- a/lib/generators/react_on_rails/base_generator.rb
+++ b/lib/generators/react_on_rails/base_generator.rb
@@ -15,12 +15,6 @@ class BaseGenerator < Rails::Generators::Base # rubocop:disable Metrics/ClassLen
default: false,
desc: "Install Redux gems and Redux version of Hello World Example",
aliases: "-R"
- # --server-rendering
- class_option :server_rendering,
- type: :boolean,
- default: false,
- desc: "Configure for server-side rendering of webpack JavaScript",
- aliases: "-S"
def add_hello_world_route
route "get 'hello_world', to: 'hello_world#index'"
@@ -48,11 +42,7 @@ def update_application_js
// DO NOT REQUIRE jQuery or jQuery-ujs in this file!
// DO NOT REQUIRE TREE!
- // CRITICAL that vendor-bundle must be BEFORE bootstrap-sprockets and turbolinks
- // since it is exposing jQuery and jQuery-ujs
-
- //= require vendor-bundle
- //= require app-bundle
+ //= require webpack-bundle
DATA
@@ -86,10 +76,7 @@ def copy_base_files
base_path = "base/base/"
base_files = %w(app/controllers/hello_world_controller.rb
client/.babelrc
- client/webpack.client.base.config.js
- client/webpack.client.rails.config.js
- REACT_ON_RAILS.md
- client/REACT_ON_RAILS_CLIENT_README.md)
+ client/webpack.config.js)
base_files.each { |file| copy_file(base_path + file, file) }
end
@@ -103,26 +90,6 @@ def template_base_files
client/package.json).each { |file| template(base_path + file + ".tt", file) }
end
- def add_base_gems_to_gemfile
- return unless options.server_rendering?
- append_to_file("Gemfile", "\ngem 'therubyracer', platforms: :ruby\n")
- end
-
- def template_client_registration_file
- filename = "clientRegistration.jsx"
- location = "client/app/bundles/HelloWorld/startup"
- template("base/base/#{location}/clientRegistration.jsx.tt", "#{location}/#{filename}")
- end
-
- def install_server_rendering_files_if_enabled
- return unless options.server_rendering?
- base_path = "base/server_rendering/"
- %w(client/webpack.server.rails.config.js
- client/app/bundles/HelloWorld/startup/serverRegistration.jsx).each do |file|
- copy_file(base_path + file, file)
- end
- end
-
def template_assets_rake_file
template("base/base/lib/tasks/assets.rake.tt", "lib/tasks/assets.rake")
end
@@ -132,7 +99,7 @@ def template_assets_rake_file
# If you do not want to move existing images and fonts from your Rails app
# you could also consider creating symlinks there that point to the original
# rails directories. In that case, you would not add these paths here.
-Rails.application.config.assets.precompile += %w( server-bundle.js )
+Rails.application.config.assets.precompile += %w( webpack-bundle.js )
# Add folder with webpack generated assets to assets.paths
Rails.application.config.assets.paths << Rails.root.join("app", "assets", "webpack")
diff --git a/lib/generators/react_on_rails/dev_tests_generator.rb b/lib/generators/react_on_rails/dev_tests_generator.rb
index 8602620fbb..a6beb5461b 100644
--- a/lib/generators/react_on_rails/dev_tests_generator.rb
+++ b/lib/generators/react_on_rails/dev_tests_generator.rb
@@ -8,6 +8,12 @@ class DevTestsGenerator < Rails::Generators::Base
Rails::Generators.hide_namespace(namespace)
source_root(File.expand_path("../templates/dev_tests", __FILE__))
+ # --example-server-rendering
+ class_option :example_server_rendering,
+ type: :boolean,
+ default: false,
+ desc: "Setup prerender true for server rendered examples"
+
def copy_rspec_files
%w(spec/spec_helper.rb
spec/rails_helper.rb
@@ -40,7 +46,7 @@ def change_webpack_client_base_config_to_include_fallback
plugins: [
TEXT
sentinel = /^\s\s},\n\s\splugins: \[\n/
- config = File.join(destination_root, "client", "webpack.client.base.config.js")
+ config = File.join(destination_root, "client", "webpack.config.js")
old_contents = File.read(config)
new_contents = old_contents.gsub(sentinel, text)
File.open(config, "w+") { |f| f.puts new_contents }
@@ -53,6 +59,16 @@ def add_test_related_gems_to_gemfile
gem("coveralls", require: false)
gem("poltergeist")
end
+
+ def gsub_prerender_if_server_rendering
+ return if !options.example_server_rendering
+ hello_world_index = File.join(destination_root, "app", "views", "hello_world", "index.html.erb")
+ hello_world_contents = File.read(hello_world_index)
+ new_hello_world_contents = hello_world_contents.gsub(/\) %>/,
+ ', prerender: true) %>')
+
+ File.open(hello_world_index, "w+") { |f| f.puts new_hello_world_contents }
+ end
end
end
end
diff --git a/lib/generators/react_on_rails/install_generator.rb b/lib/generators/react_on_rails/install_generator.rb
index a3210f0ad0..580978715b 100644
--- a/lib/generators/react_on_rails/install_generator.rb
+++ b/lib/generators/react_on_rails/install_generator.rb
@@ -16,12 +16,6 @@ class InstallGenerator < Rails::Generators::Base
default: false,
desc: "Install Redux gems and Redux version of Hello World Example. Default: false",
aliases: "-R"
- # --server-rendering
- class_option :server_rendering,
- type: :boolean,
- default: false,
- desc: "Add necessary files and configurations for server-side rendering. Default: false",
- aliases: "-S"
# --ignore-warnings
class_option :ignore_warnings,
diff --git a/lib/generators/react_on_rails/react_no_redux_generator.rb b/lib/generators/react_on_rails/react_no_redux_generator.rb
index e559db20dd..ed633f7bfb 100644
--- a/lib/generators/react_on_rails/react_no_redux_generator.rb
+++ b/lib/generators/react_on_rails/react_no_redux_generator.rb
@@ -8,30 +8,16 @@ class ReactNoReduxGenerator < Rails::Generators::Base
Rails::Generators.hide_namespace(namespace)
source_root(File.expand_path("../templates", __FILE__))
- # --server-rendering
- class_option :server_rendering,
- type: :boolean,
- default: false,
- desc: "Configure for server-side rendering of webpack JavaScript",
- aliases: "-S"
-
def copy_base_files
base_path = "no_redux/base/"
file = "client/app/bundles/HelloWorld/containers/HelloWorld.jsx"
copy_file(base_path + file, file)
end
- def copy_server_rendering_files_if_appropriate
- return unless options.server_rendering?
- base_path = "no_redux/server_rendering/"
- file = "client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx"
- copy_file(base_path + file, file)
- end
-
- def template_appropriate_version_of_hello_world_app_client
- filename = "HelloWorldAppClient.jsx"
+ def template_appropriate_version_of_hello_world_app
+ filename = "HelloWorldApp.jsx"
location = "client/app/bundles/HelloWorld/startup"
- template("no_redux/base/#{location}/HelloWorldAppClient.jsx.tt", "#{location}/#{filename}")
+ template("no_redux/base/#{location}/HelloWorldApp.jsx.tt", "#{location}/#{filename}")
end
end
end
diff --git a/lib/generators/react_on_rails/react_with_redux_generator.rb b/lib/generators/react_on_rails/react_with_redux_generator.rb
index 8843359909..f15acc6869 100644
--- a/lib/generators/react_on_rails/react_with_redux_generator.rb
+++ b/lib/generators/react_on_rails/react_with_redux_generator.rb
@@ -6,18 +6,9 @@ class ReactWithReduxGenerator < Rails::Generators::Base
Rails::Generators.hide_namespace(namespace)
source_root(File.expand_path("../templates", __FILE__))
- # --server-rendering
- class_option :server_rendering,
- type: :boolean,
- default: false,
- desc: "Configure for server-side rendering of webpack JavaScript",
- aliases: "-S"
-
def create_redux_directories
dirs = %w(actions constants reducers store)
dirs.each { |name| empty_directory("client/app/bundles/HelloWorld/#{name}") }
-
- empty_directory("client/app/lib/middlewares")
end
def copy_base_redux_files
@@ -27,23 +18,15 @@ def copy_base_redux_files
client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx
client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx
client/app/bundles/HelloWorld/reducers/index.jsx
- client/app/bundles/HelloWorld/store/helloWorldStore.jsx
- client/app/lib/middlewares/loggerMiddleware.js).each do |file|
+ client/app/bundles/HelloWorld/store/helloWorldStore.jsx).each do |file|
copy_file(base_path + file, file)
end
end
- def copy_server_rendering_redux_files
- return unless options.server_rendering?
- base_path = "redux/server_rendering/"
- file = "client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx"
- copy_file(base_path + file, file)
- end
-
- def template_appropriate_version_of_hello_world_app_client
- filename = "HelloWorldAppClient.jsx"
+ def template_appropriate_version_of_hello_world_app
+ filename = "HelloWorldApp.jsx"
location = "client/app/bundles/HelloWorld/startup"
- template("redux/base/#{location}/HelloWorldAppClient.jsx.tt", "#{location}/#{filename}")
+ template("redux/base/#{location}/HelloWorldApp.jsx.tt", "#{location}/#{filename}")
end
end
end
diff --git a/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt b/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt
index 27e91f4af5..d14c6cabf8 100644
--- a/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt
+++ b/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt
@@ -1,3 +1,2 @@
web: rails s
-client: sh -c 'rm app/assets/webpack/* || true && cd client && npm run build:dev:client'
-<%- if options.server_rendering? %>server: sh -c 'cd client && npm run build:dev:server'<%- end %>
+client: sh -c 'rm app/assets/webpack/* || true && cd client && npm run build:dev'
diff --git a/lib/generators/react_on_rails/templates/base/base/REACT_ON_RAILS.md b/lib/generators/react_on_rails/templates/base/base/REACT_ON_RAILS.md
deleted file mode 100644
index da6741e7a2..0000000000
--- a/lib/generators/react_on_rails/templates/base/base/REACT_ON_RAILS.md
+++ /dev/null
@@ -1,16 +0,0 @@
-The `react_on_rails` gem has been installed. You can view the documentation online at
-[React on Rails](https://github.com/shakacode/react_on_rails).
-
-Also, check out the [example application](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/server.js)
-for a live example and code.
-
-The "Hello World" example has been installed.
-
-+ The view is located at `app/views/hello_world/index.html.erb`
-+ The controller is located at `app/controllers/hello_world_controller.rb`
-
-See [the documentation](https://github.com/shakacode/react_on_rails) for how to build your bundles and
-install your packages. Then you can view the example as follows:
-
-- Rails Server: [localhost:3000/hello_world](http://localhost:3000/hello_world)
-- Webpack Development Server with HMR: [localhost:4000/hello_world](http://localhost:4000/hello_world)
diff --git a/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt b/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt
index 6f0e76018f..ebf8512fe5 100644
--- a/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt
+++ b/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt
@@ -1,4 +1,3 @@
-
<%= options.server_rendering? ? "Server Rendering" : "Client Rendering" %>
-<%%= react_component("HelloWorldApp",
- props: @hello_world_props,
- prerender: <%= options.server_rendering? %>) %>
+Hello World
+<%%= react_component("HelloWorldApp", props: @hello_world_props) %>
+
diff --git a/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md b/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md
deleted file mode 100644
index 7bb961d954..0000000000
--- a/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md
+++ /dev/null
@@ -1,3 +0,0 @@
-Client folder generated by React on Rails gem.
-
-See documentation [on github](https://github.com/shakacode/react_on_rails) for details on how it is organized.
diff --git a/lib/generators/react_on_rails/templates/base/base/client/package.json.tt b/lib/generators/react_on_rails/templates/base/base/client/package.json.tt
index f1d7318670..6e6ce0ec15 100644
--- a/lib/generators/react_on_rails/templates/base/base/client/package.json.tt
+++ b/lib/generators/react_on_rails/templates/base/base/client/package.json.tt
@@ -7,23 +7,10 @@
"npm": "3.5.0"
},
"scripts": {
- "build:client": "NODE_ENV=production webpack --config webpack.client.rails.config.js",
- <%- if options.server_rendering? -%>
- "build:server": "NODE_ENV=production webpack --config webpack.server.rails.config.js",
- <%- end -%>
- "build:dev:client": "webpack -w --config webpack.client.rails.config.js",
- <%- if options.server_rendering? -%>
- "build:dev:server": "webpack -w --config webpack.server.rails.config.js",
- <%- end -%>
- "build:production:client": "NODE_ENV=production webpack --config webpack.client.rails.build.config.js",
- <%- if options.server_rendering? -%>
- "build:production:server": "NODE_ENV=production webpack --config webpack.server.rails.build.config.js",
- <%- end -%>
- "test": "echo \"Error: no test specified\" && exit 1"
+ "build": "NODE_ENV=production webpack --config webpack.config.js",
+ "build:dev": "webpack -w --config webpack.config.js"
},
"dependencies": {
- "autoprefixer": "^6.3.5",
- "axios": "^0.9.1",
"babel": "^6.5.2",
"babel-cli": "^6.6.5",
"babel-core": "^6.7.4",
@@ -33,7 +20,6 @@
"babel-preset-es2015": "^6.6.0",
"babel-preset-react": "^6.5.0",
"babel-preset-stage-0": "^6.5.0",
- "css-loader": "^0.23.1",
"es5-shim": "^4.5.7",
"expose-loader": "^0.7.1",
<%- if options.redux? -%>
@@ -42,8 +28,6 @@
"imports-loader": "^0.6.5",
"jquery": "^2.2.2",
"jquery-ujs": "^1.2.1",
- "loader-utils": "^0.2.13",
- "lodash": "^4.7.0",
<%- if options.redux? -%>
"mirror-creator": "1.1.0",
<%- end -%>
diff --git a/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js b/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js
deleted file mode 100644
index b96abe10cc..0000000000
--- a/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js
+++ /dev/null
@@ -1,65 +0,0 @@
-// Common client-side webpack configuration used by webpack.hot.config and webpack.rails.config.
-
-const webpack = require('webpack');
-const path = require('path');
-
-const devBuild = process.env.NODE_ENV !== 'production';
-const nodeEnv = devBuild ? 'development' : 'production';
-
-module.exports = {
-
- // the project dir
- context: __dirname,
- entry: {
-
- // See use of 'vendor' in the CommonsChunkPlugin inclusion below.
- vendor: [
- 'babel-polyfill',
- 'jquery',
- ],
-
- // This will contain the app entry points defined by webpack.hot.config and
- // webpack.rails.config
- app: [
- './app/bundles/HelloWorld/startup/clientRegistration',
- ],
- },
- resolve: {
- extensions: ['', '.js', '.jsx'],
- alias: {
- lib: path.join(process.cwd(), 'app', 'lib'),
- react: path.resolve('./node_modules/react'),
- 'react-dom': path.resolve('./node_modules/react-dom'),
- },
- },
- plugins: [
- new webpack.DefinePlugin({
- 'process.env': {
- NODE_ENV: JSON.stringify(nodeEnv),
- },
- }),
-
- // https://webpack.github.io/docs/list-of-plugins.html#2-explicit-vendor-chunk
- new webpack.optimize.CommonsChunkPlugin({
-
- // This name 'vendor' ties into the entry definition
- name: 'vendor',
-
- // We don't want the default vendor.js name
- filename: 'vendor-bundle.js',
-
- // Passing Infinity just creates the commons chunk, but moves no modules into it.
- // In other words, we only put what's in the vendor entry definition in vendor-bundle.js
- minChunks: Infinity,
- }),
- ],
- module: {
- loaders: [
-
- // Not all apps require jQuery. Many Rails apps do, such as those using TurboLinks or
- // bootstrap js
- { test: require.resolve('jquery'), loader: 'expose?jQuery' },
- { test: require.resolve('jquery'), loader: 'expose?$' },
- ],
- },
-};
diff --git a/lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js b/lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js
deleted file mode 100644
index 5e0eb7798e..0000000000
--- a/lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js
+++ /dev/null
@@ -1,53 +0,0 @@
-// Run like this:
-// cd client && npm run build:dev:client
-// Note that Foreman (Procfile.dev) has also been configured to take care of this.
-
-// NOTE: All style sheets handled by the asset pipeline in rails
-
-const webpack = require('webpack');
-const config = require('./webpack.client.base.config');
-const devBuild = process.env.NODE_ENV !== 'production';
-
-config.output = {
- filename: '[name]-bundle.js',
- path: '../app/assets/webpack',
-};
-
-// You can add entry points specific to rails here
-// The es5-shim/sham is for capybara testing
-config.entry.vendor.unshift(
- 'es5-shim/es5-shim',
- 'es5-shim/es5-sham'
-);
-
-// jquery-ujs MUST GO AFTER jquery, so must use 'push'
-config.entry.vendor.push('jquery-ujs');
-
-// See webpack.common.config for adding modules common to both the webpack dev server and rails
-config.module.loaders.push(
- {
- test: /\.jsx?$/,
- loader: 'babel-loader',
- exclude: /node_modules/,
- },
- {
- test: require.resolve('react'),
- loader: 'imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham',
- },
- {
- test: require.resolve('jquery-ujs'),
- loader: 'imports?jQuery=jquery',
- }
-);
-
-module.exports = config;
-
-if (devBuild) {
- console.log('Webpack dev build for Rails'); // eslint-disable-line no-console
- module.exports.devtool = 'eval-source-map';
-} else {
- config.plugins.push(
- new webpack.optimize.DedupePlugin()
- );
- console.log('Webpack production build for Rails'); // eslint-disable-line no-console
-}
diff --git a/lib/generators/react_on_rails/templates/base/base/client/webpack.config.js b/lib/generators/react_on_rails/templates/base/base/client/webpack.config.js
new file mode 100644
index 0000000000..a470a13a9d
--- /dev/null
+++ b/lib/generators/react_on_rails/templates/base/base/client/webpack.config.js
@@ -0,0 +1,57 @@
+const webpack = require('webpack');
+const path = require('path');
+
+const devBuild = process.env.NODE_ENV !== 'production';
+const nodeEnv = devBuild ? 'development' : 'production';
+
+config = {
+ entry: [
+ 'es5-shim/es5-shim',
+ 'es5-shim/es5-sham',
+ 'babel-polyfill',
+ './app/bundles/HelloWorld/startup/HelloWorldApp',
+ ],
+
+ output: {
+ filename: 'webpack-bundle.js',
+ path: '../app/assets/webpack',
+ },
+
+ resolve: {
+ extensions: ['', '.js', '.jsx'],
+ alias: {
+ lib: path.join(process.cwd(), 'app', 'lib'),
+ // Look into
+ react: path.resolve('./node_modules/react'),
+ 'react-dom': path.resolve('./node_modules/react-dom'),
+ },
+ },
+ plugins: [
+ new webpack.DefinePlugin({
+ 'process.env': {
+ NODE_ENV: JSON.stringify(nodeEnv),
+ },
+ }),
+ ],
+ module: {
+ loaders: [
+ { test: require.resolve('jquery'), loader: 'expose?jQuery' },
+ { test: require.resolve('jquery'), loader: 'expose?$' },
+ { test: require.resolve('react'), loader: 'imports?shim=es5-shim/es5-shim&sham=es5-shim/es5-sham' },
+ { test: require.resolve('jquery-ujs'), loader: 'imports?jQuery=jquery' },
+ { test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/ },
+ ],
+ },
+};
+
+module.exports = config;
+
+if (devBuild) {
+ console.log('Webpack dev build for Rails'); // eslint-disable-line no-console
+ module.exports.devtool = 'eval-source-map';
+} else {
+ config.plugins.push(
+ new webpack.optimize.DedupePlugin()
+ );
+ console.log('Webpack production build for Rails'); // eslint-disable-line no-console
+}
diff --git a/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt b/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt
index 2966f1fbb3..d10792a97b 100644
--- a/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt
+++ b/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt
@@ -6,20 +6,13 @@ ReactOnRails.configure do |config|
config.generated_assets_dir = File.join(%w(app assets webpack))
# Define the files for we need to check for webpack compilation when running tests
- <%- if options.server_rendering? %>
- config.webpack_generated_files = %w( client-bundle.js server-bundle.js )
- <% else %>
- config.webpack_generated_files = %w( client-bundle.js )
- <%- end %>
+ config.webpack_generated_files = %w( webpack-bundle.js )
+
+ # This is the file used for server rendering.
+ # This only needs to be modified for advanced usage
+ # or if you change your webpack bundle file name.
+ config.server_bundle_js_file = "webpack-bundle.js"
- # Server rendering:
- # Server bundle is a single file for all server rendering of components.
- # Set the server_bundle_js_file to "" if you know that you will not be server rendering.
- <%- if options.server_rendering? %>
- config.server_bundle_js_file = "server-bundle.js"
- <% else %>
- config.server_bundle_js_file = ""
- <%- end %>
# increase if you're on JRuby
config.server_renderer_pool_size = 1
# seconds
diff --git a/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt b/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt
index 596a20652b..f29eda86a2 100644
--- a/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt
+++ b/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt
@@ -14,10 +14,7 @@ namespace :assets do
desc "Compile assets with webpack"
task :webpack do
- sh "cd client && npm run build:client"
- <%- if options[:server_rendering] -%>
- sh "cd client && npm run build:server"
- <%- end -%>
+ sh "cd client && npm run build"
end
task :clobber do
diff --git a/lib/generators/react_on_rails/templates/base/base/package.json.tt b/lib/generators/react_on_rails/templates/base/base/package.json.tt
index 2878d897e3..afd70f3891 100644
--- a/lib/generators/react_on_rails/templates/base/base/package.json.tt
+++ b/lib/generators/react_on_rails/templates/base/base/package.json.tt
@@ -8,18 +8,8 @@
"scripts": {
"postinstall": "cd client && npm install",
"rails-server": "echo 'visit http://localhost:3000/hello_world' && foreman start -f Procfile.dev",
- "build:production:client": "(cd client && npm run build:production:client --silent)",
- <%- if options.server_rendering? -%>
- "build:production:server": "(cd client && npm run build:production:server --silent)",
- <%- end -%>
- "build:client": "(cd client && npm run build:client --silent)",
- <%- if options.server_rendering? -%>
- "build:server": "(cd client && npm run build:server --silent)",
- <%- end -%>
- "build:dev:client": "(cd client && npm run build:dev:client --silent)",
- <%- if options.server_rendering? -%>
- "build:dev:server": "(cd client && npm run build:dev:server --silent)",
- <%- end -%>
+ "build": "(cd client && npm run build --silent)",
+ "build:dev": "(cd client && npm run build:dev --silent)",
"test": "rspec"
}
}
diff --git a/lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverRegistration.jsx b/lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverRegistration.jsx
deleted file mode 100644
index 4f1090e32e..0000000000
--- a/lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverRegistration.jsx
+++ /dev/null
@@ -1,4 +0,0 @@
-import ReactOnRails from 'react-on-rails';
-import HelloWorldApp from './HelloWorldAppServer';
-
-ReactOnRails.register({ HelloWorldApp });
diff --git a/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js b/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js
deleted file mode 100644
index d0e4212451..0000000000
--- a/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js
+++ /dev/null
@@ -1,39 +0,0 @@
-// Webpack configuration for server bundle
-
-const webpack = require('webpack');
-const path = require('path');
-
-const devBuild = process.env.NODE_ENV !== 'production';
-const nodeEnv = devBuild ? 'development' : 'production';
-
-module.exports = {
-
- // the project dir
- context: __dirname,
- entry: [
- 'babel-polyfill',
- './app/bundles/HelloWorld/startup/serverRegistration',
- ],
- output: {
- filename: 'server-bundle.js',
- path: '../app/assets/webpack',
- },
- resolve: {
- extensions: ['', '.js', '.jsx'],
- alias: {
- lib: path.join(process.cwd(), 'app', 'lib'),
- },
- },
- plugins: [
- new webpack.DefinePlugin({
- 'process.env': {
- NODE_ENV: JSON.stringify(nodeEnv),
- },
- }),
- ],
- module: {
- loaders: [
- { test: /\.jsx?$/, loader: 'babel-loader', exclude: /node_modules/ },
- ],
- },
-};
diff --git a/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/clientRegistration.jsx.tt b/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx.tt
similarity index 51%
rename from lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/clientRegistration.jsx.tt
rename to lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx.tt
index 1cbb1eb1fe..233830242b 100644
--- a/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/clientRegistration.jsx.tt
+++ b/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx.tt
@@ -1,5 +1,11 @@
+import React from 'react';
import ReactOnRails from 'react-on-rails';
-import HelloWorldApp from './HelloWorldAppClient';
+
+import HelloWorld from '../containers/HelloWorld';
+
+const HelloWorldApp = (props) => (
+
+);
// This is how react_on_rails can see the HelloWorldApp in the browser.
ReactOnRails.register({ HelloWorldApp });
diff --git a/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt b/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt
deleted file mode 100644
index 0e0ec41af0..0000000000
--- a/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt
+++ /dev/null
@@ -1,6 +0,0 @@
-import React from 'react';
-import HelloWorld from '../containers/HelloWorld';
-
-export default (props) => (
-
-);
diff --git a/lib/generators/react_on_rails/templates/no_redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx b/lib/generators/react_on_rails/templates/no_redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx
deleted file mode 100644
index 0e0ec41af0..0000000000
--- a/lib/generators/react_on_rails/templates/no_redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx
+++ /dev/null
@@ -1,6 +0,0 @@
-import React from 'react';
-import HelloWorld from '../containers/HelloWorld';
-
-export default (props) => (
-
-);
diff --git a/lib/generators/react_on_rails/templates/redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx b/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx.tt
similarity index 73%
rename from lib/generators/react_on_rails/templates/redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx
rename to lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx.tt
index 17a7cf5030..5cada08cf8 100644
--- a/lib/generators/react_on_rails/templates/redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx
+++ b/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx.tt
@@ -1,4 +1,5 @@
import React from 'react';
+import ReactOnRails from 'react-on-rails';
import { Provider } from 'react-redux';
import createStore from '../store/helloWorldStore';
@@ -7,8 +8,7 @@ import HelloWorld from '../containers/HelloWorld';
// See documentation for https://github.com/reactjs/react-redux.
// This is how you get props from the Rails view into the redux store.
// This code here binds your smart component to the redux store.
-// This is how the server redux gets hydrated with data.
-export default (props) => {
+const HelloWorldApp = (props) => {
const store = createStore(props);
const reactComponent = (
@@ -17,3 +17,6 @@ export default (props) => {
);
return reactComponent;
};
+
+// This is how react_on_rails can see the HelloWorldApp in the browser.
+ReactOnRails.register({ HelloWorldApp });
\ No newline at end of file
diff --git a/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt b/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt
deleted file mode 100644
index b469d6653e..0000000000
--- a/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt
+++ /dev/null
@@ -1,18 +0,0 @@
-import React from 'react';
-import { Provider } from 'react-redux';
-
-import createStore from '../store/helloWorldStore';
-import HelloWorld from '../containers/HelloWorld';
-
-// See documentation for https://github.com/reactjs/react-redux.
-// This is how you get props from the Rails view into the redux store.
-// This code here binds your smart component to the redux store.
-export default (props) => {
- const store = createStore(props);
- const reactComponent = (
-
-
-
- );
- return reactComponent;
-};
diff --git a/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx b/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx
index 872cd7a539..85d21edd58 100644
--- a/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx
+++ b/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx
@@ -6,10 +6,6 @@ import { compose, createStore, applyMiddleware, combineReducers } from 'redux';
// once your app has asynchronous actions.
import thunkMiddleware from 'redux-thunk';
-// This provides an example of logging redux actions to the console.
-// You'd want to disable this for production.
-import loggerMiddleware from 'lib/middlewares/loggerMiddleware';
-
import reducers from '../reducers';
import { initialStates } from '../reducers';
@@ -27,7 +23,7 @@ export default props => {
const reducer = combineReducers(reducers);
const composedStore = compose(
- applyMiddleware(thunkMiddleware, loggerMiddleware)
+ applyMiddleware(thunkMiddleware)
);
const storeCreator = composedStore(createStore);
const store = storeCreator(reducer, initialState);
diff --git a/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js b/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js
deleted file mode 100644
index 51f1de3db3..0000000000
--- a/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js
+++ /dev/null
@@ -1,21 +0,0 @@
-/* eslint no-console: 0 */
-
-// This logger should be configured not to run in a production environment.
-// See https://github.com/petehunt/webpack-howto#6-feature-flags for how you might turn this
-// off for production.
-export default function logger({ getState }) {
- return next => action => {
- console.log('will dispatch', action);
-
- // Call the next dispatch method in the middleware chain.
- const result = next(action);
-
- const immutableState = getState();
-
- console.log('state after dispatch', JSON.stringify(immutableState));
-
- // This will likely be the action itself, unless
- // a middleware further in chain changed it.
- return result;
- };
-}
diff --git a/lib/react_on_rails/configuration.rb b/lib/react_on_rails/configuration.rb
index c4965726d1..a3ea15df54 100644
--- a/lib/react_on_rails/configuration.rb
+++ b/lib/react_on_rails/configuration.rb
@@ -8,7 +8,7 @@ def self.configure
def self.setup_config_values
if @configuration.webpack_generated_files.empty?
- files = ["client-bundle.js"]
+ files = ["webpack-bundle.js"]
if @configuration.server_bundle_js_file.present?
files << @configuration.server_bundle_js_file
end
@@ -44,7 +44,6 @@ def self.configuration
# generated_assets_dirs is deprecated
generated_assets_dir: "",
-
server_bundle_js_file: "",
prerender: false,
replay_console: true,
diff --git a/rakelib/example_type.rb b/rakelib/example_type.rb
index fa3df2faac..49aea86704 100644
--- a/rakelib/example_type.rb
+++ b/rakelib/example_type.rb
@@ -28,10 +28,6 @@ def name_pretty
"#{@name} example app"
end
- def server_rendering?
- generator_options.include?("--server-rendering")
- end
-
def dir
File.join(examples_dir, name)
end
@@ -53,14 +49,12 @@ def node_modules_dir
end
def webpack_bundles_dir
- File.join(dir, "app", "assets", "javascripts", "generated")
+ File.join(dir, "app", "assets", "javascripts", "webpack")
end
def webpack_bundles
bundles = []
- bundles << File.join(webpack_bundles_dir, "app-bundle.js")
- bundles << File.join(webpack_bundles_dir, "server-bundle.js") if server_rendering?
- bundles << File.join(webpack_bundles_dir, "vendor-bundle.js")
+ bundles << File.join(webpack_bundles_dir, "webpack-bundle.js")
end
def gemfile
@@ -137,8 +131,7 @@ def clean_files
def build_webpack_bundles_shell_commands
webpack_command = File.join("$(npm bin)", "webpack")
shell_commands = []
- shell_commands << "#{webpack_command} --config webpack.server.rails.config.js" if server_rendering?
- shell_commands << "#{webpack_command} --config webpack.client.rails.config.js"
+ shell_commands << "#{webpack_command} --config webpack.config.js"
end
# Assumes we are inside a rails app's folder and necessary gems have been installed
diff --git a/rakelib/examples_config.yml b/rakelib/examples_config.yml
index 5962818814..043d6fb017 100644
--- a/rakelib/examples_config.yml
+++ b/rakelib/examples_config.yml
@@ -4,11 +4,11 @@ example_type_data:
generator_options: ""
-
name: basic-server-rendering
- generator_options: --server-rendering
+ generator_options: --example-server-rendering
-
name: redux
generator_options: --redux
-
name: redux-server-rendering
- generator_options: --redux --server-rendering
+ generator_options: --redux --example-server-rendering
diff --git a/spec/dummy/Gemfile.lock b/spec/dummy/Gemfile.lock
index 0d1ee06c52..8d7c341262 100644
--- a/spec/dummy/Gemfile.lock
+++ b/spec/dummy/Gemfile.lock
@@ -257,8 +257,9 @@ GEM
thread_safe (0.3.5)
tilt (2.0.2)
tins (1.6.0)
- turbolinks (2.5.3)
- coffee-rails
+ turbolinks (5.0.0.beta2)
+ turbolinks-source
+ turbolinks-source (5.0.0.beta4)
tzinfo (1.2.2)
thread_safe (~> 0.1)
uglifier (2.7.2)
@@ -311,7 +312,7 @@ DEPENDENCIES
spring
sqlite3
therubyracer
- turbolinks (= 2.5.3)
+ turbolinks (~> 5.0.0.beta2)
uglifier (>= 2.7.2)
web-console
diff --git a/spec/react_on_rails/generators/dev_tests_generator_spec.rb b/spec/react_on_rails/generators/dev_tests_generator_spec.rb
index a538e2de0e..1eed60ee81 100644
--- a/spec/react_on_rails/generators/dev_tests_generator_spec.rb
+++ b/spec/react_on_rails/generators/dev_tests_generator_spec.rb
@@ -3,43 +3,44 @@
describe DevTestsGenerator, type: :generator do
destination File.expand_path("../../dummy-for-generators/", __FILE__)
- before(:all) do
- run_generator_test_with_args(%w(),
- package_json: true,
- webpack_client_base_config: true,
- spec: false)
- end
+ context "without server rendering" do
+ before(:all) do
+ run_generator_test_with_args(%w(),
+ package_json: true,
+ webpack_client_base_config: true,
+ spec: false)
+ end
- it "copies rspec files" do
- %w(spec/spec_helper.rb
- spec/rails_helper.rb
- spec/simplecov_helper.rb
- .rspec).each { |file| assert_file(file) }
- end
+ it "copies rspec files" do
+ %w(spec/spec_helper.rb
+ spec/rails_helper.rb
+ spec/simplecov_helper.rb
+ .rspec).each { |file| assert_file(file) }
+ end
- it "copies tests" do
- %w(spec/features/hello_world_spec.rb).each { |file| assert_file(file) }
- end
+ it "copies tests" do
+ %w(spec/features/hello_world_spec.rb).each { |file| assert_file(file) }
+ end
- it "changes package.json to use local react-on-rails version of module" do
- assert_file("client/package.json") do |contents|
- assert_match('"react-on-rails": "../../../.."', contents)
- refute_match('"react-on-rails": "ReactOnRails::VERSION"', contents)
+ it "changes package.json to use local react-on-rails version of module" do
+ assert_file("client/package.json") do |contents|
+ assert_match('"react-on-rails": "../../../.."', contents)
+ refute_match('"react-on-rails": "ReactOnRails::VERSION"', contents)
+ end
end
- end
- it "adds test-related gems to Gemfile" do
- assert_file("Gemfile") do |contents|
- assert_match("gem 'rspec-rails', group: :test", contents)
- assert_match("gem 'capybara', group: :test", contents)
- assert_match("gem 'selenium-webdriver', group: :test", contents)
- assert_match("gem 'coveralls', require: false", contents)
- assert_match("gem 'poltergeist'", contents)
+ it "adds test-related gems to Gemfile" do
+ assert_file("Gemfile") do |contents|
+ assert_match("gem 'rspec-rails', group: :test", contents)
+ assert_match("gem 'capybara', group: :test", contents)
+ assert_match("gem 'selenium-webdriver', group: :test", contents)
+ assert_match("gem 'coveralls', require: false", contents)
+ assert_match("gem 'poltergeist'", contents)
+ end
end
- end
- it "changes the webpack.client.base.config.js to use a resolveLoader" do
- expected = <<-TEXT
+ it "changes the webpack.config.js to use a resolveLoader" do
+ expected = <<-TEXT
resolve: {
...
},
@@ -54,8 +55,25 @@
]
TEXT
- assert_file("client/webpack.client.base.config.js") do |contents|
- assert_match(expected, contents)
+ assert_file("client/webpack.config.js") do |contents|
+ assert_match(expected, contents)
+ end
+ end
+ end
+
+ context "with server-rendering" do
+ before(:all) do
+ run_generator_test_with_args(%w(--example-server-rendering),
+ package_json: true,
+ webpack_client_base_config: true,
+ spec: false,
+ hello_world_file: true)
+ end
+
+ it "adds prerender for examples with example-server-rendering" do
+ assert_file("app/views/hello_world/index.html.erb") do |contents|
+ assert_match("prerender: true", contents)
+ end
end
end
end
diff --git a/spec/react_on_rails/generators/install_generator_spec.rb b/spec/react_on_rails/generators/install_generator_spec.rb
index 325774a22c..5efacafac8 100644
--- a/spec/react_on_rails/generators/install_generator_spec.rb
+++ b/spec/react_on_rails/generators/install_generator_spec.rb
@@ -6,86 +6,40 @@
context "no args" do
before(:all) { run_generator_test_with_args(%w()) }
- include_examples "base_generator:base", application_js: true
- include_examples "base_generator:no_server_rendering"
- include_examples "no_redux_generator:base"
- include_examples "no_redux_generator:no_server_rendering"
- end
-
- context "--server-rendering" do
- before(:all) { run_generator_test_with_args(%w(--server-rendering)) }
- include_examples "base_generator:base", application_js: true
- include_examples "base_generator:server_rendering"
- include_examples "no_redux_generator:base"
- include_examples "no_redux_generator:server_rendering"
- end
-
- context "-S" do
- before(:all) { run_generator_test_with_args(%w(-S)) }
- include_examples "base_generator:base", application_js: true
- include_examples "base_generator:server_rendering"
- include_examples "no_redux_generator:base"
- include_examples "no_redux_generator:server_rendering"
+ include_examples "base_generator", application_js: true
+ include_examples "no_redux_generator"
end
context "--redux" do
before(:all) { run_generator_test_with_args(%w(--redux)) }
- include_examples "base_generator:base", application_js: true
- include_examples "base_generator:no_server_rendering"
- include_examples "react_with_redux_generator:base"
- include_examples "react_with_redux_generator:no_server_rendering"
+ include_examples "base_generator", application_js: true
+ include_examples "react_with_redux_generator"
end
context "-R" do
before(:all) { run_generator_test_with_args(%w(-R)) }
- include_examples "base_generator:base", application_js: true
- include_examples "base_generator:no_server_rendering"
- include_examples "react_with_redux_generator:base"
- include_examples "react_with_redux_generator:no_server_rendering"
- end
-
- context "--redux --server_rendering" do
- before(:all) { run_generator_test_with_args(%w(--redux --server-rendering)) }
- include_examples "base_generator:base", application_js: true
- include_examples "base_generator:server_rendering"
- include_examples "react_with_redux_generator:base"
- include_examples "react_with_redux_generator:server_rendering"
- end
-
- context "-R -S" do
- before(:all) { run_generator_test_with_args(%w(-R -S)) }
- include_examples "base_generator:base", application_js: true
- include_examples "base_generator:server_rendering"
- include_examples "react_with_redux_generator:base"
- include_examples "react_with_redux_generator:server_rendering"
- end
-
- context "-R -S" do
- before(:all) { run_generator_test_with_args(%w(-R -S)) }
- include_examples "base_generator:base", application_js: true
- include_examples "base_generator:server_rendering"
- include_examples "react_with_redux_generator:base"
- include_examples "react_with_redux_generator:server_rendering"
+ include_examples "base_generator", application_js: true
+ include_examples "react_with_redux_generator"
end
context "without existing application.js or application.js.coffee file" do
before(:all) { run_generator_test_with_args([], application_js: false) }
- include_examples "base_generator:base", application_js: false
+ include_examples "base_generator", application_js: false
end
context "with existing application.js or application.js.coffee file" do
before(:all) { run_generator_test_with_args([], application_js: true) }
- include_examples "base_generator:base", application_js: true
+ include_examples "base_generator", application_js: true
end
context "without existing assets.rb file" do
before(:all) { run_generator_test_with_args([], assets_rb: false) }
- include_examples "base_generator:base", assets_rb: false
+ include_examples "base_generator", assets_rb: false
end
context "with existing assets.rb file" do
before(:all) { run_generator_test_with_args([], assets_rb: true) }
- include_examples "base_generator:base", assets_rb: true
+ include_examples "base_generator", assets_rb: true
end
context "with rails_helper" do
diff --git a/spec/react_on_rails/support/generator_spec_helper.rb b/spec/react_on_rails/support/generator_spec_helper.rb
index edde76802c..0ab8a065c4 100644
--- a/spec/react_on_rails/support/generator_spec_helper.rb
+++ b/spec/react_on_rails/support/generator_spec_helper.rb
@@ -13,6 +13,12 @@
def simulate_existing_rails_files(options)
simulate_existing_file(".gitignore") if options.fetch(:gitignore, true)
+ if options.fetch(:hello_world_file, false)
+ simulate_existing_file(
+ "app/views/hello_world/index.html.erb",
+ "<%= react_component('HelloWorldApp', props: @hello_world_props) %>"
+ )
+ end
simulate_existing_file("Gemfile", "")
simulate_existing_file("config/routes.rb", "Rails.application.routes.draw do\nend\n")
simulate_existing_file("config/application.rb",
@@ -48,12 +54,12 @@ def simulate_existing_assets_files(options)
def simulate_npm_files(options)
if options.fetch(:package_json, false)
package_json = "client/package.json"
- package_json_data = ' "react-on-rails": "2.0.0-beta.1",'
+ package_json_data = ' "react-on-rails": "5.2.0",'
simulate_existing_file(package_json, package_json_data)
end
return unless options.fetch(:webpack_client_base_config, false)
- config = "client/webpack.client.base.config.js"
+ config = "client/webpack.config.js"
text = <<-TEXT
resolve: {
...
@@ -74,18 +80,6 @@ def run_generator_test_with_args(args, options = {})
run_generator(args + ["--ignore-warnings"])
end
-def assert_server_render_procfile
- assert_file "Procfile.dev" do |contents|
- assert_match(/\n\s*server:/, contents)
- end
-end
-
-def assert_client_render_procfile
- assert_file "Procfile.dev" do |contents|
- refute_match(/\n\s*server:/, contents)
- end
-end
-
# Simulate having an existing file for cases where the generator needs to modify, not create, a file
def simulate_existing_file(file, data = "some existing text\n")
# raise "File #{file} already exists in call to simulate_existing_file" if File.exist?(file)
diff --git a/spec/react_on_rails/support/shared_examples/base_generator_examples.rb b/spec/react_on_rails/support/shared_examples/base_generator_examples.rb
index 1e3c3080a2..8f8eec0cf0 100644
--- a/spec/react_on_rails/support/shared_examples/base_generator_examples.rb
+++ b/spec/react_on_rails/support/shared_examples/base_generator_examples.rb
@@ -1,4 +1,4 @@
-shared_examples "base_generator:base" do |options|
+shared_examples "base_generator" do |options|
it "adds a route for get 'hello_world' to 'hello_world#index'" do
match = <<-MATCH.strip_heredoc
Rails.application.routes.draw do
@@ -26,11 +26,7 @@
// DO NOT REQUIRE jQuery or jQuery-ujs in this file!
// DO NOT REQUIRE TREE!
- // CRITICAL that vendor-bundle must be BEFORE bootstrap-sprockets and turbolinks
- // since it is exposing jQuery and jQuery-ujs
-
- //= require vendor-bundle
- //= require app-bundle
+ //= require webpack-bundle
MATCH
assert_file("app/assets/javascripts/application.js") do |contents|
@@ -63,100 +59,25 @@
end
it "copies react files" do
+ # client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx
%w(app/controllers/hello_world_controller.rb
app/views/hello_world/index.html.erb
- client/REACT_ON_RAILS_CLIENT_README.md
- client/app/bundles/HelloWorld/startup/clientRegistration.jsx
- client/webpack.client.rails.config.js
+ client/webpack.config.js
client/.babelrc
client/package.json
config/initializers/react_on_rails.rb
package.json
- Procfile.dev
- REACT_ON_RAILS.md).each { |file| assert_file(file) }
+ Procfile.dev).each { |file| assert_file(file) }
end
it "appends path configurations to assets.rb" do
expected = ReactOnRails::Generators::BaseGenerator::ASSETS_RB_APPEND
assert_file("config/initializers/assets.rb") { |contents| assert_match(expected, contents) }
end
-end
-
-shared_examples "base_generator:no_server_rendering" do
- it "copies client-side-rendering version of Procfile.dev" do
- %w(Procfile.dev).each do |file|
- assert_file(file) do |contents|
- refute_match(/server: sh -c 'cd client && npm run build:dev:server'/, contents)
- end
- end
- end
-
- it "copies client-side-rendering version of hello_world/index.html.erb" do
- assert_file("app/views/hello_world/index.html.erb") do |contents|
- assert_match("prerender: false", contents)
- end
- end
-
- it "templates client-side-rendering version of webpack.client.base.js" do
- assert_file("client/webpack.client.base.config.js") do |contents|
- assert_match("clientRegistration", contents)
- end
- end
-
- it "doesn't add therubyracer to the Gemfile" do
- assert_file("Gemfile") do |contents|
- refute_match("gem 'therubyracer', platforms: :ruby", contents)
- end
- end
-
- it "doesn't copy server-side-rendering-only files" do
- %w(client/webpack.server.rails.config.js
- client/app/bundles/HelloWorld/startup/serverRegistration.jsx).each { |file| assert_no_file(file) }
- end
-
- it "sets server bundle js file to '' in react_on_rails initializer" do
- assert_file("config/initializers/react_on_rails.rb") do |contents|
- assert_match(/config.server_bundle_js_file = ""/, contents)
- end
- end
-end
-
-shared_examples "base_generator:server_rendering" do
- it "copies server-rendering-only files" do
- %w(client/webpack.server.rails.config.js
- client/app/bundles/HelloWorld/startup/serverRegistration.jsx).each { |file| assert_file(file) }
- end
-
- it "templates client-side-rendering version of webpack.client.base.js" do
- assert_file("client/webpack.client.base.config.js") do |contents|
- assert_match("clientRegistration", contents)
- end
- end
-
- it "copies server-side-rendering version of Procfile.dev" do
- %w(Procfile.dev).each do |file|
- assert_file(file) do |contents|
- assert_match(/server: sh -c 'cd client && npm run build:dev:server'/, contents)
- end
- end
- end
-
- it "copies the server-side-rendering version of hello_world/index.html.erb" do
- assert_file("app/views/hello_world/index.html.erb") do |contents|
- assert_match("prerender: true", contents)
- end
- end
-
- it "adds therubyracer to the Gemfile" do
- assert_file("Gemfile") do |contents|
- assert_match("gem 'therubyracer', platforms: :ruby", contents)
- end
- end
- it "sets server bundle js file to server-bundle in react_on_rails initializer" do
- regexp = /config.server_bundle_js_file = "server-bundle.js"/
- assert_file("config/initializers/react_on_rails.rb") do |contents|
- assert_match(regexp, contents)
+ it "templates HelloWorldApp into webpack.config.js" do
+ assert_file("client/webpack.config.js") do |contents|
+ assert_match("HelloWorldApp", contents)
end
end
end
diff --git a/spec/react_on_rails/support/shared_examples/react_no_redux_generator_examples.rb b/spec/react_on_rails/support/shared_examples/react_no_redux_generator_examples.rb
index 4c8045c6a3..e9a088bc1e 100644
--- a/spec/react_on_rails/support/shared_examples/react_no_redux_generator_examples.rb
+++ b/spec/react_on_rails/support/shared_examples/react_no_redux_generator_examples.rb
@@ -1,6 +1,9 @@
-shared_examples "no_redux_generator:base" do
+shared_examples "no_redux_generator" do
it "copies non-redux base files" do
assert_file("client/app/bundles/HelloWorld/containers/HelloWorld.jsx")
+ assert_file("client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx") do |contents|
+ assert_match("HelloWorld", contents)
+ end
end
it "does not place react folders in root" do
@@ -9,29 +12,3 @@
end
end
end
-
-shared_examples "no_redux_generator:no_server_rendering" do
- it "does not copy react server-rendering-specific files" do
- assert_no_file("client/webpack.server.rails.config.js")
- assert_no_file("client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx")
- end
-
- it "templates the client-side-rendering version of HelloWorldApp" do
- assert_file("client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx") do |contents|
- assert_match("HelloWorld", contents)
- end
- end
-end
-
-shared_examples "no_redux_generator:server_rendering" do
- it "copies the react server-rendering-specific files" do
- assert_file("client/webpack.server.rails.config.js")
- assert_file("client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx")
- end
-
- it "templates the server-side-rendering version of HelloWorldApp" do
- assert_file("client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx") do |contents|
- assert_match("HelloWorld", contents)
- end
- end
-end
diff --git a/spec/react_on_rails/support/shared_examples/react_with_redux_generator_examples.rb b/spec/react_on_rails/support/shared_examples/react_with_redux_generator_examples.rb
index 3857a5d7d3..1546dda2eb 100644
--- a/spec/react_on_rails/support/shared_examples/react_with_redux_generator_examples.rb
+++ b/spec/react_on_rails/support/shared_examples/react_with_redux_generator_examples.rb
@@ -1,7 +1,6 @@
-shared_examples "react_with_redux_generator:base" do
+shared_examples "react_with_redux_generator" do
it "creates redux directories" do
%w(actions constants reducers store).each { |dir| assert_directory("client/app/bundles/HelloWorld/#{dir}") }
- assert_directory("client/app/lib/middlewares")
end
it "copies base redux files" do
@@ -11,21 +10,6 @@
client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx
client/app/bundles/HelloWorld/reducers/index.jsx
client/app/bundles/HelloWorld/store/helloWorldStore.jsx
- client/app/lib/middlewares/loggerMiddleware.js
- client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx).each { |file| assert_file(file) }
- end
-end
-
-shared_examples "react_with_redux_generator:no_server_rendering" do
- it "does not template the server-side rendering files" do
- assert_no_file "client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx"
- end
-end
-
-shared_examples "react_with_redux_generator:server_rendering" do
- it "copies redux version of helloWorldAppServer.jsx" do
- assert_file("client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx") do |contents|
- assert_match(/import { Provider } from 'react-redux';/, contents)
- end
+ client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx).each { |file| assert_file(file) }
end
end