webpack_rails 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4eefc65be79a7423acbb4aee442f794dda650b0a
4
- data.tar.gz: fc8ff00a8a7ffb4048e783756c0d35041f7c81f7
3
+ metadata.gz: ddb9eeee4bbff9584582e6b7c92e4a654e2a9af8
4
+ data.tar.gz: f12e3aceb14f4a508f49fef60caca7b2e54f8ba7
5
5
  SHA512:
6
- metadata.gz: c12944c42e4f37cf0ad6d559a6389553067ce9034590aa93f25929767656542795ae622657f0cda43c9f3a5217f9440a1feca69dfe68e7ff693e72e8c5f37e85
7
- data.tar.gz: b737ff3f47506b20307bc35af43cb94e25bea7e61f3cd15473987fcfa3823873e194b297eaf5b3d0831fc1edddc66a4def50ecfd52e6d1fd6a46f84637c56cc6
6
+ metadata.gz: 4b93a1aa955ebe77fa38091d5c6b895d4cca14a287ee941a4ac540ce9633099f53376be84cdff4b14576b07d6294bac3e4b95742f9b6a57c15988d78022b9248
7
+ data.tar.gz: c9bf05d74228ddcac831458a5b1166c44dd7dfdd08a9656c925b22742c3ceee85bd91a922f4d33abe22d7edd02ac0249d9307d76a019e7a2216169622917e5a0
@@ -2,11 +2,17 @@ require_relative './processor'
2
2
 
3
3
  module WebpackRails
4
4
  class Engine < ::Rails::Engine
5
+ engine_name "webpack"
6
+
5
7
  initializer :setup_webpack_rails, :after => "sprockets.environment", :group => :all do |app|
6
8
  # where [name].bundle.js files should be
7
9
  app.assets.append_path Rails.root.join('tmp/webpack/bundles')
8
10
  # process
9
11
  app.assets.register_preprocessor('application/javascript', WebpackRails::Processor)
10
12
  end
13
+
14
+ rake_tasks do
15
+ load 'webpack_rails/webpack.rake'
16
+ end
11
17
  end
12
18
  end
@@ -21,4 +21,4 @@ module WebpackRails
21
21
  bundle_contents.gsub(/['"]\$asset_path\/([^'"]+?)['"]/) {|s| "'#{context.asset_path($1)}'" }
22
22
  end
23
23
  end
24
- end
24
+ end
@@ -47,14 +47,26 @@ module WebpackRails
47
47
  return_value
48
48
  end
49
49
 
50
+ def build_result
51
+ begin
52
+ JSON.parse(File.open(File.join(working_dir, 'webpack-build-result.json')).read)
53
+ rescue Errno::ENOENT => e
54
+ {modules: []}
55
+ end
56
+ end
57
+
50
58
  def run_webpack(opts = nil)
51
59
  result = nil
60
+ if ENV['DISABLE_WEBPACK']
61
+ return build_result
62
+ end
52
63
 
53
64
  task_duration = Benchmark.realtime do
54
65
  result = with_app_node_path do
55
66
  begin
56
67
  task = self.new
57
68
  task.run(opts)
69
+ build_result
58
70
  rescue NodeTask::Error => e
59
71
  raise self::Error.new(e)
60
72
  end
@@ -2,9 +2,10 @@ var webpack = require('webpack');
2
2
  var fs = require('fs');
3
3
  var path = require('path');
4
4
 
5
- var logging = true;
5
+ var stdoutLogging = process.env.WEBPACK_STDOUT_LOGGING;
6
+ var loggingToFile = true;
6
7
  function log(message) {
7
- if (logging) fs.appendFile('log/webpack-task.log', message+'\n');
8
+ if (loggingToFile) fs.appendFile('log/webpack-task.log', message+'\n');
8
9
  }
9
10
 
10
11
  // TODO: add support for multiple builds using multiple webpack configs which
@@ -21,6 +22,8 @@ var lastBuildResult = null;
21
22
  function buildComplete(buildResult) {
22
23
  lastBuildResult = buildResult;
23
24
 
25
+ if (stdoutLogging) console.log('rebuild complete');
26
+
24
27
  currentBuildCallbacks.forEach(function(callback) {
25
28
  log('async completion callback');
26
29
  callback(buildResult);
@@ -77,8 +80,6 @@ module.exports = function waitForBuild(opts, done) {
77
80
  else done(null, buildResult);
78
81
  }
79
82
 
80
- log('watcher.running: '+JSON.stringify(watcher.running));
81
-
82
83
  if (!watcher.running) {
83
84
  sendResults(lastBuildResult);
84
85
  } else {
@@ -0,0 +1,19 @@
1
+ require_relative './task'
2
+
3
+ namespace :webpack do
4
+ task :watch do
5
+ puts 'watching for webpack changes'
6
+ WebpackRails::Task.with_app_node_path do
7
+ system "WEBPACK_STDOUT_LOGGING=yes #{WebpackRails::Task.node_command} #{WebpackRails::Task.webpack_task_script}"
8
+ end
9
+ end
10
+
11
+ task :before_assets_precompile do
12
+ # with production config, sprockets index isn't updated correctly by the
13
+ # find_asset monkey patch. instead, we just run it before precompiling assets
14
+ WebpackRails::Task.run_webpack
15
+ end
16
+ end
17
+
18
+ # runs before every 'rake assets:precompile'
19
+ Rake::Task['assets:precompile'].enhance(['webpack:before_assets_precompile'])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpack_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Friend
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-05 00:00:00.000000000 Z
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: node_task
@@ -57,6 +57,7 @@ files:
57
57
  - lib/webpack_rails/sprockets_index_webpack.rb
58
58
  - lib/webpack_rails/task.rb
59
59
  - lib/webpack_rails/webpack-task.js
60
+ - lib/webpack_rails/webpack.rake
60
61
  homepage: https://rubygems.org/gems/webpack_rails
61
62
  licenses:
62
63
  - MIT