webpackrails 1.0.0 → 1.1.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: 2fa2985efb84baf179b44c31c54b45b7bebb8a79
4
- data.tar.gz: 90aeb67545627aeb8227b627c5507bbe056686e3
3
+ metadata.gz: 23a0ed3b4f87bc4f9f28188d34e0b3917f1de549
4
+ data.tar.gz: 7fcec1a616e7664b9e5cee82b3a0fafb9920b85c
5
5
  SHA512:
6
- metadata.gz: a0172bd0f2f2e60ed678b4ec5991e5e10e8368b23d2c3412b70e66f140c35cb7942be659916ebfb8207d18af5821c5d243af52a6261b7236d46633aa887188dd
7
- data.tar.gz: 18ecc798dd746604ec293e89a6c7274e543a24451c7039045135d2a9fed4356397d1b6d5b8a2c019729c4c39f4305c76d726865cf4558fc6105942091108aed2
6
+ metadata.gz: 95e37ac03e8379e6cb98d5a1b64dd042487f23f235ea6e5e667cd1d0f47c799c222f77042083165462064b9a13b58c218ece9bc715915b65f530a38e22dcf15b
7
+ data.tar.gz: d892189d8cfd6544eb9b391ce71e2a672f79a8aa8ed6caa99dcd88aab696f6bf7aa393d718b5e36a86ec00ba588d744f76870d1573ac1833e163e67e29b5083b
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source 'https://rubygems.org/'
1
+ source 'https://ruby.taobao.org/'
2
2
 
3
3
  # Specify your gem's dependencies in webpack-rails.gemspec
4
4
  gemspec
