webpack_react_on_rails 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +29 -0
  4. data/lib/generators/webpack_react_on_rails/install_generator.rb +47 -0
  5. data/lib/tasks/webpack/compile.rake +13 -0
  6. data/lib/templates/package +38 -0
  7. data/lib/templates/webpack_development_config +44 -0
  8. data/lib/templates/webpack_initializer +12 -0
  9. data/lib/templates/webpack_production_config +46 -0
  10. data/lib/webpack_react_on_rails.rb +4 -0
  11. data/lib/webpack_react_on_rails/action_view/webpack_helpers.rb +24 -0
  12. data/lib/webpack_react_on_rails/railtie.rb +13 -0
  13. data/lib/webpack_react_on_rails/version.rb +3 -0
  14. data/test/dummy/README.rdoc +28 -0
  15. data/test/dummy/Rakefile +6 -0
  16. data/test/dummy/app/assets/javascripts/application.js +13 -0
  17. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  18. data/test/dummy/app/controllers/application_controller.rb +5 -0
  19. data/test/dummy/app/helpers/application_helper.rb +2 -0
  20. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  21. data/test/dummy/bin/bundle +3 -0
  22. data/test/dummy/bin/rails +4 -0
  23. data/test/dummy/bin/rake +4 -0
  24. data/test/dummy/bin/setup +29 -0
  25. data/test/dummy/config.ru +4 -0
  26. data/test/dummy/config/application.rb +25 -0
  27. data/test/dummy/config/boot.rb +5 -0
  28. data/test/dummy/config/database.yml +25 -0
  29. data/test/dummy/config/environment.rb +5 -0
  30. data/test/dummy/config/environments/development.rb +41 -0
  31. data/test/dummy/config/environments/production.rb +79 -0
  32. data/test/dummy/config/environments/test.rb +42 -0
  33. data/test/dummy/config/initializers/assets.rb +11 -0
  34. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  36. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  37. data/test/dummy/config/initializers/inflections.rb +16 -0
  38. data/test/dummy/config/initializers/mime_types.rb +4 -0
  39. data/test/dummy/config/initializers/session_store.rb +3 -0
  40. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  41. data/test/dummy/config/locales/en.yml +23 -0
  42. data/test/dummy/config/routes.rb +56 -0
  43. data/test/dummy/config/secrets.yml +22 -0
  44. data/test/dummy/db/development.sqlite3 +0 -0
  45. data/test/dummy/log/development.log +76 -0
  46. data/test/dummy/public/404.html +67 -0
  47. data/test/dummy/public/422.html +67 -0
  48. data/test/dummy/public/500.html +66 -0
  49. data/test/dummy/public/favicon.ico +0 -0
  50. data/test/react_redux_webpack_scaffolder_test.rb +7 -0
  51. data/test/test_helper.rb +20 -0
  52. metadata +152 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 766f5913515bf02700aaa8ea1051189f5127e81c
