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 18, 2016
1 parent bfdac11 commit 1c71580
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 16 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 start
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": {
"build": "webpack -d --config config/webpack.config.js",
"start": "webpack-dev-server -p --config config/webpack.config.js"
},
"dependencies": {
"stats-webpack-plugin": "^0.2.1",
"webpack": "^1.9.11",
Expand Down
18 changes: 3 additions & 15 deletions lib/tasks/webpack.rake
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
namespace :webpack do
desc "Compile webpack bundles"
task compile: :environment do
ENV["TARGET"] = 'production' # TODO: Deprecated, use NODE_ENV instead
ENV["NODE_ENV"] = 'production'
webpack_bin = ::Rails.root.join(::Rails.configuration.webpack.binary)
config_file = ::Rails.root.join(::Rails.configuration.webpack.config_file)
task(:compile) { sh "npm run build" }

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
desc "Start webpack dev server"
task(:dev) { sh "npm start" }
end

0 comments on commit 1c71580

Please sign in to comment.