data/README.md CHANGED
@@ -4,6 +4,8 @@ This gem make [Webpack](http://webpack.github.io) works with [Rails](http://gith
4
4
 
5
5
  ## Installation
6
6
 
7
+ *Rails: >= 3*
8
+
7
9
  Add this line to your application's Gemfile:
8
10
 
9
11
  ```ruby
@@ -24,7 +26,8 @@ Create `package.json` in your Rails root:
24
26
  {
25
27
  "name": "app",
26
28
  "dependencies": {
27
- "webpack": "^1.11.0"
29
+ "webpack": "^1.11.0",
30
+ "railshot-webpack-plugin": "*"
28
31
  }
29
32
  }
30
33
  ```
@@ -36,7 +39,25 @@ Run `npm i` to install the dependencies.
36
39
  Make sure you have a `webpack.config.js` file in your Rails root dir, or specific your
37
40
  webpack config file within `application.rb`
38
41
 
39
- `config.webpack_rails.config_file = "path_to_the_config_file"`
42
+ `config.webpackrails.config_file = "path_to_the_config_file"`
43
+
44
+ ### Watch file for changes
45
+
46
+ Use webpack plugin `railshot-webpack-plugin` in your `webpack.config.js`.
47
+ If you haven't install the plugin yet, run `npm install railshot-webpack-plugin`.
48
+
49
+ ```js
50
+ // webpack.config.js
51
+
52
+ var railshotPlugin = require('railshot-webpack-plugin');
53
+
54
+ // no entry here.
55
+ module.exports = {
56
+ plugins: [
57
+ railshotPlugin()
58
+ ]
59
+ }
60
+ ```
40
61
 
41
62
  ### Config
42
63
 
@@ -2,22 +2,29 @@
2
2
 
3
3
  module WebpackRails
4
4
  class Railtie < Rails::Engine
5
- config.webpack_rails = ActiveSupport::OrderedOptions.new
5
+ config.webpackrails = ActiveSupport::OrderedOptions.new
6
6
 
7
7
  # Webpack config file location
8
- config.webpack_rails.config_file = ''
8
+ config.webpackrails.config_file = ''
9
9
 
10
10
  # Process every file?
11
- config.webpack_rails.force = false
11
+ config.webpackrails.force = false
12
12
 
13
13
  # paths to be parse
14
- config.webpack_rails.paths = [lambda { |p| p.start_with?(Rails.root.join("app").to_s) },
14
+ config.webpackrails.paths = [lambda { |p| p.start_with?(Rails.root.join("app").to_s) },
15
15
  lambda { |p| p.start_with?(Rails.root.join('node_modules').to_s) }]
16
16
 
17
- config.webpack_rails.node_bin = "node_modules/.bin/"
17
+ config.webpackrails.node_bin = "node_modules/.bin/"
18
+
19
+ # ignore node_modules
20
+ config.webpackrails.ignore_node_modules = true
18
21
 
19
22
  initializer :setup_webpack do |app|
20
23
  app.assets.register_postprocessor "application/javascript", WebpackRails::WebpackProcessor
21
24
  end
25
+
26
+ rake_tasks do
27
+ Dir[File.join(File.dirname(__FILE__), "tasks/*.rake")].each { |f| load f }
28
+ end
22
29
  end
23
30
  end
@@ -0,0 +1,20 @@
1
+ namespace :npm do
2
+ desc "Run npm install"
3
+ task :install do
4
+ sh "npm install && npm --save install railshot-webpack-plugin" do |ok, res|
5
+ fail "Error running npm install." unless ok
6
+ end
7
+ end
8
+
9
+ desc "Clean npm node_modules"
10
+ task :clean do
11
+ sh "rm -rf ./node_modules" do |ok, res|
12
+ fail "Error cleaning npm node_modules." unless ok
13
+ end
14
+ end
15
+
16
+ namespace :install do
17
+ desc "Run a clean npm install"
18
+ task :clean => ['npm:clean', 'npm:install']
19
+ end
20
+ end
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module WebpackRails
4
- VERSION = "1.0.0"
4
+ VERSION = "1.1.0"
5
5
  end
@@ -11,7 +11,7 @@ module WebpackRails
11
11
  attr_accessor :config
12
12
 
13
13
  def initialize(template)
14
- self.config = Rails.application.config.webpack_rails
14
+ self.config = Rails.application.config.webpackrails
15
15
  super(template)
16
16
  end
17
17
 
@@ -25,14 +25,20 @@ module WebpackRails
25
25
  # return if there is nothing to do
26
26
  return data unless should_webpack?
27
27
 
28
- run_webpack(context.pathname || context.logical_path)
28
+ evaluated = run_webpack(context.pathname || context.logical_path)
29
+
30
+ evaluate_dependencies(context.environment.paths).each do |path|
31
+ context.depend_on(path.to_s)
32
+ end
33
+
34
+ evaluated
29
35
  end
30
36
 
31
37
  private
32
38
 
33
39
  # Set the temp path
34
40
  def tmp_path
35
- @tmp_path ||= Rails.root.join('tmp', 'cache', 'webpack-rails').freeze
41
+ @tmp_path ||= Rails.root.join('tmp', 'cache', 'webpackrails').freeze
36
42
  end
37
43
 
38
44
  # return the webpack command path
@@ -43,6 +49,42 @@ module WebpackRails
43
49
  # make sure the temp dir exists
44
50
  def ensure_tmp_dir_exists!
45
51
  FileUtils.mkdir_p(rails_path(tmp_path))
52
+ @deps_path = File.join(tmp_path, '_$webpackrails_dependencies');
53
+ end
54
+
55
+ # Filter out node_module/ files
56
+ def evaluate_dependencies(asset_paths)
57
+ return dependencies if !config.ignore_node_modules
58
+
59
+ dependencies.select do |path|
60
+ path.start_with?(*asset_paths)
61
+ end
62
+ end
63
+
64
+ # return array
65
+ def dependencies
66
+ ret ||= begin
67
+ if !File.exists?(@deps_path)
68
+ return []
69
+ end
70
+
71
+ output = ''
72
+ begin
73
+ file = File.open(@deps_path, 'r')
74
+ output = file.read
75
+ file.close
76
+ rescue
77
+ output = ''
78
+ end
79
+
80
+ if !output
81
+ return []
82
+ end
83
+
84
+ output.lines.map(&:strip).select do |path|
85
+ File.exists?(path)
86
+ end
87
+ end
46
88
  end
47
89
 
48
90
  # make sure the webpack config file exists
@@ -93,6 +135,8 @@ module WebpackRails
93
135
  env_hash = {}
94
136
  env_hash["NODE_PATH"] = asset_paths unless uses_exorcist
95
137
  env_hash["NODE_ENV"] = config.node_env || Rails.env
138
+ env_hash["WR_TMP_FILE"] = @deps_path;
139
+ env_hash['RAILS_ROOT'] = Rails.root.to_s
96
140
  env_hash
97
141
  end
98
142
 
@@ -116,7 +160,12 @@ module WebpackRails
116
160
  raise WebpackRails::WebpackError.new("Error while running `#{command}`:\n\n#{stderr}")
117
161
  end
118
162
 
119
- output_file.read
163
+ output = output_file.read
164
+
165
+ output_file.close
166
+ output_file.unlink
167
+
168
+ output
120
169
  end
121
170
 
122
171
  def rails_path(*paths)
data/webpackrails.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ["lib"]
29
29
 
30
- spec.add_runtime_dependency "railties", "~> 3.2", "<= 5.0.0"
30
+ spec.add_runtime_dependency "railties", ">= 3.0"
31
31
  spec.add_runtime_dependency "sprockets", "~> 2.0"
32
32
 
33
33
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,35 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webpackrails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - towry
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-08-11 00:00:00.000000000 Z
11
+ date: 2015-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: railties
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '3.2'
20
- - - <=
17
+ - - '>='
21
18
  - !ruby/object:Gem::Version
22
- version: 5.0.0
19
+ version: '3.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
- - - ~>
28
- - !ruby/object:Gem::Version
29
- version: '3.2'
30
- - - <=
24
+ - - '>='
31
25
  - !ruby/object:Gem::Version
32
- version: 5.0.0
26
+ version: '3.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: sprockets
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -131,6 +125,7 @@ files:
131
125
  - bin/setup
132
126
  - lib/webpackrails.rb
133
127
  - lib/webpackrails/railtie.rb
128
+ - lib/webpackrails/tasks/npm.rake
134
129
  - lib/webpackrails/version.rb
135
130
  - lib/webpackrails/webpack_error.rb
136
131
  - lib/webpackrails/webpack_logger.rb
@@ -162,3 +157,4 @@ signing_key:
162
157
  specification_version: 4
163
158
  summary: Make Webpack work with Rails for you
164
159
  test_files: []
160
+ has_rdoc: