Bring webpack tasks to npm scripts and wrap it with rakes
I usually do it in my projects. What you think about?
We can run npm tasks or rake tasks whenever you need:
npm start
npm run build
rake webpack:dev
rake webpack:compile
I often run rails s in one tab and npm start in another.
The main advantage is have all commands configured in just one place and can eventually be removed from rails (without ruby methods as dependency to run webpack server o build it).
I need to think about this one a bit more. I was originally against this because if you changed away from the default paths in your config it'd break.. but there's lots of 👍 's and it's really annoying having to wait for rails to boot just to run a compile.
Yeah, if you change the default path it will break. I usually put configs into config/js/ but I have only one and simple place to change, the package.json. Who use webpack hope it. Let npm do his job.
Look. How can I improve more? @talyssonoc, @mipearson.
I unfortunately can't merge this as it is as it will be a breaking change for those that have reconfigured paths in webpack-rails and expect the rake task to 'just work'.
That said, though, this is the better way.
I will be making a 1.x branch and we can merge it in to that.
Nice. Anyway I will think about improve it in this way.
What you think about this?:
namespace :webpack do
desc "Compile webpack bundles"
task compile: :environment do
ENV["TARGET"] = 'production' # TODO: Deprecated, use NODE_ENV instead
ENV["NODE_ENV"] = 'production'
package_json = JSON.parse(File.read(Rails.root.join('package.json')))
if( package_json['scripts']['compile'] )
sh "npm run compile"
else
# WE can put a deprecation warning here
webpack_bin = ::Rails.root.join(::Rails.configuration.webpack.binary)
config_file = ::Rails.root.join(::Rails.configuration.webpack.config_file)
unless File.exist?(webpack_bin)
raise "Can't find our webpack executable at #{webpack_bin} - have you run `npm install`?"
end
unless File.exist?(config_file)
raise "Can't find our webpack config file at #{config_file}"
end
sh "#{webpack_bin} --config #{config_file} --bail"
end
end
end
This is really cool! Would love to see this as it doesn't require my rails environment (secrets.yml, redis.yml) to exist at the time of assets compilation.
I'm going to be bringing this in to an API-breaking 1.0-pre branch shortly.
The delay on this (and other) pull requests is that I've been cautious to merge anything that could break functionality for existing users.
Of course, I understand. Do you need some more adjustments?