diff --git a/example/Procfile b/example/Procfile index 45da176..783f646 100644 --- a/example/Procfile +++ b/example/Procfile @@ -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 diff --git a/example/package.json b/example/package.json index 44b3845..85b9861 100644 --- a/example/package.json +++ b/example/package.json @@ -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", diff --git a/lib/tasks/webpack.rake b/lib/tasks/webpack.rake index dda273e..66fc9d4 100644 --- a/lib/tasks/webpack.rake +++ b/lib/tasks/webpack.rake @@ -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