Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use webpacker_lite #387

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ vendor/ruby
.ruby-gemset

# Generated js bundles
/app/assets/webpack/
/public/webpack/

# Rubymine/IntelliJ
.idea
Expand Down
4 changes: 3 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ gem "sdoc", group: :doc
# Use Rails Html Sanitizer for HTML sanitization
gem "rails-html-sanitizer"

gem "react_on_rails", "6.9.3"
gem "react_on_rails", "8.0.0.beta.2"

gem "webpacker_lite", "1.0.0"

# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# mini_racer is probably faster than therubyracer
Expand Down
9 changes: 7 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ GEM
rb-inotify (0.9.8)
ffi (>= 0.5.0)
rdoc (4.3.0)
react_on_rails (6.9.3)
react_on_rails (8.0.0.beta.2)
addressable
connection_pool
execjs (~> 2.5)
Expand Down Expand Up @@ -288,6 +288,10 @@ GEM
activemodel (>= 5.0)
bindex (>= 0.4.0)
railties (>= 5.0)
webpacker_lite (1.0.0)
activesupport (>= 4.2)
multi_json (~> 1.2)
railties (>= 4.2)
websocket (1.2.4)
websocket-driver (0.6.5)
websocket-extensions (>= 0.1.0)
Expand Down Expand Up @@ -330,7 +334,7 @@ DEPENDENCIES
rails
rails-html-sanitizer
rainbow
react_on_rails (= 6.9.3)
react_on_rails (= 8.0.0.beta.2)
redis
rspec-rails (~> 3)
rspec-retry
Expand All @@ -344,6 +348,7 @@ DEPENDENCIES
spring-commands-rspec
uglifier
web-console
webpacker_lite (= 1.0.0)

RUBY VERSION
ruby 2.4.1p111
Expand Down
2 changes: 1 addition & 1 deletion Procfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
rails: REACT_ON_RAILS_ENV=HOT rails s -b 0.0.0.0

# Run the hot reload server for client development
hot-assets: sh -c 'rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && HOT_RAILS_PORT=3500 yarn run hot-assets'
hot-assets: sh -c 'rm -rf public/webpack/development || true && bundle exec rake react_on_rails:locale && HOT_RAILS_PORT=3500 yarn run hot-assets'

# Render static client assets
rails-static-client-assets: sh -c 'yarn run build:dev:client'
Expand Down
2 changes: 1 addition & 1 deletion Procfile.hot
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
rails: REACT_ON_RAILS_ENV=HOT rails s -b 0.0.0.0

# Run the hot reload server for client development
hot-assets: sh -c 'rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && HOT_RAILS_PORT=3500 yarn run hot-assets'
hot-assets: sh -c 'rm -rf public/webpack/development || true && bundle exec rake react_on_rails:locale && HOT_RAILS_PORT=3500 yarn run hot-assets'

# Keep the JS fresh for server rendering. Remove if not server rendering
rails-server-assets: sh -c 'yarn run build:dev:server'
2 changes: 1 addition & 1 deletion Procfile.static
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
rails: REACT_ON_RAILS_ENV= rails s -b 0.0.0.0

