Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add webpack react and render default component
- Loading branch information
1 parent
08f495d
commit fcf3254
Showing
18 changed files
with
5,768 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
{ | ||
"presets": [ | ||
[ | ||
"env", | ||
{ | ||
"modules": false, | ||
"targets": { | ||
"browsers": "> 1%", | ||
"uglify": true | ||
}, | ||
"useBuiltIns": true | ||
} | ||
], | ||
"react" | ||
], | ||
"plugins": [ | ||
"syntax-dynamic-import", | ||
"transform-object-rest-spread", | ||
[ | ||
"transform-class-properties", | ||
{ | ||
"spec": true | ||
} | ||
] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,6 @@ bower.json | |
|
||
# Ignore DS_Store | ||
.DS_Store | ||
/public/packs | ||
/public/packs-test | ||
/node_modules |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
plugins: | ||
postcss-smart-import: {} | ||
postcss-cssnext: {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Static page controller | ||
class PagesController < ApplicationController | ||
def home | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/* eslint no-console:0 */ | ||
// This file is automatically compiled by Webpack, along with any other files | ||
// present in this directory. You're encouraged to place your actual application logic in | ||
// a relevant structure within app/javascript and only use these pack files to reference | ||
// that code so it'll be compiled. | ||
// | ||
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate | ||
// layout file, like app/views/layouts/application.html.erb | ||
|
||
console.log('Hello World from Webpacker') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Run this example by adding <%= javascript_pack_tag 'hello_react' %> to the head of your layout file, | ||
// like app/views/layouts/application.html.erb. All it does is render <div>Hello React</div> at the bottom | ||
// of the page. | ||
|
||
import React from 'react' | ||
import ReactDOM from 'react-dom' | ||
import PropTypes from 'prop-types' | ||
|
||
const Hello = props => ( | ||
<div>Hello {props.name}!</div> | ||
) | ||
|
||
Hello.defaultProps = { | ||
name: 'David' | ||
} | ||
|
||
Hello.propTypes = { | ||
name: PropTypes.string | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', () => { | ||
ReactDOM.render( | ||
<Hello name="React" />, | ||
document.body.appendChild(document.createElement('div')), | ||
) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
</head> | ||
|
||
<body> | ||
<%= javascript_pack_tag 'application' %> | ||
<%= yield %> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= javascript_pack_tag 'hello_react' %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#!/usr/bin/env ruby | ||
$stdout.sync = true | ||
|
||
require "shellwords" | ||
|
||
ENV["RAILS_ENV"] ||= "development" | ||
RAILS_ENV = ENV["RAILS_ENV"] | ||
|
||
ENV["NODE_ENV"] ||= RAILS_ENV | ||
NODE_ENV = ENV["NODE_ENV"] | ||
|
||
APP_PATH = File.expand_path("../", __dir__) | ||
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules") | ||
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js") | ||
|
||
unless File.exist?(WEBPACK_CONFIG) | ||
puts "Webpack configuration not found." | ||
puts "Please run bundle exec rails webpacker:install to install webpacker" | ||
exit! | ||
end | ||
|
||
env = { "NODE_PATH" => NODE_MODULES_PATH.shellescape } | ||
cmd = [ "#{NODE_MODULES_PATH}/.bin/webpack", "--config", WEBPACK_CONFIG ] + ARGV | ||
|
||
Dir.chdir(APP_PATH) do | ||
exec env, *cmd | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#!/usr/bin/env ruby | ||
$stdout.sync = true | ||
|
||
require "shellwords" | ||
require "yaml" | ||
require "socket" | ||
|
||
ENV["RAILS_ENV"] ||= "development" | ||
RAILS_ENV = ENV["RAILS_ENV"] | ||
|
||
ENV["NODE_ENV"] ||= RAILS_ENV | ||
NODE_ENV = ENV["NODE_ENV"] | ||
|
||
APP_PATH = File.expand_path("../", __dir__) | ||
CONFIG_FILE = File.join(APP_PATH, "config/webpacker.yml") | ||
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules") | ||
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js") | ||
|
||
DEFAULT_LISTEN_HOST_ADDR = NODE_ENV == 'development' ? 'localhost' : '0.0.0.0' | ||
|
||
def args(key) | ||
index = ARGV.index(key) | ||
index ? ARGV[index + 1] : nil | ||
end | ||
|
||
begin | ||
dev_server = YAML.load_file(CONFIG_FILE)[RAILS_ENV]["dev_server"] | ||
|
||
HOSTNAME = args('--host') || dev_server["host"] | ||
PORT = args('--port') || dev_server["port"] | ||
HTTPS = ARGV.include?('--https') || dev_server["https"] | ||
DEV_SERVER_ADDR = "http#{"s" if HTTPS}://#{HOSTNAME}:#{PORT}" | ||
LISTEN_HOST_ADDR = args('--listen-host') || DEFAULT_LISTEN_HOST_ADDR | ||
|
||
rescue Errno::ENOENT, NoMethodError | ||
$stdout.puts "Webpack dev_server configuration not found in #{CONFIG_FILE}." | ||
$stdout.puts "Please run bundle exec rails webpacker:install to install webpacker" | ||
exit! | ||
end | ||
|
||
begin | ||
server = TCPServer.new(LISTEN_HOST_ADDR, PORT) | ||
server.close | ||
|
||
rescue Errno::EADDRINUSE | ||
$stdout.puts "Another program is running on port #{PORT}. Set a new port in #{CONFIG_FILE} for dev_server" | ||
exit! | ||
end | ||
|
||
# Delete supplied host, port and listen-host CLI arguments | ||
["--host", "--port", "--listen-host"].each do |arg| | ||
ARGV.delete(args(arg)) | ||
ARGV.delete(arg) | ||
end | ||
|
||
env = { "NODE_PATH" => NODE_MODULES_PATH.shellescape } | ||
|
||
cmd = [ | ||
"#{NODE_MODULES_PATH}/.bin/webpack-dev-server", "--progress", "--color", | ||
"--config", WEBPACK_CONFIG, | ||
"--host", LISTEN_HOST_ADDR, | ||
"--public", "#{HOSTNAME}:#{PORT}", | ||
"--port", PORT.to_s | ||
] + ARGV | ||
|
||
Dir.chdir(APP_PATH) do | ||
exec env, *cmd | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
Rails.application.routes.draw do | ||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html | ||
root 'pages#home' | ||
namespace :api, defaults: { format: :json } do | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const environment = require('./environment') | ||
|
||
module.exports = environment.toWebpackConfig() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const { environment } = require('@rails/webpacker') | ||
|
||
module.exports = environment |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const environment = require('./environment') | ||
|
||
module.exports = environment.toWebpackConfig() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const environment = require('./environment') | ||
|
||
module.exports = environment.toWebpackConfig() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
# Note: You must restart bin/webpack-dev-server for changes to take effect | ||
|
||
default: &default | ||
source_path: app/javascript | ||
source_entry_path: packs | ||
public_output_path: packs | ||
cache_path: tmp/cache/webpacker | ||
|
||
# Additional paths webpack should lookup modules | ||
# ['app/assets', 'engine/foo/app/assets'] | ||
resolved_paths: [] | ||
|
||
# Reload manifest.json on all requests so we reload latest compiled packs | ||
cache_manifest: false | ||
|
||
extensions: | ||
- .coffee | ||
- .erb | ||
- .js | ||
- .jsx | ||
- .ts | ||
- .vue | ||
- .sass | ||
- .scss | ||
- .css | ||
- .png | ||
- .svg | ||
- .gif | ||
- .jpeg | ||
- .jpg | ||
|
||
development: | ||
<<: *default | ||
compile: true | ||
|
||
dev_server: | ||
host: localhost | ||
port: 8080 | ||
hmr: false | ||
https: false | ||
|
||
test: | ||
<<: *default | ||
compile: true | ||
|
||
# Compile test packs to a separate directory | ||
public_output_path: packs-test | ||
|
||
production: | ||
<<: *default | ||
|
||
# Production depends on precompilation of packs prior to booting for performance. | ||
compile: false | ||
|
||
# Cache manifest.json for performance | ||
cache_manifest: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,14 @@ | ||
{ | ||
"name": "rmi", | ||
"private": true, | ||
"dependencies": {} | ||
"dependencies": { | ||
"@rails/webpacker": "^3.0.1", | ||
"babel-preset-react": "^6.24.1", | ||
"prop-types": "^15.6.0", | ||
"react": "^16.0.0", | ||
"react-dom": "^16.0.0" | ||
}, | ||
"devDependencies": { | ||
"webpack-dev-server": "^2.8.2" | ||
} | ||
} |
Oops, something went wrong.