webpackrails 1.2.1 → 2.0.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 +4 -4
- data/README.md +9 -1
- data/lib/webpackrails/railtie.rb +4 -1
- data/lib/webpackrails/version.rb +1 -1
- data/lib/webpackrails/webpack_processor.rb +56 -9
- metadata +18 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbba3cde0af91cb39ec6bbb53d0ca0fadf6b1dae
|
4
|
+
data.tar.gz: fcc9d57ef318cb5a002bedd665af6cf6e48e2705
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 030c57346ad4ad4db817b8464aa5340aaac7408ef4d193582ca70f98c7bb53a3b007c5a4158f7b4676c14f94003d502322af658436d5dff2449b84622f0c58da
|
7
|
+
data.tar.gz: b57c2071bec71224024d03d81066816d36229a1ed922ccc8d21cfc7a3911c6b5b8fa9856b0c8c923eff115f11ac1bff3835b58a1d30d352a4a6d96b254b59040
|
data/README.md
CHANGED
@@ -63,10 +63,18 @@ module.exports = {
|
|
63
63
|
|
64
64
|
[Wiki troubleshooting](https://github.com/towry/webpackrails/wiki/Troubleshooting)
|
65
65
|
|
66
|
-
|
66
|
+
|
67
|
+
## Feature
|
68
|
+
|
69
|
+
* Support embedding erb in javascript, see [troubleshooting](https://github.com/towry/webpackrails/wiki/Troubleshooting) page. **Aug 16, 2015**
|
70
|
+
* Support es6 (just use webpack babel loader)
|
71
|
+
* Support react jsx syntax (just use webpack babel loader)
|
72
|
+
|
73
|
+
## Config
|
67
74
|
|
68
75
|
See [source](https://raw.githubusercontent.com/towry/webpackrails/master/lib/webpackrails/railtie.rb)
|
69
76
|
|
77
|
+
|
70
78
|
## Development
|
71
79
|
|
72
80
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/webpackrails/railtie.rb
CHANGED
@@ -19,12 +19,15 @@ module WebpackRails
|
|
19
19
|
# ignore node_modules
|
20
20
|
config.webpackrails.ignore_node_modules = true
|
21
21
|
|
22
|
+
# embed erb
|
23
|
+
config.webpackrails.embed_erb = false
|
24
|
+
|
22
25
|
# array of string to test if the file need to be process by this gem.
|
23
26
|
# see `commonjs_module?` method
|
24
27
|
config.webpackrails.force_condition = []
|
25
28
|
|
26
29
|
initializer :setup_webpack do |app|
|
27
|
-
app.assets.
|
30
|
+
app.assets.register_postprocessor "application/javascript", WebpackRails::WebpackProcessor
|
28
31
|
end
|
29
32
|
|
30
33
|
rake_tasks do
|
data/lib/webpackrails/version.rb
CHANGED
@@ -5,6 +5,7 @@ require 'open3'
|
|
5
5
|
require 'tempfile'
|
6
6
|
require 'fileutils'
|
7
7
|
require 'shellwords'
|
8
|
+
require 'digest/sha1'
|
8
9
|
|
9
10
|
module WebpackRails
|
10
11
|
class WebpackProcessor < Tilt::Template
|
@@ -25,17 +26,51 @@ module WebpackRails
|
|
25
26
|
# return if there is nothing to do
|
26
27
|
return data unless should_webpack?
|
27
28
|
|
28
|
-
|
29
|
+
if config.embed_erb
|
30
|
+
run_webpack(context.pathname || context.logical_path, false)
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
evaluate_dependencies(context.environment.paths).each do |path|
|
33
|
+
context.depend_on(path.to_s)
|
34
|
+
end
|
35
|
+
|
36
|
+
if !@erb_deps.empty?
|
37
|
+
evaluate_erb_deps(context, locals)
|
38
|
+
end
|
33
39
|
|
40
|
+
evaluated = run_webpack(context.pathname || context.logical_path)
|
41
|
+
else
|
42
|
+
evaluated = run_webpack(context.pathname || context.logical_path)
|
43
|
+
evaluate_dependencies(context.environment.paths).each do |path|
|
44
|
+
context.depend_on(path.to_s)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
34
48
|
evaluated
|
35
49
|
end
|
36
50
|
|
37
51
|
private
|
38
52
|
|
53
|
+
def evaluate_erb_deps(context, locals)
|
54
|
+
return if @erb_deps.empty?
|
55
|
+
|
56
|
+
# dep is a path
|
57
|
+
@erb_deps.each do |dep|
|
58
|
+
begin
|
59
|
+
shaname = sha1(dep)
|
60
|
+
tmpfile = File.join(@erb_deps_root, shaname)
|
61
|
+
template = Tilt::ERBTemplate.new(dep)
|
62
|
+
template = template.render(context, locals)
|
63
|
+
file = File.open(tmpfile, 'w')
|
64
|
+
file.write(template)
|
65
|
+
file.close()
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def sha1(content)
|
71
|
+
Digest::SHA1.hexdigest content
|
72
|
+
end
|
73
|
+
|
39
74
|
# Set the temp path
|
40
75
|
def tmp_path
|
41
76
|
@tmp_path ||= Rails.root.join('tmp', 'cache', 'webpackrails').freeze
|
@@ -50,13 +85,20 @@ module WebpackRails
|
|
50
85
|
def ensure_tmp_dir_exists!
|
51
86
|
FileUtils.mkdir_p(rails_path(tmp_path))
|
52
87
|
@deps_path ||= File.join(tmp_path, '_$webpackrails_dependencies');
|
88
|
+
@erb_deps_root ||= rails_path('tmp/cache/webpackrails/erbs').freeze
|
89
|
+
|
90
|
+
FileUtils.mkdir_p(@erb_deps_root)
|
53
91
|
end
|
54
92
|
|
55
|
-
# Filter out node_module/ files
|
93
|
+
# Filter out node_module/ files and erb files.
|
56
94
|
def evaluate_dependencies(asset_paths)
|
57
|
-
return dependencies if !config.ignore_node_modules
|
95
|
+
return dependencies if !config.ignore_node_modules and !config.embed_erb
|
58
96
|
|
59
|
-
|
97
|
+
@erb_deps = []
|
98
|
+
deps = dependencies.select do |path|
|
99
|
+
if File.extname(path) == '.erb'
|
100
|
+
@erb_deps << path
|
101
|
+
end
|
60
102
|
path.start_with?(*asset_paths)
|
61
103
|
end
|
62
104
|
end
|
@@ -150,8 +192,13 @@ module WebpackRails
|
|
150
192
|
false
|
151
193
|
end
|
152
194
|
|
153
|
-
def run_webpack(logical_path=nil)
|
154
|
-
|
195
|
+
def run_webpack(logical_path=nil, bail= true)
|
196
|
+
if bail
|
197
|
+
command_options = "--colors --config #{@config_file} #{logical_path} --bail --output-filename"
|
198
|
+
else
|
199
|
+
command_options = "--colors --config #{@config_file} #{logical_path} --output-filename"
|
200
|
+
end
|
201
|
+
|
155
202
|
output_file = Tempfile.new("output", rails_path(tmp_path))
|
156
203
|
command_options << " #{output_file.path.inspect}"
|
157
204
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webpackrails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- towry
|
@@ -14,98 +14,98 @@ dependencies:
|
|
14
14
|
name: railties
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '3.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: sprockets
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ~>
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '2.0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '1.3'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.3'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: pry
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- -
|
87
|
+
- - '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- -
|
94
|
+
- - '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: tilt
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|
100
100
|
requirements:
|
101
|
-
- -
|
101
|
+
- - '>='
|
102
102
|
- !ruby/object:Gem::Version
|
103
103
|
version: '0'
|
104
104
|
type: :development
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
|
-
- -
|
108
|
+
- - '>='
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
description: Webpack + Rails ≠ CommonJS Heaven
|
@@ -115,7 +115,7 @@ executables: []
|
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
117
117
|
files:
|
118
|
-
-
|
118
|
+
- .gitignore
|
119
119
|
- CODE_OF_CONDUCT.md
|
120
120
|
- Gemfile
|
121
121
|
- LICENSE.txt
|
@@ -142,12 +142,12 @@ require_paths:
|
|
142
142
|
- lib
|
143
143
|
required_ruby_version: !ruby/object:Gem::Requirement
|
144
144
|
requirements:
|
145
|
-
- -
|
145
|
+
- - '>='
|
146
146
|
- !ruby/object:Gem::Version
|
147
147
|
version: '0'
|
148
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- -
|
150
|
+
- - '>='
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
153
|
requirements: []
|