react_on_rails 5.1.1 → 5.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +14 -2
  3. data/README.md +3 -77
  4. data/docs/additional-reading/heroku-deployment.md +30 -0
  5. data/docs/contributor-info/contributing.md +11 -6
  6. data/docs/contributor-info/releasing.md +1 -1
  7. data/docs/tutorial.md +3 -1
  8. data/lib/generators/react_on_rails/base_generator.rb +0 -57
  9. data/lib/generators/react_on_rails/install_generator.rb +0 -28
  10. data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx.tt +8 -22
  11. data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +4 -54
  12. data/lib/generators/react_on_rails/templates/base/base/package.json.tt +5 -25
  13. data/lib/react_on_rails/version.rb +1 -1
  14. data/package.json +3 -3
  15. data/rakelib/examples_config.yml +1 -6
  16. metadata +2 -26
  17. data/lib/generators/react_on_rails/bootstrap_generator.rb +0 -86
  18. data/lib/generators/react_on_rails/heroku_deployment_generator.rb +0 -29
  19. data/lib/generators/react_on_rails/js_linters_generator.rb +0 -19
  20. data/lib/generators/react_on_rails/ruby_linters_generator.rb +0 -35
  21. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hot.tt +0 -4
  22. data/lib/generators/react_on_rails/templates/base/base/client/index.jade +0 -15
  23. data/lib/generators/react_on_rails/templates/base/base/client/server.js +0 -72
  24. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.hot.config.js.tt +0 -70
  25. data/lib/generators/react_on_rails/templates/base/base/lib/tasks/linters.rake.tt +0 -88
  26. data/lib/generators/react_on_rails/templates/bootstrap/app/assets/stylesheets/_bootstrap-custom.scss +0 -63
  27. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_post-bootstrap.scss +0 -10
  28. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_pre-bootstrap.scss +0 -8
  29. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_react-on-rails-sass-helper.scss +0 -19
  30. data/lib/generators/react_on_rails/templates/bootstrap/client/bootstrap-sass.config.js +0 -89
  31. data/lib/generators/react_on_rails/templates/heroku_deployment/Procfile +0 -1
  32. data/lib/generators/react_on_rails/templates/heroku_deployment/config/puma.rb +0 -15
  33. data/lib/generators/react_on_rails/templates/js_linters/client/.eslintignore +0 -1
  34. data/lib/generators/react_on_rails/templates/js_linters/client/.eslintrc +0 -48
  35. data/lib/generators/react_on_rails/templates/js_linters/client/.jscsrc +0 -18
  36. data/lib/generators/react_on_rails/templates/ruby_linters/.rubocop.yml +0 -27
  37. data/lib/generators/react_on_rails/templates/ruby_linters/.scss-lint.yml +0 -205
  38. data/lib/generators/react_on_rails/templates/ruby_linters/lib/tasks/brakeman.rake +0 -17
  39. data/lib/generators/react_on_rails/templates/ruby_linters/lib/tasks/ci.rake +0 -33
  40. data/lib/generators/react_on_rails/templates/ruby_linters/ruby-lint.yml.tt +0 -26
@@ -1,31 +1,12 @@
1
1
  <%- require "react_on_rails/version_syntax_converter" -%>