# Build client assets, watching for changes.
rails-client-assets: rm app/assets/webpack/* || true && bundle exec rake react_on_rails:locale && yarn run build:dev:client
rails-client-assets: rm -rf public/webpack/development || true && bundle exec rake react_on_rails:locale && yarn run build:dev:client

# Build server assets, watching for changes. Remove if not server rendering.
rails-server-assets: yarn run build:dev:server
17 changes: 5 additions & 12 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,13 @@
<head>
<title>RailsReactTutorial</title>

<%= env_stylesheet_link_tag(static: 'application_static',
hot: 'application_non_webpack',
media: 'all',
'data-turbolinks-track' => "reload") %>
<%= stylesheet_pack_tag(static: ['vendor-bundle', 'app-bundle'],
media: 'all',
'data-turbolinks-track': true) %>

<!-- These do not use turbolinks, so no data-turbolinks-track -->
<!-- This is to load the hot assets. -->
<%= env_javascript_include_tag(hot: ['http://localhost:3500/vendor-bundle.js',
'http://localhost:3500/app-bundle.js']) %>
<%= javascript_pack_tag('vendor-bundle', 'data-turbolinks-track': true) %>
<%= javascript_pack_tag('app-bundle', 'data-turbolinks-track': true) %>

<!-- These do use turbolinks -->
<%= env_javascript_include_tag(static: 'application_static',
hot: 'application_non_webpack',
'data-turbolinks-track' => "reload") %>
<%= csrf_meta_tags %>
</head>
<body>
Expand Down
2 changes: 1 addition & 1 deletion client/.babelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"presets": ["es2015", "stage-0", "react"]
"presets": ["es2015", "stage-2", "react"]
}
21 changes: 13 additions & 8 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@
"build:production:client": "NODE_ENV=production webpack --config webpack.client.rails.build.config.js",
"build:production:server": "NODE_ENV=production webpack --config webpack.server.rails.build.config.js",
"build:client": "webpack --config webpack.client.rails.build.config.js",
"build:dev:client": "webpack -w --config webpack.client.rails.build.config.js",
"build:dev:server": "webpack -w --config webpack.server.rails.build.config.js",
"build:dev:client": "NODE_ENV=development webpack -w --config webpack.client.rails.build.config.js",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kaizencodes Why are we setting the NODE_ENV for development?

"build:dev:server": "NODE_ENV=development webpack -w --config webpack.server.rails.build.config.js",
"build:server": "webpack --config webpack.server.rails.build.config.js",
"build:test": "yarn run build:client && yarn run build:server",
"build:production": "yarn run build:production:client && yarn run build:production:server",
"hot-assets": "babel-node server-rails-hot.js",
"build:test": "NODE_ENV=test yarn run build:client && NODE_ENV=test yarn run build:server",
"build:production": "NODE_ENV=production yarn run build:production:client && yarn run build:production:server",
"hot-assets": "NODE_ENV=development babel-node server-rails-hot.js",
"lint": "eslint --ext .js,.jsx ."
},
"dependencies": {
Expand All @@ -51,22 +51,25 @@
"babel-polyfill": "^6.23.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"babel-preset-stage-2": "^0.2.0",
"babel-runtime": "^6.23.0",
"bootstrap-loader": "^2.0.0",
"bootstrap-sass": "^3.3.7",
"classnames": "^2.2.5",
"compression-webpack-plugin": "^0.3.2",
"css-loader": "^0.28.0",
"es5-shim": "^4.5.9",
"estraverse": "^4.2.0",
"expose-loader": "^0.7.3",
"extract-text-webpack-plugin": "^2.1.0",
"file-loader": "^0.11.1",
"glob": "^7.1.1",
"immutable": "^3.8.1",
"imports-loader": "^0.7.1",
"intl": "^1.2.5",
"jquery": "^3.2.1",
"jquery-ujs": "^1.2.2",
"js-yaml": "^3.8.2",
"loader-utils": "^1.1.0",
"lodash": "^4.17.4",
"marked": "^0.3.6",
Expand All @@ -78,7 +81,7 @@
"react-bootstrap": "^0.30.8",
"react-dom": "^15.4.1",
"react-intl": "^2.2.2",
"react-on-rails": "^6.9.3",
"react-on-rails": "8.0.0-beta.1",
"react-redux": "^4.4.6",
"react-router": "^3.0.0",
"react-router-redux": "^4.0.7",
Expand All @@ -90,7 +93,9 @@
"style-loader": "^0.16.1",
"turbolinks": "^5.0.0",
"url-loader": "^0.5.8",
"webpack": "^2.3.3"
"webpack": "^2.3.3",
"webpack-manifest-plugin": "^1.1.0",
"webpack-merge": "^4.1.0"
},
"devDependencies": {
"babel-eslint": "^7.2.1",
Expand Down
16 changes: 11 additions & 5 deletions client/server-rails-hot.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
/* eslint no-var: 0, no-console: 0, import/no-extraneous-dependencies: 0 */

