webpack_react_on_rails 1.0.3 → 1.0.4

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fb39b321561aab0c6d212638e275421d3faae851
4
- data.tar.gz: fe9c2785523a68139224dac135aa3255e7de18d6
3
+ metadata.gz: 29b605af265426460dd4e9e7c1763af73fce413a
4
+ data.tar.gz: 837c87c989797bdfd7c5d6f6e396bd61de0386ad
5
5
  SHA512:
6
- metadata.gz: 57719a6bd96ae8ace6bb14ec7feb1f446f9decac49c290923c8e8ad40bf0c2272aa8e56392b72919925b1750b013e7991c81772783931fe4f26bfca2b5520d50
7
- data.tar.gz: a3c37743ca9c2fa513d9a6bbf1cd0369fc7dac5c664aa2ca3295583fc32c974fe1fb57b33e13ff2fe7d6bedad178dd1c6da5dac3808c49ac65abb8b1ebbcf6f3
6
+ metadata.gz: bd36a55bbcfb1a16f433dfd7b4ac3b1d0c795ecc495aac3761fcf6e4d9e99cec32a2ea4cf0a0d006fffbbcd39e1332ff40295f819188b9a24dceef10a2752582
7
+ data.tar.gz: 0b6c754ed1769a4c1566d050bf6e047f9cad37693720d2f5ba33db9e8fb4f0404ea4aaf771bba09572a3701db1b28c4bb372103a021f6cb44f800c87b6912da6
@@ -2,20 +2,28 @@ require 'rails/generators'
2
2
 
3
3
  module WebpackReactOnRails
4
4
  class InstallGenerator < Rails::Generators::Base
5
- TEMPLATES_DIR = File.join(File.expand_path(File.dirname(__FILE__)), '../../templates')
5
+ source_root File.expand_path('../templates', __FILE__)
6
6
 
7
7
  def create_scaffold_file
8
- generate_package_file('package', "#{Rails.root}/package.json")
8
+ inside 'config' do
9
+ inject_into_file "application.rb", "\n config.webpack = {\n :use_manifest => false,\n :asset_manifest => {},\n :common_manifest => {}\n }\n", after: "class Application < Rails::Application"
9
10
 
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")
11
+ inside 'environments' do
12
+ inject_into_file "production.rb", " config.webpack[:use_manifest] = true\n", before: /^end/
13
+ end
13
14
 
14
- generate_config_file('webpack_initializer', "#{Rails.root}/config/initializers/webpack.rb")
15
+ inside 'initializers' do
16
+ copy_file "../../../templates/config/initializers/webpack.rb", "webpack.rb"
17
+ end
15
18
 
16
- inject_into_file "config/application.rb", "\n config.webpack = {\n :use_manifest => false,\n :asset_manifest => {},\n :common_manifest => {}\n }\n", after: "class Application < Rails::Application"
19
+ inside 'webpack' do
20
+ copy_file "../../../templates/config/webpack/main.config.js", "main.config.js"
21
+ copy_file "../../../templates/config/webpack/development.config.js", "development.config.js"
22
+ copy_file "../../../templates/config/webpack/production.config.js", "production.config.js"
23
+ end
24
+ end
17
25
 
18
- inject_into_file "config/environments/production.rb", " config.webpack[:use_manifest] = true\n", before: /^end/
26
+ copy_file "../templates/package.json", "./package.json"
19
27
 
20
28
  # Update .gitignore to include app/assets/javascripts, /node_modules
21
29
  gitignore_path = File.join(Rails.root, '.gitignore')
@@ -26,22 +34,5 @@ module WebpackReactOnRails
26
34
  end
27
35
  end
28
36
  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
37
  end
47
38
  end