2
2
  {
3
3
  "name": "react-webpack-rails-tutorial",
4
- "version": "1.1.0",
5
- "description": "Built using the react_on_rails generator.",
6
- "main": "server.js",
4
+ "version": "0.0.1",
7
5
  "engines": {
8
- "node": "5.0.0",
6
+ "node": "5.10.0",
9
7
  "npm": "3.5.0"
10
8
  },
11
- "repository": {
12
- "type": "git",
13
- "url": "https://github.com/shakacode/react-webpack-rails-tutorial.git"
14
- },
15
- "keywords": [
16
- "react",
17
- "tutorial",
18
- "comment",
19
- "example"
20
- ],
21
- "author": "justin808",
22
- "license": "MIT",
23
- "bugs": {
24
- "url": "https://github.com/shakacode/react-webpack-rails-tutorial/issues"
25
- },
26
- "homepage": "https://github.com/shakacode/react-webpack-rails-tutorial",
27
9
  "scripts": {
28
- "start": "node server.js",
29
10
  "build:client": "NODE_ENV=production webpack --config webpack.client.rails.config.js",
30
11
  <%- if options.server_rendering? -%>
31
12
  "build:server": "NODE_ENV=production webpack --config webpack.server.rails.config.js",
@@ -38,11 +19,6 @@
38
19
  <%- if options.server_rendering? -%>
39
20
  "build:production:server": "NODE_ENV=production webpack --config webpack.server.rails.build.config.js",
40
21
  <%- end -%>
41
- <%- unless options.skip_js_linters? -%>
42
- "lint": "npm run eslint && npm run jscs",
43
- "eslint": "eslint --ext .js,.jsx .",
44
- "jscs": "jscs --verbose .",
45
- <%- end -%>
46
22
  "test": "echo \"Error: no test specified\" && exit 1"
47
23
  },
48
24
  "dependencies": {
@@ -71,11 +47,8 @@
71
47
  <%- if options.redux? -%>
72
48
  "mirror-creator": "1.1.0",
73
49
  <%- end -%>
74
- "react": "^0.14.8",
75
- <%- unless options.skip_bootstrap? -%>
76
- "react-bootstrap": "^0.28.5",
77
- <%- end -%>
78
- "react-dom": "^0.14.8",
50
+ "react": "^0.14.8 || ^15.0.0",
51
+ "react-dom": "^0.14.8 || ^15.0.0",
79
52
  "react-on-rails": "<%= VersionSyntaxConverter.new.rubygem_to_npm %>",
80
53
  <%- if options.redux? -%>
81
54
  "react-redux": "^4.4.1",
@@ -86,28 +59,5 @@
86
59
  "webpack": "^1.12.14"
87
60
  },
88
61
  "devDependencies": {
89
- "babel-plugin-react-transform": "^2.0.2",
90
- <%- unless options.skip_bootstrap? -%>
91
- "bootstrap-sass": "^3.3.6",
92
- "bootstrap-sass-loader": "^1.0.10",
93
- <%- end -%>
94
- "css-loader": "^0.23.1",
95
- <%- unless options.skip_js_linters? -%>
96
- "eslint": "^2.6.0",
97
- "eslint-config-shakacode": "^4.0.0",
98
- "eslint-plugin-react": "^4.2.3",
99
- <%- end -%>
100
- "express": "^4.13.4",
101
- "file-loader": "^0.8.5",
102
- "jade": "^1.11.0",
103
- <%- unless options.skip_js_linters? -%>
104
- "jscs": "^2.11.0",
105
- <%- end -%>
106
- "node-sass": "^3.4.2",
107
- "react-transform-hmr": "^1.0.4",
108
- "sass-loader": "^3.2.0",
109
- "style-loader": "^0.13.1",
110
- "url-loader": "^0.5.7",
111
- "webpack-dev-server": "^1.14.1"
112
62
  }
113
63
  }
