diff --git a/README.md b/README.md index 0aaf5cdeb..9ed33ee39 100644 --- a/README.md +++ b/README.md @@ -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 @@ -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 diff --git a/lib/install/angular.rb b/lib/install/angular.rb index 98d165415..7d2dd7964 100644 --- a/lib/install/angular.rb +++ b/lib/install/angular.rb @@ -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 🎉" diff --git a/lib/install/bin/webpack-dev-server.tt b/lib/install/bin/webpack-dev-server.tt index 94f8eaa57..5ea4a6e1c 100644 --- a/lib/install/bin/webpack-dev-server.tt +++ b/lib/install/bin/webpack-dev-server.tt @@ -19,7 +19,6 @@ 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." @@ -27,9 +26,10 @@ rescue Errno::ENOENT, NoMethodError 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 diff --git a/lib/install/bin/webpack.tt b/lib/install/bin/webpack.tt index f67e18030..3f0480ad1 100644 --- a/lib/install/bin/webpack.tt +++ b/lib/install/bin/webpack.tt @@ -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") @@ -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 diff --git a/lib/install/bin/yarn.tt b/lib/install/bin/yarn.tt deleted file mode 100644 index 5187824b2..000000000 --- a/lib/install/bin/yarn.tt +++ /dev/null @@ -1,11 +0,0 @@ -<%= shebang %> -VENDOR_PATH = File.expand_path('..', __dir__) -Dir.chdir(VENDOR_PATH) do - begin - exec "yarnpkg #{ARGV.join(" ")}" - rescue Errno::ENOENT - $stderr.puts "Yarn executable was not detected in the system." - $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install" - exit 1 - end -end diff --git a/lib/install/elm.rb b/lib/install/elm.rb index 1cd307409..9bbf68f79 100644 --- a/lib/install/elm.rb +++ b/lib/install/elm.rb @@ -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" diff --git a/lib/install/react.rb b/lib/install/react.rb index 059ec0272..c6e2dc374 100644 --- a/lib/install/react.rb +++ b/lib/install/react.rb @@ -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 🎉" diff --git a/lib/install/template.rb b/lib/install/template.rb index 7029531b0..fa600347a 100644 --- a/lib/install/template.rb +++ b/lib/install/template.rb @@ -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 @@ -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 babel-loader@7.x 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 🎉 🍰" diff --git a/lib/install/vue.rb b/lib/install/vue.rb index 97a6f74b5..71adb8c41 100644 --- a/lib/install/vue.rb +++ b/lib/install/vue.rb @@ -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 🎉" diff --git a/lib/tasks/webpacker/yarn_install.rake b/lib/tasks/webpacker/yarn_install.rake index 43e3d1431..fbb15f2eb 100644 --- a/lib/tasks/webpacker/yarn_install.rake +++ b/lib/tasks/webpacker/yarn_install.rake @@ -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 diff --git a/package.json b/package.json index 2bab1f128..2aa4a83ed 100644 --- a/package.json +++ b/package.json @@ -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",