import webpack from 'webpack';

import WebpackDevServer from 'webpack-dev-server';

import webpackConfig from './webpack.client.rails.hot.config';

const hotRailsPort = process.env.HOT_RAILS_PORT || 3500;
const { resolve } = require('path');

const webpackConfigLoader = require('react-on-rails/webpackConfigLoader');

const configPath = resolve('..', 'config', 'webpack');
const { devServer: devServerConfig, publicPath } = webpackConfigLoader(configPath);

const compiler = webpack(webpackConfig);

const devServer = new WebpackDevServer(compiler, {
proxy: {
'*': `http://lvh.me:${hotRailsPort}`,
'*': `http://lvh.me:${devServerConfig.port}`,
},
publicPath: webpackConfig.output.publicPath,
publicPath,
hot: true,
inline: true,
historyApiFallback: true,
Expand All @@ -29,9 +35,9 @@ const devServer = new WebpackDevServer(compiler, {
},
});

devServer.listen(hotRailsPort, 'localhost', (err) => {
devServer.listen(devServerConfig.port, 'localhost', (err) => {
if (err) console.error(err);
console.log(
`=> 🔥 Webpack development server is running on port ${hotRailsPort}`,
`=> 🔥 Webpack development server is running on port ${devServerConfig.port}`,
);
});
41 changes: 31 additions & 10 deletions client/webpack.client.base.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,27 @@

// Common client-side webpack configuration used by webpack.hot.config and webpack.rails.config.
const webpack = require('webpack');
const path = require('path');

const { resolve } = require('path');

const ManifestPlugin = require('webpack-manifest-plugin');

const webpackConfigLoader = require('react-on-rails/webpackConfigLoader');

const configPath = resolve('..', 'config', 'webpack');
const { paths, publicPath } = webpackConfigLoader(configPath);

const devBuild = process.env.NODE_ENV !== 'production';
const nodeEnv = devBuild ? 'development' : 'production';

module.exports = {

// the project dir
context: __dirname,
context: resolve(__dirname),
entry: {

// See use of 'vendor' in the CommonsChunkPlugin inclusion below.
vendor: [
'vendor-bundle': [
'babel-polyfill',
'es5-shim/es5-shim',
'es5-shim/es5-sham',
Expand All @@ -41,17 +49,23 @@ module.exports = {
],

// This will contain the app entry points defined by webpack.hot.config and webpack.rails.config
app: [
'app-bundle': [
'./app/bundles/comments/startup/clientRegistration',
],
},

output: {
filename: '[name].js',
path: resolve('..', paths.output, paths.assets),
pathinfo: true,
},

resolve: {
extensions: ['.js', '.jsx'],
alias: {
libs: path.resolve(__dirname, 'app/libs'),
react: path.resolve(__dirname, 'node_modules/react'),
'react-dom': path.resolve(__dirname, 'node_modules/react-dom'),
},
modules: [
'client/app',
'client/node_modules',
],
},

plugins: [
Expand All @@ -66,7 +80,7 @@ module.exports = {
new webpack.optimize.CommonsChunkPlugin({

// This name 'vendor' ties into the entry definition
name: 'vendor',
name: 'vendor-bundle',

// We don't want the default vendor.js name
filename: 'vendor-bundle.js',
Expand All @@ -76,6 +90,11 @@ module.exports = {
minChunks: Infinity,

}),
new ManifestPlugin({
fileName: paths.manifest,
publicPath,
writeToFileEmit: true,
}),
],

module: {
Expand All @@ -89,6 +108,8 @@ module.exports = {
use: {
loader: 'url-loader',
options: {
publicPath,
name: '[name]-[hash].[ext]',
limit: 10000,
},
},
Expand Down
Loading