@@ -1,15 +1,12 @@
1
1
  {
2
2
  "name": "react-webpack-rails-tutorial",
3
- "version": "1.1.1",
4
- "description": "Built using the react_on_rails generator. Allows you to run npm install from root.",
5
- "main": "server.js",
3
+ "version": "0.0.1",
6
4
  "engines": {
7
- "node": "4.2.0",
8
- "npm": "3.3.6"
5
+ "node": "5.10.0",
6
+ "npm": "3.5.0"
9
7
  },
10
8
  "scripts": {
11
9
  "postinstall": "cd client && npm install",
12
- "express-server": "echo 'visit http://localhost:4000' && cd client && npm start",
13
10
  "rails-server": "echo 'visit http://localhost:3000/hello_world' && foreman start -f Procfile.dev",
14
11
  "build:production:client": "(cd client && npm run build:production:client --silent)",
15
12
  <%- if options.server_rendering? -%>
@@ -23,23 +20,6 @@
23
20
  <%- if options.server_rendering? -%>
24
21
  "build:dev:server": "(cd client && npm run build:dev:server --silent)",
25
22
  <%- end -%>
26
- "test": "rspec && (cd client && npm run lint)"
27
- },
28
- "repository": {
29
- "type": "git",
30
- "url": "https://github.com/shakacode/react-webpack-rails-tutorial.git"
31
- },
32
- "keywords": [
33
- "react",
34
- "tutorial",
35
- "comment",
36
- "example"
37
- ],
38
- "author": "justin808",
39
- "license": "MIT",
40
- "bugs": {
41
- "url": "https://github.com/shakacode/react-webpack-rails-tutorial/issues"
42
- },
43
- "homepage": "https://github.com/shakacode/react-webpack-rails-tutorial",
44
- "dependencies": {}
23
+ "test": "rspec"
24
+ }
45
25
  }
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module ReactOnRails
3
- VERSION = "5.1.1".freeze
3
+ VERSION = "5.2.0".freeze
4
4
  end
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "5.1.1",
3
+ "version": "5.2.0",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
@@ -24,8 +24,8 @@
24
24
  "eslint-plugin-react": "^4.2.3",
25
25
  "jscs": "^2.11.0",
26
26
  "jsdom": "^8.2.0",
27
- "react": "^0.14.8",
28
- "react-dom": "^0.14.8",
27
+ "react": "^15.0.0",
28
+ "react-dom": "^15.0.0",
29
29
  "react-transform-hmr": "^1.0.4",
30
30
  "redux": "^3.3.1",
31
31
  "release-it": "^2.3.1",
@@ -11,9 +11,4 @@ example_type_data:
11
11
  -
12
12
  name: redux-server-rendering
13
13
  generator_options: --redux --server-rendering
14
- -
15
- name: heroku-deployment
16
- generator_options: --heroku-deployment
17
- -
18
- name: skip-bootstrap
19
- generator_options: --skip-bootstrap
14
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.1
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-04-05 00:00:00.000000000 Z
11
+ date: 2016-04-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -345,17 +345,12 @@ files:
345
345
  - docs/tutorial.md
346
346
  - lib/generators/USAGE
347
347
  - lib/generators/react_on_rails/base_generator.rb
348
- - lib/generators/react_on_rails/bootstrap_generator.rb
349
348
  - lib/generators/react_on_rails/dev_tests_generator.rb
350
349
  - lib/generators/react_on_rails/generator_helper.rb
351
350
  - lib/generators/react_on_rails/generator_messages.rb
352
- - lib/generators/react_on_rails/heroku_deployment_generator.rb
353
351
  - lib/generators/react_on_rails/install_generator.rb
354
- - lib/generators/react_on_rails/js_linters_generator.rb
355
352
  - lib/generators/react_on_rails/react_no_redux_generator.rb
356
353
  - lib/generators/react_on_rails/react_with_redux_generator.rb
357
- - lib/generators/react_on_rails/ruby_linters_generator.rb
358
- - lib/generators/react_on_rails/templates/base/base/Procfile.dev-hot.tt
359
354
  - lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt
360
355
  - lib/generators/react_on_rails/templates/base/base/REACT_ON_RAILS.md
361
356
  - lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rb
@@ -364,33 +359,19 @@ files:
364
359
  - lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md
365
360
  - lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx.tt
366
361
  - lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/clientRegistration.jsx.tt
367
- - lib/generators/react_on_rails/templates/base/base/client/index.jade
368
362
  - lib/generators/react_on_rails/templates/base/base/client/package.json.tt
369
- - lib/generators/react_on_rails/templates/base/base/client/server.js
370
363
  - lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js
371
- - lib/generators/react_on_rails/templates/base/base/client/webpack.client.hot.config.js.tt
372
364
  - lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js
373
365
  - lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt
374
366
  - lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt
375
- - lib/generators/react_on_rails/templates/base/base/lib/tasks/linters.rake.tt
376
367
  - lib/generators/react_on_rails/templates/base/base/package.json.tt
377
368
  - lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverRegistration.jsx
378
369
  - lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js