@@ -0,0 +1,31 @@
1
+ var path = require('path');
2
+ var webpack = require('webpack');
3
+ var _ = require('lodash');
4
+ var config = module.exports = require('./main.config.js');
5
+
6
+ config = _.merge(config, {
7
+ debug: true,
8
+ displayErrorDetails: true,
9
+ outputPathinfo: true,
10
+ devtool: 'sourcemap',
11
+ });
12
+
13
+ config.entry = _.merge(config.entry, {
14
+ webpackDev: 'webpack/hot/only-dev-server',
15
+ });
16
+
17
+ // this config dicates where compiled bundles end up
18
+ config.output = _.merge(config.output, {
19
+ // this is our app/assets/javascripts directory, which is part of the Sprockets pipeline
20
+ path: path.join(__dirname, '../../app', 'assets', 'javascripts', 'bundle'),
21
+
22
+ // the filename of the compiled bundle, e.g. app/assets/javascripts/bundle.js
23
+ filename: '[name].js',
24
+
25
+ // if the webpack code-splitting feature is enabled, this is the path it'll use to download bundles
26
+ publicPath: '/assets',
27
+ });
28
+
29
+ config.plugins.push(
30
+ new webpack.HotModuleReplacementPlugin()
31
+ );
@@ -0,0 +1,32 @@
1
+ var path = require('path');
2
+ var webpack = require('webpack');
3
+
4
+ var config = module.exports = {
5
+ context: path.join(__dirname, '../', '../')
6
+ };
7
+
8
+ config.module = {
9
+ loaders: [{
10
+ test: /\.jsx?$/,
11
+ exclude: /node_modules/,
12
+ loader: 'babel'
13
+ }]
14
+ };
15
+
16
+ config.resolve = {
17
+ extensions: ['', '.js', '.jsx'],
18
+ modulesDirectories: ['node_modules'],
19
+ };
20
+
21
+ // the main entry point for our application's frontend js
22
+ // anything not required by this file will never end up in the compiled bundle
23
+ // passing an object provides multiple entries points
24
+ config.entry = {
25
+ // your entry points
26
+ };
27
+
28
+ config.output = {
29
+ // your outputs
30
+ // we'll be overriding some of these in the production config, to support
31
+ // writing out bundles with digests in their filename
32
+ }
@@ -1,33 +1,16 @@
1
1
  var path = require('path');
2
2
  var webpack = require('webpack');
3
3
  var ChunkManifestPlugin = require('chunk-manifest-webpack-plugin');
4
+ var _ = require('lodash');
5
+ var config = module.exports = require('./main.config.js');
4
6
 
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'),
7
+ config.output = _.merge(config.output, {
8
+ path: path.join(__dirname, '../../public', 'assets', 'bundle'),
21
9
  filename: '[name]-bundle-[chunkhash].js',
22
10
  chunkFilename: '[id]-bundle-[chunkhash].js'
23
- };
24
-
25
- config.resolve = {
26
- extensions: ['', '.js', '.jsx'],
27
- modulesDirectories: ['node_modules'],
28
- };
11
+ });
29
12
 
