webpacker 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1b67ae76eb6b5825e3147654c956f617527bb5f1
4
+ data.tar.gz: a06d84b86eac617349551713e00c8f3bf42481b2
5
+ SHA512:
6
+ metadata.gz: 041403069acab101703d356979b189b4635151818ff5c1fd06d22def7928fb1d9726c4e1f25e57dbfa8ca21045fb2dcc2592ec2a79ee2efce01c958668ea2dbe
7
+ data.tar.gz: f05bcb4779c5b9dad44fa599d837ce9b4114ce40ba4f62c6422791d300e265e8a2d39bcfdedc80faf616220b7627842ce7dc8978194cb2913469622d903cb0a0
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 David Heinemeier Hansson, Basecamp
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,18 @@
1
+ # Webpacker
2
+
3
+ Webpacker makes it easy to use the JavaScript preprocessor and bundler Webpack
4
+ to manage application-like JavaScript in Rails. It coexists with the asset pipeline,
5
+ as the purpose is only to use Webpack for app-like JavaScript, not images, css, or
6
+ even JavaScript Sprinkles.
7
+
8
+ It's designed to work with Rails 5.1+ and makes use of the Yarn dependency management
9
+ that's been made default from that version forward. You can either make use of Webpacker
10
+ during setup of a new application with --webpack or you can uncomment the gem and run
11
+ `bin/rails webpacker:install` in an existing application.
12
+
13
+ When Webpacker has been installed...
14
+
15
+ FIXME: Write the rest...
16
+
17
+ ## License
18
+ Webpacker is released under the [MIT License](http://www.opensource.org/licenses/MIT).
@@ -0,0 +1,7 @@
1
+ <%= shebang %>
2
+
3
+ BIN_PATH = File.expand_path('.', __dir__)
4
+
5
+ Dir.chdir(BIN_PATH) do
6
+ exec "./webpack --watch --progress --color #{ARGV.join(" ")}"
7
+ end
@@ -0,0 +1,15 @@
1
+ <%= shebang %>
2
+
3
+ RAILS_ENV = ENV['RAILS_ENV'] || 'development'
4
+ WEBPACK_ENV = ENV['WEBPACK_ENV'] || RAILS_ENV
5
+
6
+ APP_PATH = File.expand_path('../', __dir__)
7
+ VENDOR_PATH = File.expand_path('../vendor', __dir__)
8
+
9
+ SET_NODE_PATH = "NODE_PATH=#{VENDOR_PATH}/node_modules"
10
+ WEBPACK_BIN = "./node_modules/webpack/bin/webpack.js"
11
+ WEBPACK_CONFIG = "#{APP_PATH}/config/webpack/#{WEBPACK_ENV}.js"
12
+
13
+ Dir.chdir(VENDOR_PATH) do
14
+ exec "#{SET_NODE_PATH} #{WEBPACK_BIN} --config #{WEBPACK_CONFIG} #{ARGV.join(" ")}"
15
+ end
@@ -0,0 +1,14 @@
1
+ // Note: You must restart bin/webpack-watcher for changes to take effect
2
+
3
+ var path = require('path')
4
+ var webpack = require('webpack')
5
+ var _ = require('lodash')
6
+
7
+ var config = module.exports = require('./shared.js')
8
+
9
+ config = _.merge(config, {
10
+ debug: true,
11
+ displayErrorDetails: true,
12
+ outputPathinfo: true,
13
+ devtool: 'sourcemap',
14
+ })
@@ -0,0 +1,14 @@
1
+ // Note: You must restart bin/webpack-watcher for changes to take effect
2
+
3
+ var path = require('path')
4
+ var webpack = require('webpack')
5
+ var _ = require('lodash')
6
+
7
+ var config = module.exports = require('./shared.js');
8
+
9
+ config.output = _.merge(config.output, { filename: '[name]-[hash].js' })
10
+
11
+ config.plugins.push(
12
+ new webpack.optimize.UglifyJsPlugin(),
13
+ new webpack.optimize.OccurenceOrderPlugin()
14
+ )
@@ -0,0 +1,31 @@
1
+ // Note: You must restart bin/webpack-watcher for changes to take effect
2
+
3
+ var path = require('path')
4
+ var glob = require('glob')
5
+ var _ = require('lodash')
6
+
7
+ module.exports = {
8
+ entry: _.keyBy(glob.sync('../app/javascript/packs/*.js'), function(entry) { return path.basename(entry, '.js') }),
9
+
10
+ output: { filename: '[name].js', path: '../public/packs' },
11
+
12
+ module: {
13
+ loaders: [
14
+ { test: /\.coffee$/, loader: "coffee-loader" }
15
+ ]
16
+ },
17
+
18
+ plugins: [],
19
+
20
+ resolve: {
21
+ extensions: [ '', '.js', '.coffee' ],
22
+ root: [
23
+ path.resolve('../app/javascript'),
24
+ path.resolve('../vendor/node_modules')
25
+ ]
26
+ },
27
+
28
+ resolveLoader: {
29
+ modulesDirectories: [ path.resolve('../vendor/node_modules') ]
30
+ }
31
+ }
@@ -0,0 +1 @@
1
+ // var React = require('react')
@@ -0,0 +1,15 @@
1
+ INSTALL_PATH = File.dirname(__FILE__)
2
+
3
+ directory "#{INSTALL_PATH}/javascript", 'app/javascript'
4
+
5
+ directory "#{INSTALL_PATH}/bin", 'bin'
6
+ chmod 'bin', 0755 & ~File.umask, verbose: false
7
+
8
+ directory "#{INSTALL_PATH}/config", 'config/webpack'
9
+
10
+ run './bin/yarn add webpack lodash'
11
+
12
+ environment \
13
+ "# Make javascript_pack_tag lookup digest hash to enable long-term caching\n" +
14
+ " config.x.webpacker[:digesting] = true\n",
15
+ env: 'production'
@@ -0,0 +1,22 @@
1
+ PACKS_PATH = Rails.root.join('public/packs')
2
+ PACK_DIGESTS_PATH = PACKS_PATH.join('digests.json')
3
+
4
+ WEBPACKER_APP_TEMPLATE_PATH = File.expand_path('../install/template.rb', File.dirname(__FILE__))
5
+
6
+ namespace :webpacker do
7
+ desc "compile javascript packs using webpack for production with digests"
8
+ task :compile do
9
+ webpack_digests_json = JSON.parse(`WEBPACK_ENV=production ./bin/webpack --json`)['assetsByChunkName'].to_json
10
+
11
+ FileUtils.mkdir_p(PACKS_PATH)
12
+ File.open(PACK_DIGESTS_PATH, 'w+') { |file| file.write webpack_digests_json }
13
+
14
+ puts "Compiled digests for all packs in #{PACK_DIGESTS_PATH}: "
15
+ puts webpack_digests_json
16
+ end
17
+
18
+ desc "install webpacker in this application"
19
+ task :install do
20
+ exec "./bin/rails app:template LOCATION=#{WEBPACKER_APP_TEMPLATE_PATH}"
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ module Webpacker
2
+ end
3
+
4
+ require 'webpacker/railtie' if defined?(Rails)
@@ -0,0 +1,36 @@
1
+ class Webpacker::Digests
2
+ class_attribute :instance
3
+
4
+ class << self
5
+ def load(path)
6
+ self.instance = new(path)
7
+ end
8
+
9
+ def lookup(name)
10
+ if instance
11
+ instance.lookup(name)
12
+ else
13
+ raise "Webpacker::Digests.load(path) must be called first"
14
+ end
15
+ end
16
+ end
17
+
18
+ def initialize(path)
19
+ @path = path
20
+ load
21
+ end
22
+
23
+ def lookup(name)
24
+ @digests[name.to_s]
25
+ end
26
+
27
+ private
28
+ def load
29
+ begin
30
+ @digests = JSON.parse(File.read(@path))
31
+ rescue Errno::ENOENT
32
+ Rails.logger.error \
33
+ "Missing digests file at #{@path}! You must first compile the packs via rails webpacker:compile"
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,7 @@
1
+ require 'webpacker/source'
2
+
3
+ module Webpacker::Helper
4
+ def javascript_pack_tag(name, **options)
5
+ tag.script src: Webpacker::Source.new(name).path, **options
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ require 'rails/railtie'
2
+
3
+ require 'webpacker/helper'
4
+ require 'webpacker/digests'
5
+
6
+ class Webpacker::Engine < ::Rails::Engine
7
+ initializer :webpacker do
8
+ ActiveSupport.on_load :action_controller do
9
+ ActionController::Base.helper Webpacker::Helper
10
+ end
11
+
12
+ if Rails.configuration.x.webpacker[:digesting]
13
+ Webpacker::Digests.load \
14
+ Rails.application.config.x.webpacker[:digests_path] ||
15
+ Rails.root.join('public/packs/digests.json')
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,28 @@
1
+ class Webpacker::Source
2
+ def initialize(name)
3
+ @name = name
4
+ end
5
+
6
+ def path
7
+ if digesting?
8
+ "/packs/#{digested_filename}"
9
+ else
10
+ "/packs/#{filename}"
11
+ end
12
+ end
13
+
14
+ private
15
+ attr_accessor :name
16
+
17
+ def digesting?
18
+ Rails.configuration.x.webpacker[:digesting]
19
+ end
20
+
21
+ def digested_filename
22
+ Webpacker::Digests.lookup(name)
23
+ end
24
+
25
+ def filename
26
+ "#{name}.js"
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'webpacker'
3
+ s.version = '0.1'
4
+ s.authors = 'David Heinemeier Hansson'
5
+ s.email = 'david@basecamp.com'
6
+ s.summary = 'Use Webpack to manage app-like JavaScript modules in Rails'
7
+ s.homepage = 'https://github.com/rails/webpacker'
8
+ s.license = 'MIT'
9
+
10
+ s.required_ruby_version = '>= 1.9.3'
11
+
12
+ s.add_dependency 'activesupport', '>= 3.0.0', '< 5.1'
13
+ s.add_dependency 'multi_json', '~> 1.2'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- test/*`.split("\n")
17
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webpacker
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - David Heinemeier Hansson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.0.0
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: 3.0.0
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: multi_json
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.2'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.2'
47
+ description:
48
+ email: david@basecamp.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - MIT-LICENSE
54
+ - README.md
55
+ - lib/install/bin/webpack-watcher.tt
56
+ - lib/install/bin/webpack.tt
57
+ - lib/install/config/development.js
58
+ - lib/install/config/production.js
59
+ - lib/install/config/shared.js
60
+ - lib/install/javascript/packs/application.js
61
+ - lib/install/template.rb
62
+ - lib/tasks/webpacker.rake
63
+ - lib/webpacker.rb
64
+ - lib/webpacker/digests.rb
65
+ - lib/webpacker/helper.rb
66
+ - lib/webpacker/railtie.rb
67
+ - lib/webpacker/source.rb
68
+ - webpacker.gemspec
69
+ homepage: https://github.com/rails/webpacker
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: 1.9.3
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - ">="
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.5.1
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: Use Webpack to manage app-like JavaScript modules in Rails
93
+ test_files: []