4
+ data.tar.gz: 6c80b1aef5e937754eb1a14c0880d7510fd7392a
5
+ SHA512:
6
+ metadata.gz: fce2950142224238c91afb22002727152aef1e9b20040d33df3bd561536a9aad1c57f7b078eb4435124d359f58a5ded920351a57987c8cad6ab46822a078aacb
7
+ data.tar.gz: 0c6f505d0cd7d148031f395987f53e81925f5d926ff5aabe689964e93cc8d6bc40dfcffcff0b7651ea4e81660dab8d9017119de4096021f8b347fc67a8b78175
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2016 Hyun Sik Kang
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,29 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'WebpackReactOnRails'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ Bundler::GemHelper.install_tasks
18
+
19
+ require 'rake/testtask'
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'lib'
23
+ t.libs << 'test'
24
+ t.pattern = 'test/**/*_test.rb'
25
+ t.verbose = false
26
+ end
27
+
28
+
29
+ task default: :test
@@ -0,0 +1,47 @@
1
+ require 'rails/generators'
2
+
3
+ module WebpackReactOnRails
4
+ class InstallGenerator < Rails::Generators::Base
5
+ TEMPLATES_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '../../templates')
6
+
7
+ def create_scaffold_file
8
+ generate_package_file('package', "#{Rails.root}/package.json")
9
+
10
+ generate_config_file('webpack_development_config', "#{Rails.root}/webpack_development.config.js")
11
+
12
+ generate_config_file('webpack_production_config', "#{Rails.root}/webpack_production.config.js")
13
+
14
+ generate_config_file('webpack_initializer', "#{Rails.root}/config/initializers/webpack.rb")
15
+
16
+ inject_into_file "config/application.rb", " config.webpack = {\n :use_manifest => false,\n :asset_manifest => {},\n :common_manifest => {}\n }\n", before: /^end/
17
+
18
+ inject_into_file "config/environments/production.rb", " config.webpack[:use_manifest] = true\n", before: /^end/
19
+
20
+ # Update .gitignore to include app/assets/javascripts, /node_modules
21
+ gitignore_path = File.join(Rails.root, '.gitignore')
22
+ File.open(gitignore_path, 'a+') do |f|
23
+ if !/\/node_modules\n/.match(f.read)
24
+ f.write "/public/assets/javascripts/bundle\n"
25
+ f.write "/node_modules\n"
26
+ end
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def rails_application_name
33
+ Rails.application.class.parent.to_s
34
+ end
35
+
36
+ def generate_package_file(template_name, file_path)
37
+ template = File.read(File.join(TEMPLATES_DIR, template_name))
38
+ template.gsub!('APPLICATION_NAME', rails_application_name)
39
+ create_file file_path, template
40
+ end
41
+
42
+ def generate_config_file(template_name, file_path)
43
+ template = File.read(File.join(TEMPLATES_DIR, template_name))
44
+ create_file file_path, template
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ namespace :webpack do
2
+ desc 'compile bundles using webpack'
3
+ task :compile do
4
+ cmd = 'node_modules/.bin/webpack --config ./webpack_production.config.js --json'
5
+ output = `#{cmd}`
6
+
7
+ stats = JSON.parse(output)
8
+
9
+ File.open('./public/assets/webpack-asset-manifest.json', 'w') do |f|
10
+ f.write stats['assetsByChunkName'].to_json
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "APPLICATION_NAME",
3
+ "description": "TODO: Add a brief description for the application",
4
+ "version": "1.0.0",
5
+ "babel": {
6
+ "presets": [
7
+ "es2015",
8
+ "react"
9
+ ],
10
+ "plugins": [
11
+ "transform-object-assign"
12
+ ]
13
+ },
14
+ "devDependencies": {
15
+ "react-hot-loader": "^1.3.0"
16
+ },
17
+ "dependencies": {
18
+ "babel-core": "^6.13.2",
19
+ "babel-loader": "^6.2.5",
20
+ "babel-preset-es2015": "^6.13.2",
21
+ "babel-preset-react": "^6.11.1",
22
+ "chunk-manifest-webpack-plugin": "^0.1.0",
23
+ "exports-loader": "~0.6.2",
24
+ "expose-loader": "~0.6.0",
25
+ "imports-loader": "~0.6.3",
26
+ "lodash": "~2.4.1",
27
+ "babel-plugin-transform-object-assign": "^6.8.0",
28
+ "immutable": "^3.8.1",
29
+ "isomorphic-fetch": "^2.2.1",
30
+ "react": "^15.3.1",
31
+ "react-dom": "^15.3.1",
32
+ "react-redux": "^4.4.5",
33
+ "react-router": "^2.8.0",
34
+ "redux": "^3.5.2",
35
+ "redux-thunk": "^2.1.0",
36
+ "webpack": "^1.4.13"
37
+ }
38
+ }
@@ -0,0 +1,44 @@
1
+ var path = require('path');
2
+ var webpack = require('webpack');
3
+
4
+ var config = module.exports = {
5
+ // the base path which will be used to resolve entry points
6
+ context: __dirname,
7
+
8
+ // the main entry point for our application's frontend js
9
+ // anything not required by this file will never end up in the compiled bundle
10
+ // passing an object provides multiple entries points
11
+ entry: {
12
+ webpackDev: 'webpack/hot/only-dev-server',
13
+ // The entry point for the application js i.e. './app/frontend/javascripts/app.js'
14
+ }
15
+ };
16
+
17
+ config.module = {
18
+ loaders: [{
19
+ test: /\.jsx?$/,
20
+ exclude: /node_modules/,
21
+ loader: 'babel'
22
+ }]
23
+ };
24
+
25
+ // this config dicates where compiled bundles end up
26
+ config.output = {
27
+ // this is our app/assets/javascripts directory, which is part of the Sprockets pipeline
28
+ path: path.join(__dirname, 'app', 'assets', 'javascript', 'bundle'),
29
+
30
+ // the filename of the compiled bundle, e.g. app/assets/javascripts/bundle.js
31
+ filename: '[name]-bundle.js',
32
+
33
+ // if the webpack code-splitting feature is enabled, this is the path it'll use to download bundles
34
+ publicPath: '/assets',
35
+ };
36
+
37
+ config.resolve = {
38
+ extensions: ['', '.js', '.jsx'],
39
+ modulesDirectories: ['node_modules'],
40
+ };
41
+
42
+ config.plugins = [
43
+ new webpack.HotModuleReplacementPlugin()
44
+ ];
@@ -0,0 +1,12 @@
1
+ if Rails.configuration.webpack[:use_manifest]
2
+ Rails.application.load_tasks
3
+ Rake::Task['webpack:compile'].invoke
4
+
5
+ asset_manifest = Rails.root.join('public', 'assets', 'webpack-asset-manifest.json')
6
+
7
+ if File.exist?(asset_manifest)
8
+ Rails.configuration.webpack[:asset_manifest] = JSON.parse(
9
+ File.read(asset_manifest),
10
+ ).with_indifferent_access
11
+ end
12
+ end
@@ -0,0 +1,46 @@
1
+ var path = require('path');
2
+ var webpack = require('webpack');
3
+ var ChunkManifestPlugin = require('chunk-manifest-webpack-plugin');
4
+
5
+ var config = module.exports = {
6
+ entry: {
7
+ // The entry point for the application js i.e. './app/frontend/javascripts/app.js'
8
+ }
9
+ };
10
+
11
+ config.module = {
12
+ loaders: [{
13
+ test: /\.jsx?$/,
14
+ exclude: /node_modules/,
15
+ loader: 'babel'
16
+ }]
17
+ };
18
+
19
+ config.output = {
20
+ path: path.join(__dirname, 'public', 'assets', 'bundle'),
21
+ filename: '[name]-bundle-[chunkhash].js',
22
+ chunkFilename: '[id]-bundle-[chunkhash].js'
23
+ };
24
+
25
+ config.resolve = {
26
+ extensions: ['', '.js', '.jsx'],
27
+ modulesDirectories: ['node_modules'],
28
+ };
29
+
30
+ config.plugins = [
31
+ new webpack.optimize.UglifyJsPlugin({
32
+ minimize: true,
33
+ compress: {
34
+ warnings: false
35
+ }
36
+ }),
37
+ new ChunkManifestPlugin({
38
+ filename: 'webpack-common-manifest.json',
39
+ manifestVariable: 'webpackBundleManifest'
40
+ }),
41
+ new webpack.DefinePlugin({
42
+ 'process.env': {
43
+ 'NODE_ENV': JSON.stringify('production')
44
+ }
45
+ })
46
+ ];
@@ -0,0 +1,4 @@
1
+ module WebpackReactOnRails
2
+ require 'webpack_react_on_rails/action_view/webpack_helpers'
3
+ require 'webpack_react_on_rails/railtie' if defined? Rails
4
+ end
@@ -0,0 +1,24 @@
1
+ module WebpackReactOnRails
2
+ module ActionView::WebpackHelpers
3
+ include ActionView::Helpers
4
+ include ActionView::Context
5
+
6
+ def webpack_bundle_tag(bundle)
7
+ if Rails.configuration.webpack[:use_manifest]
8
+ manifest = Rails.configuration.webpack[:asset_manifest]
9
+ filename = manifest[bundle]
10
+
11
+ src = "#{compute_asset_host}/assets/#{filename}"
12
+ else
13
+ src = "#{compute_asset_host}/assets/#{bundle}-bundle"
14
+ end
15
+
16
+ javascript_include_tag(src)
17
+ end
18
+
19
+ def webpack_manifest_script
20
+ return '' unless Rails.configuration.webpack[:use_manifest]
21
+ javascript_tag "window.webpackManifest = #{Rails.configuration.webpack[:common_manifest]}"
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ module WebpackReactOnRails
2
+ class Railtie < Rails::Railtie
3
+ initializer "railtie.configure_view_controller" do
4
+ ActiveSupport.on_load :action_view do
5
+ include ActionView::WebpackHelpers
6
+ end
7
+ end
8
+
9
+ rake_tasks do
10
+ load 'tasks/webpack/compile.rake'
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module WebpackReactOnRails
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end