30
- config.plugins = [
13
+ config.plugins.push(
31
14
  new webpack.optimize.UglifyJsPlugin({
32
15
  minimize: true,
33
16
  compress: {
@@ -43,4 +26,4 @@ config.plugins = [
43
26
  'NODE_ENV': JSON.stringify('production')
44
27
  }
45
28
  })
46
- ];
29
+ );
@@ -1,7 +1,7 @@
1
1
  namespace :webpack do
2
2
  desc 'compile bundles using webpack'
3
3
  task :compile do
4
- cmd = 'node_modules/.bin/webpack --config ./webpack_production.config.js --json'
4
+ cmd = 'node_modules/.bin/webpack --config ./config/webpack/production.config.js --json'
5
5
  output = `#{cmd}`
6
6
 
7
7
  stats = JSON.parse(output)
@@ -13,7 +13,7 @@ module WebpackReactOnRails
13
13
 
14
14
  src = "#{compute_asset_host}/assets/#{path_name}"
15
15
  else
16
- src = "#{compute_asset_host}/assets/#{bundle}-bundle"
16
+ src = "#{compute_asset_host}/assets/#{bundle}"
17
17
  end
18
18
 
19
19
  javascript_include_tag(src)
@@ -1,3 +1,3 @@
1
1
  module WebpackReactOnRails
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -7,6 +7,12 @@ require "webpack_react_on_rails"
7
7
 
8
8
  module Dummy
9
9
  class Application < Rails::Application
10
+ config.webpack = {
11
+ :use_manifest => false,
12
+ :asset_manifest => {},
13
+ :common_manifest => {}
14
+ }
15
+
10
16
  # Settings in config/environments/* take precedence over those specified here.
11
17
  # Application configuration should go into files in config/initializers
12
18
  # -- all .rb files in that directory are automatically loaded.
File without changes
@@ -1,76 +0,0 @@
1
-
2
-
3
- Started GET "/" for ::1 at 2016-09-17 22:04:00 -0700
4
-
5
- Gem::LoadError (Specified 'sqlite3' for database adapter, but the gem is not loaded. Add `gem 'sqlite3'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).):
6
- activerecord (4.2.7.1) lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec'
7
- activerecord (4.2.7.1) lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
8
- activerecord (4.2.7.1) lib/active_record/connection_handling.rb:50:in `establish_connection'
9
- activerecord (4.2.7.1) lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
10
- activesupport (4.2.7.1) lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
11
- activesupport (4.2.7.1) lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
12
- activesupport (4.2.7.1) lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
13
- activesupport (4.2.7.1) lib/active_support/lazy_load_hooks.rb:44:in `each'
14
- activesupport (4.2.7.1) lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
15
- activerecord (4.2.7.1) lib/active_record/base.rb:315:in `<module:ActiveRecord>'
16
- activerecord (4.2.7.1) lib/active_record/base.rb:26:in `<top (required)>'
17
- activerecord (4.2.7.1) lib/active_record/migration.rb:383:in `connection'
18
- activerecord (4.2.7.1) lib/active_record/migration.rb:370:in `call'
19
- actionpack (4.2.7.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
20
- activesupport (4.2.7.1) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
21
- activesupport (4.2.7.1) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
22
- activesupport (4.2.7.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
23
- actionpack (4.2.7.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
24
- actionpack (4.2.7.1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
25
- actionpack (4.2.7.1) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
26
- actionpack (4.2.7.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
27
- actionpack (4.2.7.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
28
- railties (4.2.7.1) lib/rails/rack/logger.rb:38:in `call_app'
29
- railties (4.2.7.1) lib/rails/rack/logger.rb:20:in `block in call'
30
- activesupport (4.2.7.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
31
- activesupport (4.2.7.1) lib/active_support/tagged_logging.rb:26:in `tagged'
32
- activesupport (4.2.7.1) lib/active_support/tagged_logging.rb:68:in `tagged'
33
- railties (4.2.7.1) lib/rails/rack/logger.rb:20:in `call'
34
- actionpack (4.2.7.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
35
- rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
36
- rack (1.6.4) lib/rack/runtime.rb:18:in `call'
37
- activesupport (4.2.7.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
38
- rack (1.6.4) lib/rack/lock.rb:17:in `call'
39
- actionpack (4.2.7.1) lib/action_dispatch/middleware/static.rb:120:in `call'
40
- rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
41
- railties (4.2.7.1) lib/rails/engine.rb:518:in `call'
42
- railties (4.2.7.1) lib/rails/application.rb:165:in `call'
43
- rack (1.6.4) lib/rack/lock.rb:17:in `call'
44
- rack (1.6.4) lib/rack/content_length.rb:15:in `call'
45
- rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
46
- /Users/hskang/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
47
- /Users/hskang/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
48
- /Users/hskang/.rvm/rubies/ruby-2.2.1/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'
49
-
50
-
51
- Rendered /Users/hskang/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (3.7ms)
52
- Rendered /Users/hskang/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (2.2ms)
53
- Rendered /Users/hskang/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (0.8ms)
54
- Rendered /Users/hskang/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/diagnostics.html.erb within rescues/layout (63.3ms)
55
-
56
-
57
- Started GET "/" for ::1 at 2016-09-17 22:04:28 -0700
58
- Processing by Rails::WelcomeController#index as HTML
59
- Rendered /Users/hskang/.rvm/gems/ruby-2.2.1/gems/railties-4.2.7.1/lib/rails/templates/rails/welcome/index.html.erb (1.7ms)
60
- Completed 200 OK in 17ms (Views: 17.3ms | ActiveRecord: 0.0ms)
61
-
62
-
63
- Started GET "/" for ::1 at 2016-09-17 22:05:57 -0700
64
- Processing by IndexController#index as HTML
65
- Rendered index/index.html.erb within layouts/application (6.0ms)
66
- Completed 500 Internal Server Error in 26ms (ActiveRecord: 0.0ms)
67
-
68
- ActionView::Template::Error (undefined method `webpack' for #<Rails::Application::Configuration:0x007fc3b227f470>):
69
- 1: <%= webpack_bundle_tag 'index' %>
70
- app/views/index/index.html.erb:1:in `_app_views_index_index_html_erb__853855545836545768_70239244771960'
71
-
72
-
73
- Rendered /Users/hskang/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_source.erb (8.4ms)
74
- Rendered /Users/hskang/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.7ms)
75
- Rendered /Users/hskang/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (11.0ms)
76
- Rendered /Users/hskang/.rvm/gems/ruby-2.2.1/gems/actionpack-4.2.7.1/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (74.8ms)