-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix mini_racer build problems linux (rubyjs/mini_racer#218)
- Loading branch information
Showing
26 changed files
with
1,557 additions
and
32 deletions.
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 |
---|---|---|
|
@@ -65,3 +65,5 @@ end | |
gem "react_on_rails", "13.0.2" | ||
|
||
gem "shakapacker", "6.1.1" | ||
|
||
gem "mini_racer", "~> 0.6.2" |
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
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 @@ | ||
# Procfile for development using HMR | ||
# You can run these commands in separate shells | ||
rails: bundle exec rails s -p 3000 | ||
wp-client: HMR=true bin/webpacker-dev-server | ||
wp-server: HMR=true SERVER_BUNDLE_ONLY=yes bin/webpacker --watch |
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,9 @@ | ||
# You can run these commands in separate shells | ||
web: rails s -p 3000 | ||
|
||
# Next line runs a watch process with webpack to compile the changed files. | ||
# When making frequent changes to client side assets, you will prefer building webpack assets | ||
# upon saving rather than when you refresh your browser page. | ||
# Note, if using React on Rails localization you will need to run | ||
# `bundle exec rake react_on_rails:locale` before you run bin/webpacker | ||
webpack: sh -c 'rm -rf public/packs/* || true && bin/webpacker -w' |
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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
class HelloWorldController < ApplicationController | ||
layout "hello_world" | ||
|
||
def index | ||
@hello_world_props = { name: "Stranger" } | ||
end | ||
end |
26 changes: 26 additions & 0 deletions
26
app/javascript/bundles/HelloWorld/components/HelloWorld.jsx
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 @@ | ||
import PropTypes from 'prop-types'; | ||
import React, { useState } from 'react'; | ||
import style from './HelloWorld.module.css'; | ||
|
||
const HelloWorld = (props) => { | ||
const [name, setName] = useState(props.name); | ||
|
||
return ( | ||
<div> | ||
<h3>Hello, {name}!</h3> | ||
<hr /> | ||
<form> | ||
<label className={style.bright} htmlFor="name"> | ||
Say hello to: | ||
<input id="name" type="text" value={name} onChange={(e) => setName(e.target.value)} /> | ||
</label> | ||
</form> | ||
</div> | ||
); | ||
}; | ||
|
||
HelloWorld.propTypes = { | ||
name: PropTypes.string.isRequired, // this is passed from the Rails view | ||
}; | ||
|
||
export default HelloWorld; |
4 changes: 4 additions & 0 deletions
4
app/javascript/bundles/HelloWorld/components/HelloWorld.module.css
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,4 @@ | ||
.bright { | ||
color: green; | ||
font-weight: bold; | ||
} |
5 changes: 5 additions & 0 deletions
5
app/javascript/bundles/HelloWorld/components/HelloWorldServer.js
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 @@ | ||
import HelloWorld from './HelloWorld'; | ||
// This could be specialized for server rendering | ||
// For example, if using React-Router, we'd have the SSR setup here. | ||
|
||
export default HelloWorld; |
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,8 @@ | ||
import ReactOnRails from 'react-on-rails'; | ||
|
||
import HelloWorld from '../bundles/HelloWorld/components/HelloWorld'; | ||
|
||
// This is how react_on_rails can see the HelloWorld in the browser. | ||
ReactOnRails.register({ | ||
HelloWorld, | ||
}); |
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,8 @@ | ||
import ReactOnRails from 'react-on-rails'; | ||
|
||
import HelloWorld from '../bundles/HelloWorld/components/HelloWorldServer'; | ||
|
||
// This is how react_on_rails can see the HelloWorld in the browser. | ||
ReactOnRails.register({ | ||
HelloWorld, | ||
}); |
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,2 @@ | ||
<h1>Hello World</h1> | ||
<%= react_component("HelloWorld", props: @hello_world_props, prerender: false) %> |
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,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>ReactOnRailsWithWebpacker</title> | ||
<%= csrf_meta_tags %> | ||
<%= javascript_pack_tag 'hello-world-bundle' %> | ||
<%= stylesheet_pack_tag 'hello-world-bundle' %> | ||
</head> | ||
|
||
<body> | ||
<%= 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,33 @@ | ||
// The source code including full typescript support is available at: | ||
// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/babel.config.js | ||
|
||
module.exports = function (api) { | ||
const defaultConfigFunc = require('shakapacker/package/babel/preset.js') | ||
const resultConfig = defaultConfigFunc(api) | ||
const isProductionEnv = api.env('production') | ||
|
||
const changesOnDefault = { | ||
presets: [ | ||
[ | ||
'@babel/preset-react', | ||
{ | ||
development: !isProductionEnv, | ||
useBuiltIns: true | ||
} | ||
] | ||
].filter(Boolean), | ||
plugins: [ | ||
process.env.WEBPACK_SERVE && 'react-refresh/babel', | ||
isProductionEnv && ['babel-plugin-transform-react-remove-prop-types', | ||
{ | ||
removeImport: true | ||
} | ||
] | ||
].filter(Boolean), | ||
} | ||
|
||
resultConfig.presets = [...resultConfig.presets, ...changesOnDefault.presets] | ||
resultConfig.plugins = [...resultConfig.plugins, ...changesOnDefault.plugins ] | ||
|
||
return resultConfig | ||
} |
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,45 @@ | ||
# frozen_string_literal: true | ||
|
||
# See https://github.com/shakacode/react_on_rails/blob/master/docs/basics/configuration.md | ||
# for many more options. | ||
|
||
ReactOnRails.configure do |config| | ||
# This configures the script to run to build the production assets by webpack. Set this to nil | ||
# if you don't want react_on_rails building this file for you. | ||
# If nil, then the standard shakacode/shakapacker assets:precompile will run | ||
# config.build_production_command = nil | ||
|
||
################################################################################ | ||
################################################################################ | ||
# TEST CONFIGURATION OPTIONS | ||
# Below options are used with the use of this test helper: | ||
# ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config) | ||
################################################################################ | ||
|
||
# If you are using this in your spec_helper.rb (or rails_helper.rb): | ||
# | ||
# ReactOnRails::TestHelper.configure_rspec_to_compile_assets(config) | ||
# | ||
# with rspec then this controls what yarn command is run | ||
# to automatically refresh your webpack assets on every test run. | ||
# | ||
# Alternately, you can remove the `ReactOnRails::TestHelper.configure_rspec_to_compile_assets` | ||
# and set the config/webpacker.yml option for test to true. | ||
config.build_test_command = "RAILS_ENV=test bin/webpacker" | ||
|
||
################################################################################ | ||
################################################################################ | ||
# SERVER RENDERING OPTIONS | ||
################################################################################ | ||
# This is the file used for server rendering of React when using `(prerender: true)` | ||
# If you are never using server rendering, you should set this to "". | ||
# Note, there is only one server bundle, unlike JavaScript where you want to minimize the size | ||
# of the JS sent to the client. For the server rendering, React on Rails creates a pool of | ||
# JavaScript execution instances which should handle any component requested. | ||
# | ||
# While you may configure this to be the same as your client bundle file, this file is typically | ||
# different. You should have ONE server bundle which can create all of your server rendered | ||
# React components. | ||
# | ||
config.server_bundle_js_file = "server-bundle.js" | ||
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
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,18 @@ | ||
// The source code including full typescript support is available at: | ||
// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/clientWebpackConfig.js | ||
|
||
const commonWebpackConfig = require('./commonWebpackConfig'); | ||
|
||
const configureClient = () => { | ||
const clientConfig = commonWebpackConfig(); | ||
|
||
// server-bundle is special and should ONLY be built by the serverConfig | ||
// In case this entry is not deleted, a very strange "window" not found | ||
// error shows referring to window["webpackJsonp"]. That is because the | ||
// client config is going to try to load chunks. | ||
delete clientConfig.entry['server-bundle']; | ||
|
||
return clientConfig; | ||
}; | ||
|
||
module.exports = configureClient; |
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,16 @@ | ||
// The source code including full typescript support is available at: | ||
// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/commonWebpackConfig.js | ||
|
||
// Common configuration applying to client and server configuration | ||
const { webpackConfig: baseClientWebpackConfig, merge } = require('shakapacker'); | ||
|
||
const commonOptions = { | ||
resolve: { | ||
extensions: ['.css', '.ts', '.tsx'], | ||
}, | ||
}; | ||
|
||
// Copy the object using merge b/c the baseClientWebpackConfig and commonOptions are mutable globals | ||
const commonWebpackConfig = () => merge({}, baseClientWebpackConfig, commonOptions); | ||
|
||
module.exports = commonWebpackConfig; |
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 @@ | ||
// The source code including full typescript support is available at: | ||
// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/development.js | ||
|
||
const { devServer, inliningCss } = require('shakapacker'); | ||
|
||
const webpackConfig = require('./webpackConfig'); | ||
|
||
const developmentEnvOnly = (clientWebpackConfig, _serverWebpackConfig) => { | ||
// plugins | ||
if (inliningCss) { | ||
// Note, when this is run, we're building the server and client bundles in separate processes. | ||
// Thus, this plugin is not applied to the server bundle. | ||
|
||
// eslint-disable-next-line global-require | ||
const ReactRefreshWebpackPlugin = require('@pmmmwh/react-refresh-webpack-plugin'); | ||
clientWebpackConfig.plugins.push( | ||
new ReactRefreshWebpackPlugin({ | ||
overlay: { | ||
sockPort: devServer.port, | ||
}, | ||
}), | ||
); | ||
} | ||
}; | ||
|
||
module.exports = webpackConfig(developmentEnvOnly); |
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 @@ | ||
// The source code including full typescript support is available at: | ||
// https://github.com/shakacode/react_on_rails_demo_ssr_hmr/blob/master/config/webpack/production.js | ||
|
||
const webpackConfig = require('./webpackConfig'); | ||
|
||
const productionEnvOnly = (_clientWebpackConfig, _serverWebpackConfig) => { | ||
// place any code here that is for production only | ||
}; | ||
|
||
module.exports = webpackConfig(productionEnvOnly); |
Oops, something went wrong.