webpacker 0.1 → 0.2
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/.gitignore +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +70 -0
- data/README.md +81 -8
- data/Rakefile +1 -0
- data/lib/install/bin/webpack-dev-server.tt +23 -0
- data/lib/install/bin/yarn.tt +10 -0
- data/lib/install/config/development.js +17 -6
- data/lib/install/config/production.js +10 -7
- data/lib/install/config/shared.js +32 -8
- data/lib/install/javascript/packs/application.js +9 -1
- data/lib/install/react/hello_react.js +16 -0
- data/lib/install/template.rb +10 -1
- data/lib/tasks/webpacker.rake +37 -2
- data/lib/webpacker/digests.rb +4 -0
- data/lib/webpacker/helper.rb +14 -1
- data/lib/webpacker/source.rb +10 -4
- data/webpacker.gemspec +4 -1
- metadata +38 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8718b611e0688ca042fc8c4e76cbac4037eb7ef8
|
4
|
+
data.tar.gz: 22a7a34b3326f4cb4da111d84875a0e5493a9794
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2faf426f4d370a0107f5fc865125c127ab2ef280dddb037d89214798f776b9cd2b29534c98059ac30e283a4946586f88176086b42e343ae6bfc489abfb3b1353
|
7
|
+
data.tar.gz: 9c4b9245412e474a8c248d3857c49fee082ca41d9663d30f8cf2ff474b061804136b0b3327961b6d6d918087eae2767a8d96b32a977a72f661cef6a10084df0b
|
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
/.bundle
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
webpacker (0.1)
|
5
|
+
activesupport (>= 3.0.0, < 5.1)
|
6
|
+
multi_json (~> 1.2)
|
7
|
+
railties (~> 5)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: https://rubygems.org/
|
11
|
+
specs:
|
12
|
+
actionpack (5.0.0.1)
|
13
|
+
actionview (= 5.0.0.1)
|
14
|
+
activesupport (= 5.0.0.1)
|
15
|
+
rack (~> 2.0)
|
16
|
+
rack-test (~> 0.6.3)
|
17
|
+
rails-dom-testing (~> 2.0)
|
18
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
19
|
+
actionview (5.0.0.1)
|
20
|
+
activesupport (= 5.0.0.1)
|
21
|
+
builder (~> 3.1)
|
22
|
+
erubis (~> 2.7.0)
|
23
|
+
rails-dom-testing (~> 2.0)
|
24
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
25
|
+
activesupport (5.0.0.1)
|
26
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
27
|
+
i18n (~> 0.7)
|
28
|
+
minitest (~> 5.1)
|
29
|
+
tzinfo (~> 1.1)
|
30
|
+
builder (3.2.2)
|
31
|
+
concurrent-ruby (1.0.2)
|
32
|
+
erubis (2.7.0)
|
33
|
+
i18n (0.7.0)
|
34
|
+
loofah (2.0.3)
|
35
|
+
nokogiri (>= 1.5.9)
|
36
|
+
method_source (0.8.2)
|
37
|
+
mini_portile2 (2.1.0)
|
38
|
+
minitest (5.10.1)
|
39
|
+
multi_json (1.12.1)
|
40
|
+
nokogiri (1.6.8.1)
|
41
|
+
mini_portile2 (~> 2.1.0)
|
42
|
+
rack (2.0.1)
|
43
|
+
rack-test (0.6.3)
|
44
|
+
rack (>= 1.0)
|
45
|
+
rails-dom-testing (2.0.1)
|
46
|
+
activesupport (>= 4.2.0, < 6.0)
|
47
|
+
nokogiri (~> 1.6.0)
|
48
|
+
rails-html-sanitizer (1.0.3)
|
49
|
+
loofah (~> 2.0)
|
50
|
+
railties (5.0.0.1)
|
51
|
+
actionpack (= 5.0.0.1)
|
52
|
+
activesupport (= 5.0.0.1)
|
53
|
+
method_source
|
54
|
+
rake (>= 0.8.7)
|
55
|
+
thor (>= 0.18.1, < 2.0)
|
56
|
+
rake (12.0.0)
|
57
|
+
thor (0.19.4)
|
58
|
+
thread_safe (0.3.5)
|
59
|
+
tzinfo (1.2.2)
|
60
|
+
thread_safe (~> 0.1)
|
61
|
+
|
62
|
+
PLATFORMS
|
63
|
+
ruby
|
64
|
+
|
65
|
+
DEPENDENCIES
|
66
|
+
bundler (~> 1.12)
|
67
|
+
webpacker!
|
68
|
+
|
69
|
+
BUNDLED WITH
|
70
|
+
1.12.1
|
data/README.md
CHANGED
@@ -1,18 +1,91 @@
|
|
1
1
|
# Webpacker
|
2
2
|
|
3
|
-
Webpacker makes it easy to use the JavaScript preprocessor and bundler Webpack
|
3
|
+
Webpacker makes it easy to use the JavaScript preprocessor and bundler [Webpack](http://webpack.github.io)
|
4
4
|
to manage application-like JavaScript in Rails. It coexists with the asset pipeline,
|
5
5
|
as the purpose is only to use Webpack for app-like JavaScript, not images, css, or
|
6
|
-
even JavaScript Sprinkles.
|
6
|
+
even JavaScript Sprinkles (that all continues to live in app/assets).
|
7
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.
|
10
|
-
|
11
|
-
|
8
|
+
It's designed to work with Rails 5.1+ and makes use of the [Yarn](https://yarnpkg.com/) dependency management
|
9
|
+
that's been made default from that version forward.
|
10
|
+
It's also currently compatible with Rails 5.0 stable but there's absolutely no warranty
|
11
|
+
it will still be in the future.
|
12
|
+
You can either make use of Webpacker during setup of a new application with `--webpack`
|
13
|
+
or you can add the gem and run `bin/rails webpacker:install` in an existing application.
|
12
14
|
|
13
|
-
When Webpacker has been installed...
|
14
15
|
|
15
|
-
|
16
|
+
## Binstubs
|
17
|
+
|
18
|
+
Webpacker ships with three binstubs: `./bin/webpack`, `./bin/webpack-watcher` and `./bin/webpack-dev-server`.
|
19
|
+
They're thin wrappers around the standard webpack.js executable, just to ensure that the right configuration
|
20
|
+
file is loaded and the node_modules from vendor are used.
|
21
|
+
|
22
|
+
In development, you'll need to run `./bin/webpack-watcher` in a separate terminal from
|
23
|
+
`./bin/rails server` to have your `app/javascript/packs/*.js` files compiled as you make changes.
|
24
|
+
If you'd rather not have to run the two processes separately by hand, you can use
|
25
|
+
[Foreman](http://ddollar.github.io/foreman/).
|
26
|
+
|
27
|
+
Alternatively, you can run `./bin/webpack-dev-server`. This will launch a
|
28
|
+
[Webpack Dev Server](https://webpack.github.io/docs/webpack-dev-server.html) listening on http://localhost:8080/
|
29
|
+
serving your pack files. It will recompile your files as you make changes. You also need to set
|
30
|
+
`config.x.webpacker[:dev_server_host]` in your `config/environment/development.rb` to tell Webpacker to load
|
31
|
+
your packs from the Webpack Dev Server. This setup allows you to leverage advanced Webpack features, such
|
32
|
+
as [Hot Module Replacement](https://webpack.github.io/docs/hot-module-replacement-with-webpack.html).
|
33
|
+
|
34
|
+
|
35
|
+
## Configuration
|
36
|
+
|
37
|
+
Webpacker gives you a default set of configuration files for development and production. They
|
38
|
+
all live together with the shared points in `config/webpack/*.js`. By default, you shouldn't have to
|
39
|
+
make any changes for a basic setup out the box. But this is where you do go if you need something
|
40
|
+
more advanced.
|
41
|
+
|
42
|
+
The configuration for what Webpack is supposed to compile by default rests on the convention that
|
43
|
+
every file in `app/javascript/packs/*` should be turned into their own output files (or entry points,
|
44
|
+
as Webpack calls it).
|
45
|
+
|
46
|
+
Let's say you're building a calendar. Your structure could look like this:
|
47
|
+
|
48
|
+
```erb
|
49
|
+
<%# app/views/layout/application.html.erb %>
|
50
|
+
<%= javascript_pack_tag 'calendar' %>
|
51
|
+
```
|
52
|
+
|
53
|
+
```js
|
54
|
+
// app/javascript/packs/calendar.js
|
55
|
+
require('calendar')
|
56
|
+
```
|
57
|
+
|
58
|
+
```
|
59
|
+
app/javascript/calendar/index.js // gets loaded by require('calendar')
|
60
|
+
app/javascript/calendar/components/grid.jsx
|
61
|
+
app/javascript/calendar/models/month.js
|
62
|
+
```
|
63
|
+
|
64
|
+
But it could also look a million other ways. The only convention that Webpacker enforces is the
|
65
|
+
one where entry points are automatically configured by the files in `app/javascript/packs`.
|
66
|
+
|
67
|
+
|
68
|
+
## Deployment
|
69
|
+
|
70
|
+
To compile all the packs during deployment, you can use the `rails webpacker:compile` command. This
|
71
|
+
will invoke the production configuration, which includes digesting. The `javascript_pack_tag` helper
|
72
|
+
method will automatically insert the correct digest when run in production mode. Just like the asset
|
73
|
+
pipeline does it.
|
74
|
+
|
75
|
+
|
76
|
+
## Ready for React
|
77
|
+
|
78
|
+
To use Webpacker with React, just create a new app with `rails new myapp --webpack=react` (or run `rails webpacker:install:react` on a Rails 5.1 app already setup with webpack), and all the relevant dependencies
|
79
|
+
will be added via yarn and changes to the configuration files made. Now you can create JSX files and
|
80
|
+
have them properly compiled automatically.
|
81
|
+
|
82
|
+
|
83
|
+
## Work left to do
|
84
|
+
|
85
|
+
- Make asset pipeline digests readable from webpack, so you can reference images etc
|
86
|
+
- Consider chunking setup
|
87
|
+
- Consider on-demand compiling with digests when digesting=true
|
88
|
+
- I'm sure a ton of other shit
|
16
89
|
|
17
90
|
## License
|
18
91
|
Webpacker is released under the [MIT License](http://www.opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,23 @@
|
|
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
|
+
WEBPACKER_BIN = "./node_modules/.bin/webpack-dev-server"
|
11
|
+
WEBPACK_CONFIG = "#{APP_PATH}/config/webpack/#{WEBPACK_ENV}.js"
|
12
|
+
|
13
|
+
# Warn the user if the configuration is not set
|
14
|
+
RAILS_ENV_CONFIG = File.join("config", "environments", "#{RAILS_ENV}.rb")
|
15
|
+
|
16
|
+
# Look into the environment file for a non-commented variable declaration
|
17
|
+
unless File.foreach(File.join(APP_PATH, RAILS_ENV_CONFIG)).detect { |line| line.match(/^\s*[^#]*config\.x\.webpacker\[\:dev_server_host\].*=/) }
|
18
|
+
puts "Warning: if you want to use webpack-dev-server, you need to tell Webpacker to serve asset packs from it. Please set config.x.webpacker[:dev_server_host] in #{RAILS_ENV_CONFIG}.\n\n"
|
19
|
+
end
|
20
|
+
|
21
|
+
Dir.chdir(VENDOR_PATH) do
|
22
|
+
exec "#{SET_NODE_PATH} #{WEBPACKER_BIN} --config #{WEBPACK_CONFIG} --content-base public/packs #{ARGV.join(" ")}"
|
23
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<%= shebang %>
|
2
|
+
VENDOR_PATH = File.expand_path('../vendor', __dir__)
|
3
|
+
Dir.chdir(VENDOR_PATH) do
|
4
|
+
begin
|
5
|
+
exec "yarnpkg #{ARGV.join(" ")}"
|
6
|
+
rescue Errno::ENOENT
|
7
|
+
puts "Yarn executable was not detected in the system."
|
8
|
+
puts "Download Yarn at https://yarnpkg.com/en/docs/install"
|
9
|
+
end
|
10
|
+
end
|
@@ -2,13 +2,24 @@
|
|
2
2
|
|
3
3
|
var path = require('path')
|
4
4
|
var webpack = require('webpack')
|
5
|
-
var
|
5
|
+
var merge = require('webpack-merge')
|
6
6
|
|
7
|
-
var config =
|
7
|
+
var config = require('./shared.js')
|
8
8
|
|
9
|
-
|
10
|
-
debug: true,
|
11
|
-
displayErrorDetails: true,
|
12
|
-
outputPathinfo: true,
|
9
|
+
module.exports = merge(config, {
|
13
10
|
devtool: 'sourcemap',
|
11
|
+
|
12
|
+
stats: {
|
13
|
+
errorDetails: true
|
14
|
+
},
|
15
|
+
|
16
|
+
output: {
|
17
|
+
pathinfo: true
|
18
|
+
},
|
19
|
+
|
20
|
+
plugins: [
|
21
|
+
new webpack.LoaderOptionsPlugin({
|
22
|
+
debug: true
|
23
|
+
})
|
24
|
+
]
|
14
25
|
})
|
@@ -2,13 +2,16 @@
|
|
2
2
|
|
3
3
|
var path = require('path')
|
4
4
|
var webpack = require('webpack')
|
5
|
-
var
|
5
|
+
var merge = require('webpack-merge')
|
6
6
|
|
7
|
-
var config =
|
7
|
+
var config = require('./shared.js')
|
8
8
|
|
9
|
-
|
9
|
+
module.exports = merge(config, {
|
10
|
+
output: { filename: "[name]-[hash].js" },
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
)
|
12
|
+
plugins: [
|
13
|
+
new webpack.LoaderOptionsPlugin({
|
14
|
+
minimize: true
|
15
|
+
})
|
16
|
+
]
|
17
|
+
})
|
@@ -2,30 +2,54 @@
|
|
2
2
|
|
3
3
|
var path = require('path')
|
4
4
|
var glob = require('glob')
|
5
|
-
var
|
5
|
+
var extname = require('path-complete-extname')
|
6
6
|
|
7
7
|
module.exports = {
|
8
|
-
entry:
|
8
|
+
entry: glob.sync(path.join('..', 'app', 'javascript', 'packs', '*.js*')).reduce(
|
9
|
+
function(map, entry) {
|
10
|
+
var basename = path.basename(entry, extname(entry))
|
11
|
+
map[basename] = entry
|
12
|
+
return map
|
13
|
+
}, {}
|
14
|
+
),
|
9
15
|
|
10
|
-
output: { filename: '[name].js', path: '
|
16
|
+
output: { filename: '[name].js', path: path.resolve('..', 'public', 'packs') },
|
11
17
|
|
12
18
|
module: {
|
13
|
-
|
14
|
-
{ test: /\.coffee
|
19
|
+
rules: [
|
20
|
+
{ test: /\.coffee(.erb)?$/, loader: "coffee-loader" },
|
21
|
+
{
|
22
|
+
test: /\.js(.erb)?$/,
|
23
|
+
exclude: /node_modules/,
|
24
|
+
loader: 'babel-loader',
|
25
|
+
options: {
|
26
|
+
presets: [
|
27
|
+
[ 'latest', { 'es2015': { 'modules': false } } ]
|
28
|
+
]
|
29
|
+
}
|
30
|
+
},
|
31
|
+
{
|
32
|
+
test: /\.erb$/,
|
33
|
+
enforce: 'pre',
|
34
|
+
loader: 'rails-erb-loader',
|
35
|
+
options: {
|
36
|
+
runner: '../bin/rails runner'
|
37
|
+
}
|
38
|
+
},
|
15
39
|
]
|
16
40
|
},
|
17
41
|
|
18
42
|
plugins: [],
|
19
43
|
|
20
44
|
resolve: {
|
21
|
-
extensions: [ '
|
22
|
-
|
45
|
+
extensions: [ '.js', '.coffee' ],
|
46
|
+
modules: [
|
23
47
|
path.resolve('../app/javascript'),
|
24
48
|
path.resolve('../vendor/node_modules')
|
25
49
|
]
|
26
50
|
},
|
27
51
|
|
28
52
|
resolveLoader: {
|
29
|
-
|
53
|
+
modules: [ path.resolve('../vendor/node_modules') ]
|
30
54
|
}
|
31
55
|
}
|
@@ -1 +1,9 @@
|
|
1
|
-
//
|
1
|
+
// This file is will automatically compiled by Webpack, along with any other files
|
2
|
+
// present in this directory. You're encouraged to place your actual application logic in
|
3
|
+
// a relevant structure within app/javascript, and only use these pack files to reference
|
4
|
+
// that code, so it'll be compiled.
|
5
|
+
//
|
6
|
+
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
|
7
|
+
// layout file, like app/views/layouts/application.html.erb
|
8
|
+
|
9
|
+
console.log("Hello World from Webpacker")
|
@@ -0,0 +1,16 @@
|
|
1
|
+
// Run this example by adding <%= javascript_pack_tag 'hello_react' %> to the head of your layout file,
|
2
|
+
// like app/views/layouts/application.html.erb. All it does is render <div>Hello React</div> at the bottom
|
3
|
+
// of the page.
|
4
|
+
|
5
|
+
import React from 'react'
|
6
|
+
import ReactDOM from 'react-dom'
|
7
|
+
|
8
|
+
class Hello extends React.Component {
|
9
|
+
render() {
|
10
|
+
return <div>Hello {this.props.name}!</div>
|
11
|
+
}
|
12
|
+
}
|
13
|
+
|
14
|
+
document.addEventListener("DOMContentLoaded", e => {
|
15
|
+
ReactDOM.render(<Hello name="React" />, document.body.appendChild(document.createElement('div')))
|
16
|
+
})
|
data/lib/install/template.rb
CHANGED
@@ -7,9 +7,18 @@ chmod 'bin', 0755 & ~File.umask, verbose: false
|
|
7
7
|
|
8
8
|
directory "#{INSTALL_PATH}/config", 'config/webpack'
|
9
9
|
|
10
|
-
|
10
|
+
append_to_file '.gitignore', <<-EOS
|
11
|
+
/public/packs
|
12
|
+
EOS
|
13
|
+
|
14
|
+
run './bin/yarn add --dev webpack@beta webpack-merge webpack-dev-server@beta path-complete-extname babel-loader babel-core babel-preset-latest coffee-loader coffee-script rails-erb-loader'
|
11
15
|
|
12
16
|
environment \
|
13
17
|
"# Make javascript_pack_tag lookup digest hash to enable long-term caching\n" +
|
14
18
|
" config.x.webpacker[:digesting] = true\n",
|
15
19
|
env: 'production'
|
20
|
+
|
21
|
+
environment \
|
22
|
+
"# Make javascript_pack_tag load assets from webpack-dev-server.\n" +
|
23
|
+
" # config.x.webpacker[:dev_server_host] = \"http://localhost:8080\"\n",
|
24
|
+
env: 'development'
|
data/lib/tasks/webpacker.rake
CHANGED
@@ -4,7 +4,7 @@ PACK_DIGESTS_PATH = PACKS_PATH.join('digests.json')
|
|
4
4
|
WEBPACKER_APP_TEMPLATE_PATH = File.expand_path('../install/template.rb', File.dirname(__FILE__))
|
5
5
|
|
6
6
|
namespace :webpacker do
|
7
|
-
desc "
|
7
|
+
desc "Compile javascript packs using webpack for production with digests"
|
8
8
|
task :compile do
|
9
9
|
webpack_digests_json = JSON.parse(`WEBPACK_ENV=production ./bin/webpack --json`)['assetsByChunkName'].to_json
|
10
10
|
|
@@ -15,8 +15,43 @@ namespace :webpacker do
|
|
15
15
|
puts webpack_digests_json
|
16
16
|
end
|
17
17
|
|
18
|
-
desc "
|
18
|
+
desc "Install webpacker in this application"
|
19
19
|
task :install do
|
20
20
|
exec "./bin/rails app:template LOCATION=#{WEBPACKER_APP_TEMPLATE_PATH}"
|
21
21
|
end
|
22
|
+
|
23
|
+
namespace :install do
|
24
|
+
desc "Install everything needed for react"
|
25
|
+
task :react do
|
26
|
+
config_path = Rails.root.join('config/webpack/shared.js')
|
27
|
+
config = File.read(config_path)
|
28
|
+
|
29
|
+
if config =~ /presets:\s*\[\s*\[\s*'latest'/
|
30
|
+
puts "Replacing loader presets to include react in #{config_path}"
|
31
|
+
config.gsub!(/presets:(\s*\[)(\s*)\[(\s)*'latest'/, "presets:\\1\\2'react',\\2[\\3'latest'")
|
32
|
+
else
|
33
|
+
puts "Couldn't automatically update loader presets in #{config_path}. Please set presets: [ 'react', [ 'latest', { 'es2015': { 'modules': false } } ] ]."
|
34
|
+
end
|
35
|
+
|
36
|
+
if config.include?("test: /\\.js(.erb)?$/")
|
37
|
+
puts "Replacing loader test to include react in #{config_path}"
|
38
|
+
config.gsub!("test: /\\.js(.erb)?$/", "test: /\\.jsx?(.erb)?$/")
|
39
|
+
else
|
40
|
+
puts "Couldn't automatically update loader test in #{config_path}. Please set test: /\.jsx?(.erb)?$/."
|
41
|
+
end
|
42
|
+
|
43
|
+
File.write config_path, config
|
44
|
+
|
45
|
+
puts "Copying react example to app/javascript/packs/hello_react.js"
|
46
|
+
FileUtils.copy File.expand_path('../install/react/hello_react.js', File.dirname(__FILE__)),
|
47
|
+
Rails.root.join('app/javascript/packs/hello_react.js')
|
48
|
+
|
49
|
+
exec './bin/yarn add --dev babel-preset-react && ./bin/yarn add react react-dom'
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Compile packs after we've compiled all other assets during precompilation
|
55
|
+
Rake::Task['assets:precompile'].enhance do
|
56
|
+
Rake::Task['webpacker:compile'].invoke
|
22
57
|
end
|
data/lib/webpacker/digests.rb
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
# Singleton registry for accessing the digested filenames computed by Webpack in production mode.
|
2
|
+
# This allows javascript_pack_tag to take a reference to, say, "calendar.js" and turn it into
|
3
|
+
# "calendar-1016838bab065ae1e314.js". These digested filenames are what enables you to long-term
|
4
|
+
# cache things in production.
|
1
5
|
class Webpacker::Digests
|
2
6
|
class_attribute :instance
|
3
7
|
|
data/lib/webpacker/helper.rb
CHANGED
@@ -1,7 +1,20 @@
|
|
1
1
|
require 'webpacker/source'
|
2
2
|
|
3
3
|
module Webpacker::Helper
|
4
|
+
# Creates a script tag that references the named pack file, as compiled by Webpack per the entries list
|
5
|
+
# in config/webpack/shared.js. By default, this list is auto-generated to match everything in
|
6
|
+
# app/javascript/packs/*.js. In production mode, the digested reference is automatically looked up.
|
7
|
+
#
|
8
|
+
# Examples:
|
9
|
+
#
|
10
|
+
# # In development mode:
|
11
|
+
# <%= javascript_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
|
12
|
+
# <script src="/packs/calendar.js" data-turbolinks-track="reload"></script>
|
13
|
+
#
|
14
|
+
# # In production mode:
|
15
|
+
# <%= javascript_pack_tag 'calendar', 'data-turbolinks-track': 'reload' %> # =>
|
16
|
+
# <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
4
17
|
def javascript_pack_tag(name, **options)
|
5
|
-
|
18
|
+
javascript_include_tag(Webpacker::Source.new(name).path, **options)
|
6
19
|
end
|
7
20
|
end
|
data/lib/webpacker/source.rb
CHANGED
@@ -1,10 +1,16 @@
|
|
1
|
+
# Translates a logical reference for a pack source into the final path needed in the HTML.
|
2
|
+
# This translation takes into account whether digesting is configured to happen, which it
|
3
|
+
# is by default in the production environment (as set via
|
4
|
+
# `Rails.configuration.x.webpacker[:digesting] = true`).
|
1
5
|
class Webpacker::Source
|
2
6
|
def initialize(name)
|
3
7
|
@name = name
|
4
8
|
end
|
5
9
|
|
6
10
|
def path
|
7
|
-
if
|
11
|
+
if config[:dev_server_host].present?
|
12
|
+
"#{config[:dev_server_host]}/#{filename}"
|
13
|
+
elsif config[:digesting]
|
8
14
|
"/packs/#{digested_filename}"
|
9
15
|
else
|
10
16
|
"/packs/#{filename}"
|
@@ -14,9 +20,9 @@ class Webpacker::Source
|
|
14
20
|
private
|
15
21
|
attr_accessor :name
|
16
22
|
|
17
|
-
def
|
18
|
-
Rails.configuration.x.webpacker
|
19
|
-
end
|
23
|
+
def config
|
24
|
+
Rails.configuration.x.webpacker
|
25
|
+
end
|
20
26
|
|
21
27
|
def digested_filename
|
22
28
|
Webpacker::Digests.lookup(name)
|
data/webpacker.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'webpacker'
|
3
|
-
s.version = '0.
|
3
|
+
s.version = '0.2'
|
4
4
|
s.authors = 'David Heinemeier Hansson'
|
5
5
|
s.email = 'david@basecamp.com'
|
6
6
|
s.summary = 'Use Webpack to manage app-like JavaScript modules in Rails'
|
@@ -11,6 +11,9 @@ Gem::Specification.new do |s|
|
|
11
11
|
|
12
12
|
s.add_dependency 'activesupport', '>= 3.0.0', '< 5.1'
|
13
13
|
s.add_dependency 'multi_json', '~> 1.2'
|
14
|
+
s.add_dependency 'railties', '~> 5'
|
15
|
+
|
16
|
+
s.add_development_dependency 'bundler', '~> 1.12'
|
14
17
|
|
15
18
|
s.files = `git ls-files`.split("\n")
|
16
19
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webpacker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.2'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Heinemeier Hansson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,20 +44,55 @@ dependencies:
|
|
44
44
|
- - "~>"
|
45
45
|
- !ruby/object:Gem::Version
|
46
46
|
version: '1.2'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: railties
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '5'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '5'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: bundler
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.12'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '1.12'
|
47
75
|
description:
|
48
76
|
email: david@basecamp.com
|
49
77
|
executables: []
|
50
78
|
extensions: []
|
51
79
|
extra_rdoc_files: []
|
52
80
|
files:
|
81
|
+
- ".gitignore"
|
82
|
+
- Gemfile
|
83
|
+
- Gemfile.lock
|
53
84
|
- MIT-LICENSE
|
54
85
|
- README.md
|
86
|
+
- Rakefile
|
87
|
+
- lib/install/bin/webpack-dev-server.tt
|
55
88
|
- lib/install/bin/webpack-watcher.tt
|
56
89
|
- lib/install/bin/webpack.tt
|
90
|
+
- lib/install/bin/yarn.tt
|
57
91
|
- lib/install/config/development.js
|
58
92
|
- lib/install/config/production.js
|
59
93
|
- lib/install/config/shared.js
|
60
94
|
- lib/install/javascript/packs/application.js
|
95
|
+
- lib/install/react/hello_react.js
|
61
96
|
- lib/install/template.rb
|
62
97
|
- lib/tasks/webpacker.rake
|
63
98
|
- lib/webpacker.rb
|
@@ -86,7 +121,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
121
|
version: '0'
|
87
122
|
requirements: []
|
88
123
|
rubyforge_project:
|
89
|
-
rubygems_version: 2.5.
|
124
|
+
rubygems_version: 2.5.2
|
90
125
|
signing_key:
|
91
126
|
specification_version: 4
|
92
127
|
summary: Use Webpack to manage app-like JavaScript modules in Rails
|