-
-
Notifications
You must be signed in to change notification settings - Fork 631
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update the install generator to add Webpacker configuration (#1404)
* Default install includes sample configuration including SSR with HMR * Supports Rails 7
- Loading branch information
Showing
52 changed files
with
3,167 additions
and
4,012 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
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
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
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
--- | ||
extends: eslint-config-shakacode | ||
extends: | ||
- eslint-config-shakacode | ||
- prettier | ||
|
||
plugins: | ||
- react | ||
|
12 changes: 4 additions & 8 deletions
12
lib/generators/react_on_rails/templates/base/base/Procfile.dev
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,9 +1,5 @@ | ||
# Procfile for development using HMR | ||
# 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/webpack | ||
client: sh -c 'rm -rf public/packs/* || true && bin/webpack -w' | ||
rails: bundle exec rails s -p 3000 | ||
wp-client: HMR=true bin/webpack-dev-server | ||
wp-server: HMR=true SERVER_BUNDLE_ONLY=yes bin/webpack --watch |
26 changes: 0 additions & 26 deletions
26
lib/generators/react_on_rails/templates/base/base/Procfile.dev-hmr
This file was deleted.
Oops, something went wrong.
9 changes: 9 additions & 0 deletions
9
lib/generators/react_on_rails/templates/base/base/Procfile.dev-static
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/webpack | ||
webpack: sh -c 'rm -rf public/packs/* || true && bin/webpack -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
4 changes: 4 additions & 0 deletions
4
...ls/templates/base/base/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
...ails/templates/base/base/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; |
8 changes: 8 additions & 0 deletions
8
lib/generators/react_on_rails/templates/base/base/app/javascript/packs/server-bundle.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,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
15 changes: 15 additions & 0 deletions
15
lib/generators/react_on_rails/templates/base/base/babel.config.js.tt
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,15 @@ | ||
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/babel.config.js") %> | ||
|
||
const defaultConfigFunc = require('@rails/webpacker/package/babel/preset.js'); | ||
|
||
module.exports = function (api) { | ||
const resultConfig = defaultConfigFunc(api); | ||
|
||
const changesOnDefault = { | ||
plugins: [process.env.WEBPACK_SERVE && 'react-refresh/babel'].filter(Boolean), | ||
}; | ||
|
||
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
17 changes: 17 additions & 0 deletions
17
lib/generators/react_on_rails/templates/base/base/config/webpack/clientWebpackConfig.js.tt
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,17 @@ | ||
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/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; |
15 changes: 15 additions & 0 deletions
15
lib/generators/react_on_rails/templates/base/base/config/webpack/commonWebpackConfig.js.tt
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,15 @@ | ||
<%= add_documentation_reference(config[:message], "// https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh/blob/master/config/webpack/commonWebpackConfig.js") %> | ||
|
||
// Common configuration applying to client and server configuration | ||
const { webpackConfig: baseClientWebpackConfig, merge } = require('@rails/webpacker'); | ||
|
||
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; |
Oops, something went wrong.