379
- - lib/generators/react_on_rails/templates/bootstrap/app/assets/stylesheets/_bootstrap-custom.scss
380
- - lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_post-bootstrap.scss
381
- - lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_pre-bootstrap.scss
382
- - lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_react-on-rails-sass-helper.scss
383
- - lib/generators/react_on_rails/templates/bootstrap/client/bootstrap-sass.config.js
384
370
  - lib/generators/react_on_rails/templates/dev_tests/.rspec
385
371
  - lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb
386
372
  - lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb
387
373
  - lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb
388
374
  - lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb
389
- - lib/generators/react_on_rails/templates/heroku_deployment/Procfile
390
- - lib/generators/react_on_rails/templates/heroku_deployment/config/puma.rb
391
- - lib/generators/react_on_rails/templates/js_linters/client/.eslintignore
392
- - lib/generators/react_on_rails/templates/js_linters/client/.eslintrc
393
- - lib/generators/react_on_rails/templates/js_linters/client/.jscsrc
394
375
  - lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx
395
376
  - lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt
396
377
  - lib/generators/react_on_rails/templates/no_redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx
@@ -403,11 +384,6 @@ files:
403
384
  - lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx
404
385
  - lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js
405
386
  - lib/generators/react_on_rails/templates/redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx
406
- - lib/generators/react_on_rails/templates/ruby_linters/.rubocop.yml
407
- - lib/generators/react_on_rails/templates/ruby_linters/.scss-lint.yml
408
- - lib/generators/react_on_rails/templates/ruby_linters/lib/tasks/brakeman.rake
409
- - lib/generators/react_on_rails/templates/ruby_linters/lib/tasks/ci.rake
410
- - lib/generators/react_on_rails/templates/ruby_linters/ruby-lint.yml.tt
411
387
  - lib/react_on_rails.rb
412
388
  - lib/react_on_rails/configuration.rb
413
389
  - lib/react_on_rails/controller.rb
