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

Nix yarn binstub #367

Merged
merged 3 commits into from
May 12, 2017
Merged
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
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ that's been made default from that version forward.
* Ruby 2.2+
* Rails 4.2+
* Node.js 6.4.0+
* Yarn
* Yarn 0.20.1+

## Installation

Expand All @@ -42,9 +42,6 @@ You can also see a list of available commands by running `./bin/rails webpacker`
Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`.
They're thin wrappers around the standard webpack.js executable, just to ensure that the right configuration file is loaded depending on your environment.

A binstub is also created to install your npm dependencies,
and can be called via `./bin/yarn`.

In development, you'll need to run `./bin/webpack-dev-server` in a separate terminal from `./bin/rails server` to have your `app/javascript/packs/*.js` files compiled as you make changes. If you'd rather not have to run the two processes separately by hand, you can use [Foreman](https://ddollar.github.io/foreman). `./bin/webpack-dev-server` launches the [Webpack Dev Server](https://webpack.js.org/configuration/dev-server/), which serves your pack files on http://localhost:8080/, and provides advanced Webpack features, such as [Hot Module Replacement](https://webpack.js.org/guides/hmr-react/).

## Configuration
Expand Down
2 changes: 1 addition & 1 deletion lib/install/angular.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
copy_file "#{__dir__}/examples/angular/tsconfig.json", "tsconfig.json"

puts "Installing all angular dependencies"
run "#{RbConfig.ruby} ./bin/yarn add typescript ts-loader core-js zone.js rxjs @angular/core @angular/common @angular/compiler @angular/platform-browser @angular/platform-browser-dynamic"
run "yarn add typescript ts-loader core-js zone.js rxjs @angular/core @angular/common @angular/compiler @angular/platform-browser @angular/platform-browser-dynamic"

puts "Webpacker now supports angular and typescript 🎉"
6 changes: 3 additions & 3 deletions lib/install/bin/webpack-dev-server.tt
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ begin
NODE_MODULES_PATH = File.join(APP_PATH.shellescape, paths["node_modules"])
WEBPACK_CONFIG_PATH = File.join(APP_PATH.shellescape, paths["config"])

WEBPACK_BIN = "#{NODE_MODULES_PATH}/.bin/webpack-dev-server"
DEV_SERVER_CONFIG = "#{WEBPACK_CONFIG_PATH}/development.server.js"
rescue Errno::ENOENT, NoMethodError
puts "Configuration not found in config/webpacker/paths.yml."
puts "Please run bundle exec rails webpacker:install to install webpacker"
exit!
end

DEV_SERVER_BIN = "yarn run webpack-dev-server"
newenv = { "NODE_PATH" => NODE_MODULES_PATH }
cmdline = [WEBPACK_BIN, "--progress", "--color", "--config", DEV_SERVER_CONFIG] + ARGV
cmdline = [DEV_SERVER_BIN, "--", "--progress", "--color", "--config", DEV_SERVER_CONFIG] + ARGV

Dir.chdir(APP_PATH) do
exec newenv, *cmdline
exec newenv, cmdline.join(' ')
end
10 changes: 5 additions & 5 deletions lib/install/bin/webpack.tt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ require "shellwords"
require "yaml"

ENV["RAILS_ENV"] ||= "development"
RAILS_ENV = ENV["RAILS_ENV"]
RAILS_ENV = ENV["RAILS_ENV"]

ENV["NODE_ENV"] ||= RAILS_ENV
NODE_ENV = ENV["NODE_ENV"]
NODE_ENV = ENV["NODE_ENV"]

APP_PATH = File.expand_path("../", __dir__)
CONFIG_PATH = File.join(APP_PATH, "config/webpack/paths.yml")
Expand All @@ -24,12 +24,12 @@ rescue Errno::ENOENT, NoMethodError
exit!
end

WEBPACK_BIN = "#{NODE_MODULES_PATH}/.bin/webpack"
WEBPACK_BIN = "yarn run webpack"
WEBPACK_CONFIG = "#{WEBPACK_CONFIG_PATH}/#{NODE_ENV}.js"

newenv = { "NODE_PATH" => NODE_MODULES_PATH }
cmdline = [WEBPACK_BIN, "--config", WEBPACK_CONFIG] + ARGV
cmdline = [WEBPACK_BIN, "--", "--config", WEBPACK_CONFIG] + ARGV

Dir.chdir(APP_PATH) do
exec newenv, *cmdline
exec newenv, cmdline.join(' ')
end
11 changes: 0 additions & 11 deletions lib/install/bin/yarn.tt

This file was deleted.

4 changes: 2 additions & 2 deletions lib/install/elm.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
"#{Webpacker::Configuration.entry_path}/hello_elm.js"

puts "Installing all elm dependencies"
run "#{RbConfig.ruby} ./bin/yarn add elm"
run "#{RbConfig.ruby} ./bin/yarn add --dev elm-hot-loader elm-webpack-loader"
run "yarn add elm"
run "yarn add --dev elm-hot-loader elm-webpack-loader"
run "yarn run elm package install -- --yes"

puts "Updating Webpack paths to include Elm file extension"
Expand Down
2 changes: 1 addition & 1 deletion lib/install/react.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
copy_file "#{__dir__}/examples/react/hello_react.jsx", "#{Webpacker::Configuration.entry_path}/hello_react.jsx"

puts "Installing all react dependencies"
run "#{RbConfig.ruby} ./bin/yarn add react react-dom babel-preset-react prop-types"
run "yarn add react react-dom babel-preset-react prop-types"

puts "Webpacker now supports react.js 🎉"
12 changes: 3 additions & 9 deletions lib/install/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@
directory "#{__dir__}/javascript", "#{Webpacker::Configuration.source}"

puts "Copying binstubs"
template "#{__dir__}/bin/webpack-dev-server", "bin/webpack-dev-server"
template "#{__dir__}/bin/webpack", "bin/webpack"

if !File.exist?("bin/yarn")
puts "Copying yarn"
template "#{__dir__}/bin/yarn", "bin/yarn"
end
directory "#{__dir__}/bin", "bin"

chmod "bin", 0755 & ~File.umask, verbose: false

Expand All @@ -29,13 +23,13 @@
end

puts "Installing all JavaScript dependencies"
run "#{RbConfig.ruby} ./bin/yarn add webpack webpack-merge js-yaml path-complete-extname " \
run "yarn add webpack webpack-merge js-yaml path-complete-extname " \
"webpack-manifest-plugin [email protected] coffee-loader coffee-script " \
"babel-core babel-preset-env compression-webpack-plugin rails-erb-loader glob " \
"extract-text-webpack-plugin node-sass file-loader sass-loader css-loader style-loader " \
"postcss-loader autoprefixer postcss-smart-import precss"

puts "Installing dev server for live reloading"
run "#{RbConfig.ruby} ./bin/yarn add --dev webpack-dev-server"
run "yarn add --dev webpack-dev-server"

puts "Webpacker successfully installed 🎉 🍰"
2 changes: 1 addition & 1 deletion lib/install/vue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@
copy_file "#{__dir__}/examples/vue/app.vue", "#{Webpacker::Configuration.entry_path}/app.vue"

puts "Installing all vue dependencies"
run "#{RbConfig.ruby} ./bin/yarn add vue vue-loader vue-template-compiler"
run "yarn add vue vue-loader vue-template-compiler"

puts "Webpacker now supports vue.js 🎉"
4 changes: 2 additions & 2 deletions lib/tasks/webpacker/yarn_install.rake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace :webpacker do
desc "Support for older Rails versions.Install all JavaScript dependencies as specified via Yarn"
task :yarn_install do
system("./bin/yarn")
task :yarn_install, [:arg1, :arg2] do |task, args|
exec "yarn #{args[:arg1]} #{args[:arg2]}"
end
end
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "node_modules/eslint/bin/eslint.js lib/"
"lint": "yarn run eslint lib/"
},
"repository": {
"type": "git",
Expand Down