webpack_rails 1.3.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 80a7e3a77159d1eee39c12eb365ee2e6fc9eb08c
4
- data.tar.gz: 7621ed395e73ad84e7ad24c9f533584474be324d
3
+ metadata.gz: 24eb2d5b3f17a410dd75aaefd6e0e4203df63f30
4
+ data.tar.gz: a2c3d47d9286ffee33128a6489d68e48ffb5427d
5
5
  SHA512:
6
- metadata.gz: aa258967efb81ba2d2e7ea2daf80ba5dce03dc2b780631aa5075a59a38408af1b24f5abadef411feb9d6ffbe8749302dc6434f058229d752ceed4d456b8800f9
7
- data.tar.gz: 7acef91df5da7c2f8bb50dbe643f3bf75369e82bea4f69c078934bfe9811d7005c1659980ee3ae332e01ef642871ab8e069a872163d2ae0a829fc0f7909608ff
6
+ metadata.gz: e125bf7ef05f97af37333b81bafcccf0c9f3dc136668d2fbf16222efea388ba0b9475c83197178459879a7a774b9c245389e84db965abea20eebf7125fee456f
7
+ data.tar.gz: 1c11739dc521a5c47b1d60e489ef1cc3b3770f0bd5a596a74f57d8c52bb045e15df0c8c2ef585a8330a200e56356e3831d30b58639ae78224c0744a26cf3cf20
@@ -7,14 +7,11 @@ module WebpackRails
7
7
  config.webpack_rails = ActiveSupport::OrderedOptions.new
8
8
 
9
9
  initializer :setup_webpack_rails, after: 'sprockets.environment', group: :all do |app|
10
- WebpackRails::SprocketsEnvironment.enhance!(app.assets, app.config.webpack_rails)
10
+ app.config.assets.configure do |env|
11
+ WebpackRails::SprocketsEnvironment.enhance!(env, app.config.webpack_rails)
11
12
 
12
- # where [name].bundle.js files should be
13
- app.assets.append_path Rails.root.join('tmp/webpack/bundles')
14
-
15
- # stop sprockets from ruining inline sourcemaps in dev
16
- if Rails.env.development?
17
- app.assets.unregister_postprocessor 'application/javascript', ::Sprockets::SafetyColons
13
+ # where [name].bundle.js files should be
14
+ env.append_path Rails.root.join('tmp/webpack/bundles')
18
15
  end
19
16
  end
20
17
 
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "webpack_rails",
3
- "version": "1.3.1",
3
+ "version": "2.0.0",
4
4
  "description": "",
5
5
  "main": "webpack-dev-server.js",
