Comments (2)
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.
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)
- Webpacker 6 Disable Babel HOT 1
- Webpacker compilation takes more than 1.5 hours HOT 11
- How do I allow a package in node_modules to be processed by babel? HOT 1
- Remove addition of node_modules to Rails.application.config.assets.paths HOT 1
- V6 Status HOT 3
- Raise an error when javascript_pack_tag or stylesheet_pack_tag are called more than once HOT 1
- Regular Expression Denial of Service in postcss HOT 2
- Intermittent Webpacker.dev_server.running? behavior HOT 2
- Host for assets from a webpacker configuration using custom domains not being resolved HOT 2
- Cherry-pick "Nothing to do" logging update onto `5.x` HOT 1
- Rails 6 WebPacker is not calling JQuery inside views HOT 1
- Security Vulnerability in [email protected] HOT 2
- currently no loaders are configured to process this file HOT 1
- Incompatibility with Ruby 3.2.0 HOT 2
- Confusing gem description on RubyGems HOT 1
- Npm package for 5.4.4 was not released HOT 2
- class variable @@local_levels of ActiveSupport::Logger is overtaken by Logger HOT 2
- Trying to deploy but assets assets:precompile fail
- Security Vulnerability for postcss
- Postcss Security Vulnerability
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from webpacker.