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

Bring webpack tasks to npm scripts and wrap it with rakes #57

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you have used d here but you wanted p and the same on the line below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'r right. I'll fix it. Thanks.

"serve": "webpack-dev-server -p --config config/webpack.config.js"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When using -p option, I had the following issue: webpack/webpack#1385 which was fixed by removing the -p option.

when using new UglifyJsPlugin and --opimize-minimize (or -p) you are adding the UglifyJsPlugin twice. Omit the CLI option.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice. I will change.

},
"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