6
6
  "scripts": {
@@ -1,7 +1,9 @@
1
- require 'tilt'
1
+ require 'json'
2
+ require_relative './version'
3
+ require 'sprockets/directive_processor'
2
4
 
3
5
  module WebpackRails
4
- class RequireDirectiveProcessor < Tilt::Template
6
+ class RequireDirectiveProcessor
5
7
  DIRECTIVE_PATTERN = /^.*?=\s*webpack_require\s+(.*?)\s*$/
6
8
 
7
9
  def self.configure(webpack_task_config)
@@ -11,6 +13,8 @@ module WebpackRails
11
13
  end
12
14
 
13
15
  def self.config=(new_config)
16
+ @cache_key = nil
17
+ @instance = nil
14
18
  @config = new_config
15
19
  end
16
20
 
@@ -18,7 +22,17 @@ module WebpackRails
18
22
  @config
19
23
  end
20
24
 
21
- def prepare
25
+ def self.cache_key
26
+ config_serialized = @config ? @config.to_json : '{}'
27
+ @cache_key ||= "RequireDirectiveProcessor:#{::WebpackRails::VERSION}:#{config_serialized}".freeze
28
+ end
29
+
30
+ def self.instance
31
+ @instance ||= new
32
+ end
33
+
34
+ def self.call(input)
35
+ instance.call(input)
22
36
  end
23
37
 
24
38
  def config
@@ -29,23 +43,30 @@ module WebpackRails
29
43
  "#{config[:protocol]}://#{config[:host]}:#{config[:port]}"
30
44
  end
31
45
 
32
- def process_require(context, locals, bundle_filename)
46
+ def process_require(context, bundle_filename)
33
47
  if config[:dev_server]
34
48
  if bundle_filename.end_with? '.js'
49
+ # emit a script tag pointing at the dev server js url
35
50
  return %{document.write('<script src="#{dev_server_base_url}/#{bundle_filename}"></script>');}
36
51
  end
37
- return ''
52
+ # probably a css file, contents will be included in js instead to enable hot module replacement
53
+ return "\n"
38
54
  end
39
55
 
40
56
  # will be handled by normal sprockets require
41
57
  context.require_asset(bundle_filename)
42
- return ''
58
+ return "\n"
43
59
  end
44
60
 
45
- def evaluate(context, locals)
46
- data.gsub(DIRECTIVE_PATTERN) do |match_text|
47
- process_require(context, locals, $1)
61
+ def call(input)
62
+ data = input[:data]
63
+ context = input[:environment].context_class.new(input)
64
+
65
+ output = data.gsub(DIRECTIVE_PATTERN) do |match_text|
66
+ process_require(context, $1)
48
67
  end
68
+
69
+ context.metadata.merge(data: output)
49
70
  end
50
71
  end
51
72
  end
@@ -0,0 +1,15 @@
1
+ require 'sprockets'
2
+ require 'sprockets/cached_environment'
3
+
4
+ module WebpackRails
5
+ class SprocketsCachedEnvironment < ::Sprockets::CachedEnvironment
6
+ def initialize(environment)
7
+ if environment.webpack_task_config[:dev_server] || environment.webpack_task_config[:watch]
8
+ # ensure webpack-dev-server is running or watcher has finished building
9
+ WebpackRails::Task.run_webpack(environment.webpack_task_config)
10
+ end
11
+
12
+ super
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  require 'sprockets'
2
- require 'sprockets/webpack_index'
2
+ require 'webpack_rails/sprockets_cached_environment'
3
3
  require 'webpack_rails/require_directive_processor'
4
4
  require 'webpack_rails/processor'
5
5
 
@@ -31,8 +31,13 @@ module WebpackRails
31
31
  register_preprocessor 'text/css', require_directive_processor
32
32
  end
33
33
 
34
+ def cached
35
+ WebpackRails::SprocketsCachedEnvironment.new(self)
36
+ end
37
+
38
+ # sprockets 2.x compat
34
39
  def index
35
- Sprockets::WebpackIndex.new(self)
40
+ cached
36
41
  end
37
42
  end
38
43
 
@@ -0,0 +1,5 @@
1
+ require 'json'
2
+
3
+ module WebpackRails
4
+ VERSION = JSON.load(File.new(File.expand_path('../package.json', __FILE__)))['version']
5
+ end
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: 1.3.1
4
+ version: 2.0.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-11-11 00:00:00.000000000 Z
11
+ date: 2015-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: node_task
@@ -25,40 +25,31 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.3.5
27
27
  - !ruby/object:Gem::Dependency
28
- name: tilt
28
+ name: sprockets
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '1.1'
33
+ version: '3'
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
- version: '1.1'
41
- - !ruby/object:Gem::Dependency
42
- name: sprockets
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- description: Much longer explanation of the webpack_rails!
40
+ version: '3'
41
+ description: |-
42
+ Integrates Webpack with Rails/Sprockets.
43
+
44
+ The main goal of this gem is to keep things working relatively seamlessly and
45
+ automatically alongside existing Sprockets-based code, meeting the
46
+ developer-experience expectations of Rails developers, while working towards
47
+ the ultimate goal of transitioning off of Sprockets entirely.
56
48
  email: james@jsdf.co
57
49
  executables: []
58
50
  extensions: []
59
51
  extra_rdoc_files: []
60
52
  files:
61
- - lib/sprockets/webpack_index.rb
62
53
  - lib/webpack_rails.rb
63
54
  - lib/webpack_rails/ErrorMessagePlugin.js
64
55
  - lib/webpack_rails/engine.rb
@@ -404,8 +395,10 @@ files:
404
395
  - lib/webpack_rails/package.json
405
396
  - lib/webpack_rails/processor.rb
406
397
  - lib/webpack_rails/require_directive_processor.rb
398
+ - lib/webpack_rails/sprockets_cached_environment.rb
407
399
  - lib/webpack_rails/sprockets_environment.rb
408
400
  - lib/webpack_rails/task.rb
401
+ - lib/webpack_rails/version.rb
409
402
  - lib/webpack_rails/webpack-task-dev-server.js
410
403
  - lib/webpack_rails/webpack-task-watch.js
411
404
  - lib/webpack_rails/webpack.rake
@@ -432,5 +425,5 @@ rubyforge_project:
432
425
  rubygems_version: 2.2.2
433
426
  signing_key:
434
427
  specification_version: 4
435
- summary: This is an webpack_rails!
428
+ summary: Integrates Webpack with Rails/Sprockets
436
429
  test_files: []
@@ -1,15 +0,0 @@
1
- require 'sprockets'
2
- require 'sprockets/index'
3
-
4
- module Sprockets
5
- class WebpackIndex < Index
6
- def find_asset(*args)
7
- if @environment.webpack_task_config[:dev_server] || @environment.webpack_task_config[:watch]
8
- # ensure webpack-dev-server is running or watcher has finished building
9
- WebpackRails::Task.run_webpack(@environment.webpack_task_config)
10
- end
11
-
12
- super
13
- end
14
- end
15
- end