@@ -1,86 +0,0 @@
1
- require "rails/generators"
2
- require_relative "generator_helper"
3
- require_relative "generator_messages"
4
-
5
- module ReactOnRails
6
- module Generators
7
- class BootstrapGenerator < Rails::Generators::Base
8
- include GeneratorHelper
9
- Rails::Generators.hide_namespace(namespace)
10
- source_root(File.expand_path("../templates", __FILE__))
11
-
12
- def copy_bootstrap_files
13
- base_path = "bootstrap/"
14
- %w(app/assets/stylesheets/_bootstrap-custom.scss
15
- client/assets/stylesheets/_post-bootstrap.scss
16
- client/assets/stylesheets/_pre-bootstrap.scss
17
- client/assets/stylesheets/_react-on-rails-sass-helper.scss
18
- client/bootstrap-sass.config.js).each { |file| copy_file(base_path + file, file) }
19
- end
20
-
21
- # if there still is not application.scss, just create one
22
- def create_application_scss_if_necessary
23
- path = File.join(destination_root, "app/assets/stylesheets/application.scss")
24
- return if File.exist?(path)
25
- File.open(path, "w") { |f| f.puts "// Created by React on Rails gem\n\n" }
26
- end
27
-
28
- def prepend_to_application_scss
29
- data = <<-DATA.strip_heredoc
30
- // DO NOT REQUIRE TREE! It will interfere with load order!
31
-
32
- // Account for differences between Rails and Webpack Sass code.
33
- $rails: true;
34
-
35
- // Included from bootstrap-sprockets gem and loaded in app/assets/javascripts/application.rb
36
- @import 'bootstrap-sprockets';
37
-
38
- // Customizations - needs to be imported after bootstrap-sprocket but before bootstrap-custom!
39
- // The _pre-bootstrap.scss file is located under
40
- // client/assets/stylesheets, which has been added to the Rails asset
41
- // pipeline search path. See config/application.rb.
42
- @import 'pre-bootstrap';
43
-
44
- // These scss files are located under client/assets/stylesheets
45
- // (which has been added to the Rails asset pipeline search path in config/application.rb).
46
- @import 'bootstrap-custom';
47
-
48
- // This must come after all the boostrap styles are loaded so that these styles can override those.
49
- @import 'post-bootstrap';
50
-
51
- DATA
52
-
53
- application_scss = File.join(destination_root, "app/assets/stylesheets/application.scss")
54
-
55
- append_to_file(application_scss, data)
56
- end
57
-
58
- def strip_application_scss_of_incompatible_sprockets_statements
59
- application_scss = File.join(destination_root, "app/assets/stylesheets/application.scss")
60
- gsub_file(application_scss, "*= require_tree .", "")
61
- gsub_file(application_scss, "*= require_self", "")
62
- end
63
-
64
- def add_bootstrap_sprockets_to_gemfile
65
- append_to_file("Gemfile", "\ngem 'bootstrap-sass'\n")
66
- end
67
-
68
- def add_bootstrap_sprockets_to_application_js
69
- data = <<-DATA.strip_heredoc
70
-
71
- // bootstrap-sprockets depends on vendor-bundle for jQuery.
72
- //= require bootstrap-sprockets
73
-
74
- DATA
75
-
76
- app_js_path = "app/assets/javascripts/application.js"
77
- found_app_js = dest_file_exists?(app_js_path) || dest_file_exists?(app_js_path + ".coffee")
78
- if found_app_js
79
- append_to_file(found_app_js, data)
80
- else
81
- create_file(app_js_path, data)
82
- end
83
- end
84
- end
85
- end
86
- end
@@ -1,29 +0,0 @@
1
- require "rails/generators"
2
- require_relative "generator_helper"
3
-
4
- module ReactOnRails
5
- module Generators
6
- class HerokuDeploymentGenerator < Rails::Generators::Base
7
- include GeneratorHelper
8
- Rails::Generators.hide_namespace(namespace)
9
- source_root(File.expand_path("../templates", __FILE__))
10
-
11
- def copy_heroku_deployment_files
12
- base_path = "heroku_deployment"
13
- %w(Procfile
14
- config/puma.rb).each { |file| copy_file("#{base_path}/#{file}", file) }
15
- end
16
-
17
- def add_heroku_production_gems
18
- gem_text = <<-GEMS.strip_heredoc
19
-
20
- # For Heroku deployment
21
- gem 'rails_12factor', group: :production
22
- gem 'puma', group: :production
23
-
24
- GEMS
25
- append_to_file("Gemfile", gem_text)
26
- end
27
- end
28
- end
29
- end
@@ -1,19 +0,0 @@
1
- require "rails/generators"
2
-
3
- module ReactOnRails
4
- module Generators
5
- class JsLintersGenerator < Rails::Generators::Base
6
- Rails::Generators.hide_namespace(namespace)
7
- source_root File.expand_path("../templates", __FILE__)
8
-
9
- # NOTE: linter modules are included via template in base/base/client/package.json.tt
10
-
11
- def copy_js_linter_config_files
12
- base_path = "js_linters/"
13
- %w(client/.eslintrc
14
- client/.eslintignore
15
- client/.jscsrc).each { |file| copy_file(base_path + file, file) }
16
- end
17
- end
18
- end
19
- end
@@ -1,35 +0,0 @@
1
- require "rails/generators"
2
- require_relative "generator_helper"
3
-
4
- module ReactOnRails
5
- module Generators
6
- class RubyLintersGenerator < Rails::Generators::Base
7
- include GeneratorHelper
8
- Rails::Generators.hide_namespace(namespace)
9
- source_root File.expand_path("../templates", __FILE__)
10
-
11
- def add_ruby_linter_gems_to_gemfile
12
- linter_gems = <<-GEMS.strip_heredoc
13
-
14
- # require: false is necessary for the linters as we only want them loaded
15
- # when used by the linting rake tasks.
16
- group :development do
17
- gem("rubocop", require: false)
18
- gem("ruby-lint", require: false)
19
- gem("scss_lint", require: false)
20
- end
21
- GEMS
22
- append_to_file("Gemfile", linter_gems)
23
- end
24
-
25
- def copy_ruby_linting_and_auditing_tasks
26
- base_path = "ruby_linters/"
27
- %w(lib/tasks/brakeman.rake
28
- lib/tasks/ci.rake
29
- .rubocop.yml
30
- .scss-lint.yml).each { |file| copy_file(base_path + file, file) }
31
- template("ruby_linters/ruby-lint.yml.tt", "ruby-lint.yml")
32
- end
33
- end
34
- end
35
- end
@@ -1,4 +0,0 @@
1
- web: rails s
2
- # TODO: MIGRATE from tutorial
3
- client: sh -c 'rm app/assets/webpack/* || true && cd client && npm run build:dev:client'
4
- <%- if options.server_rendering? %>server: sh -c 'cd client && npm run build:dev:server'<%- end %>
@@ -1,15 +0,0 @@
1
- doctype html
2
- html
3
-
4
- head
5
- title Hello, React
6
-
7
- body
8
-
9
- h1.alert.alert-info.this-works webpack dev server (with HMR)
10
- #app
11
-
12
- script(src="vendor-bundle.js")
13
- script(src="app-bundle.js")
14
- script.
15
- ReactOnRails.render("HelloWorldApp", {name: "Stranger"}, 'app');
@@ -1,72 +0,0 @@
1
- // This file is used by the webpack HMR dev server to load your component without using Rails
2
- // It should simply match routes to basic HTML or jade files that render your component
3
- /* eslint-disable no-console, func-names, no-var */
4
- var webpack = require('webpack');
5
- var WebpackDevServer = require('webpack-dev-server');
6
- var jade = require('jade');
7
- var config = require('./webpack.client.hot.config');
8
-
9
- const PORT = 4000;
10
- const compiler = webpack(config);
11
-
12
- var server = new WebpackDevServer(compiler, {
13
- publicPath: config.output.publicPath,
14
- hot: true,
15
- historyApiFallback: true,
16
- stats: {
17
- colors: true,
18
- hash: false,
19
- version: false,
20
- chunks: false,
21
- children: false,
22
- },
23
- });
24
-
25
- // The following code is commented out because the HelloWorld example
26
- // does not use any asynchronous functionality. It is meant to serve
27
- // as an example of how one might implement an API in express for their
28
- // webpack dev server
29
- // Note, it would be necessary to run `npm i --save body-parser sleep` for
30
- // the following to work:
31
- // var bodyParser = require('body-parser');
32
- // var sleep = require('sleep');
33
- // See tutorial for example of using AJAX:
34
- // https://github.com/shakacode/react-webpack-rails-tutorial
35
-
36
- // server.app.use(bodyParser.json(null));
37
- // server.app.use(bodyParser.urlencoded({extended: true}));
38
- // server.app.get('/hello_world.json', function(req, res) {
39
- // res.setHeader('Content-Type', 'application/json');
40
- // res.send(JSON.stringify(name));
41
- // });
42
-
43
- // server.app.post('/hello_world.json', function(req, res) {
44
- // console.log('Processing name: %j', req.body.name);
45
- // console.log('(shhhh...napping 1 seconds)');
46
- // sleep.sleep(1);
47
- // console.log('Just got done with nap!');
48
- // name = req.body.name;
49
- // res.setHeader('Content-Type', 'application/json');
50
- // res.send(JSON.stringify(req.body.name));
51
- // });
52
-
53
- var initialName = 'Stranger';
54
-
55
- server.app.use('/', (req, res) => {
56
- var locals = {
57
- props: JSON.stringify(initialName),
58
- };
59
- var layout = `${process.cwd()}/index.jade`;
60
- var html = jade.compileFile(layout, { pretty: true })(locals);
61
- res.send(html);
62
- });
63
-
64
- server.listen(PORT, 'localhost', err => {
65
- if (err) console.error(err);
66
- console.log(
67
- `=> 🔥 Webpack development server is running on port ${PORT}`
68
- );
69
- });
70
- compiler.plugin('done', () => {
71
- process.stdout.write('Webpack: Done compiling assets!\n');
72
- });