Skip to content
This repository has been archived by the owner on Oct 2, 2019. It is now read-only.

Commit

Permalink
Bring webpack tasks to npm scripts and wrap it with rakes
Browse files Browse the repository at this point in the history
  • Loading branch information
halan committed Sep 22, 2016
1 parent bfdac11 commit 9fc6a1e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 15 deletions.
2 changes: 1 addition & 1 deletion example/Procfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Run Rails & Webpack concurrently
# Example file from webpack-rails gem
rails: bundle exec rails server
webpack: ./node_modules/.bin/webpack-dev-server --config config/webpack.config.js
webpack: npm run serve
4 changes: 4 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
"name": "webpack-rails-example",
"version": "0.0.1",
"license": "MIT",
"scripts": {
"compile": "webpack -d --config config/webpack.config.js",
"serve": "webpack-dev-server -p --config config/webpack.config.js"
},
"dependencies": {
"stats-webpack-plugin": "^0.2.1",
"webpack": "^1.9.11",
Expand Down
19 changes: 5 additions & 14 deletions lib/tasks/webpack.rake
Original file line number Diff line number Diff line change
@@ -1,19 +1,10 @@
namespace :webpack do
desc "Compile webpack bundles"
task compile: :environment do
ENV["TARGET"] = 'production' # TODO: Deprecated, use NODE_ENV instead
task(:compile) do
ENV["NODE_ENV"] = 'production'
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"
sh "npm run compile"
end

desc "Start webpack dev server"
task(:serve) { sh "npm run serve" }
end

0 comments on commit 9fc6a1e

Please sign in to comment.