GithubHelp home page GithubHelp logo

Comments (2)

ytbryan avatar ytbryan commented on May 5, 2024 1

So the fix is to escape the path at APP_PATH.

However, interestingly because Dir.chdir and File.foreach produce error when I pass in APP_PATH with space escaped. (is this a bug/flaw on ruby side?)

Therefore, I simply create a second APP_PATH called APP_PATH2 with the path escaped. Use it on the other paths that depends on it. Try it and let me know if this fix. It's working on my end.

And thank you for http://driftingruby.com/ :)

#!/usr/bin/env ruby

ENV['RAILS_ENV'] ||= 'development'
RAILS_ENV   = ENV['RAILS_ENV']

ENV['NODE_ENV'] ||= RAILS_ENV
NODE_ENV    = ENV['NODE_ENV']

APP_PATH = File.expand_path('../', __dir__)
APP_PATH2 = File.expand_path('../', __dir__).gsub(/ /, "\\ ")

SET_NODE_PATH  = "NODE_PATH=#{APP_PATH2}/node_modules"
WEBPACKER_BIN  = "./node_modules/.bin/webpack-dev-server"
WEBPACK_CONFIG = "#{APP_PATH2}/config/webpack/#{NODE_ENV}.js"

RAILS_ENV_CONFIG = File.join("config", "environments", "#{RAILS_ENV}.rb")

unless File.foreach(File.join(APP_PATH, RAILS_ENV_CONFIG)).detect { |line| line.match(/^\s*[^#]*config\.x\.webpacker\[\:dev_server_host\].*=/) }
  puts "Warning: if you want to use webpack-dev-server, you need to tell Webpacker to serve asset packs from it. Please set config.x.webpacker[:dev_server_host] in #{RAILS_ENV_CONFIG}.\n\n"
end

Dir.chdir(APP_PATH) do
  exec "#{SET_NODE_PATH} #{WEBPACKER_BIN} --config #{WEBPACK_CONFIG} --content-base #{APP_PATH2}/public/packs #{ARGV.join(" ")}"
end

from webpacker.

gauravtiwari avatar gauravtiwari commented on May 5, 2024

Or just use shellwords. Perhaps, needs a PR to fix this 👍

#!/usr/bin/env ruby
require 'shellwords'

ENV['RAILS_ENV'] ||= 'development'
RAILS_ENV   = ENV['RAILS_ENV']

ENV['NODE_ENV'] ||= RAILS_ENV
NODE_ENV    = ENV['NODE_ENV']

APP_PATH = File.expand_path('../', __dir__)
ESCAPED_APP_PATH = APP_PATH.shellescape

SET_NODE_PATH  = "NODE_PATH=#{ESCAPED_APP_PATH}/node_modules"
WEBPACKER_BIN  = "./node_modules/.bin/webpack-dev-server"
WEBPACK_CONFIG = "#{ESCAPED_APP_PATH}/config/webpack/#{NODE_ENV}.js"

# Warn the user if the configuration is not set
RAILS_ENV_CONFIG = File.join("config", "environments", "#{RAILS_ENV}.rb")

# Look into the environment file for a non-commented variable declaration
unless File.foreach(File.join(APP_PATH, RAILS_ENV_CONFIG)).detect { |line| line.match(/^\s*[^#]*config\.x\.webpacker\[\:dev_server_host\].*=/) }
  puts "Warning: if you want to use webpack-dev-server, you need to tell Webpacker to serve asset packs from it. Please set config.x.webpacker[:dev_server_host] in #{RAILS_ENV_CONFIG}.\n\n"
end

Dir.chdir(APP_PATH) do
  exec "#{SET_NODE_PATH} #{WEBPACKER_BIN} --config #{WEBPACK_CONFIG} --content-base #{ESCAPED_APP_PATH}/public/packs #{ARGV.join(" ")}"
end
#!/usr/bin/env ruby
require 'shellwords'

ENV['RAILS_ENV'] ||= 'development'
RAILS_ENV   = ENV['RAILS_ENV']

ENV['NODE_ENV'] ||= RAILS_ENV
NODE_ENV    = ENV['NODE_ENV']

APP_PATH = File.expand_path('../', __dir__)
ESCAPED_APP_PATH = APP_PATH.shellescape

SET_NODE_PATH  = "NODE_PATH=#{ESCAPED_APP_PATH}/node_modules"
WEBPACK_BIN    = "./node_modules/webpack/bin/webpack.js"
WEBPACK_CONFIG = "#{ESCAPED_APP_PATH}/config/webpack/#{NODE_ENV}.js"

Dir.chdir(APP_PATH) do
  exec "#{SET_NODE_PATH} #{WEBPACK_BIN} --config #{WEBPACK_CONFIG} #{ARGV.join(" ")}"
end

from webpacker.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.