Skip to content

Commit faf7f97

Browse files
authored
Merge branch 'rails:master' into patch-15
2 parents 384f290 + 32cd6b2 commit faf7f97

File tree

20 files changed

+473
-453
lines changed

20 files changed

+473
-453
lines changed

.github/workflows/jest.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@ jobs:
1313
runs-on: ${{ matrix.os }}
1414

1515
steps:
16+
- uses: actions/checkout@v2
17+
- name: Use Node.js ${{ matrix.node }}
18+
uses: actions/setup-node@v1
19+
with:
20+
node-version: ${{ matrix.node }}
21+
1622
- name: Install yarn maybe
17-
run: which yarn || sudo npm install -g yarn
23+
run: which yarn || npm install -g yarn
1824

19-
- uses: actions/checkout@v2
2025
- name: Get yarn cache directory path
2126
id: yarn-cache-dir-path
2227
run: echo "::set-output name=dir::$(yarn cache dir)"
@@ -29,11 +34,6 @@ jobs:
2934
restore-keys: |
3035
${{ runner.os }}-${{ matrix.node }}-yarn-
3136
32-
- name: Use Node.js ${{ matrix.node }}
33-
uses: actions/setup-node@v1
34-
with:
35-
node-version: ${{ matrix.node }}
36-
3737
- name: Install dependencies
3838
run: yarn --frozen-lockfile
3939

.github/workflows/js-lint.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ jobs:
99
strategy:
1010
matrix:
1111
os: [ubuntu-latest]
12-
node: [14.x]
12+
node: [14]
1313

1414
runs-on: ${{ matrix.os }}
1515

1616
steps:
17+
- name: Use Node.js ${{ matrix.node }}
18+
uses: actions/setup-node@v1
19+
with:
20+
node-version: ${{ matrix.node }}
21+
1722
- name: Install yarn maybe
18-
run: which yarn || sudo npm install -g yarn
23+
run: which yarn || npm install -g yarn
1924

2025
- uses: actions/checkout@v2
2126
- name: Get yarn cache directory path
@@ -30,11 +35,6 @@ jobs:
3035
restore-keys: |
3136
${{ runner.os }}-yarn-
3237
33-
- name: Use Node.js ${{ matrix.node }}
34-
uses: actions/setup-node@v1
35-
with:
36-
node-version: ${{ matrix.node }}
37-
3838
- name: Install dependencies
3939
run: yarn --frozen-lockfile
4040

.github/workflows/ruby.yml

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,67 +7,42 @@ jobs:
77
name: Ruby specs
88
runs-on: ${{ matrix.os }}
99
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.ruby == 'debug' || matrix.experimental }}
10-
env:
11-
BUNDLE_JOBS: 4
12-
BUNDLE_RETRY: 3
1310
strategy:
1411
fail-fast: false
1512
matrix:
1613
os: [ubuntu-latest]
17-
ruby: [
18-
2.4,
19-
2.5,
20-
2.6,
21-
2.7,
22-
3.0
23-
]
24-
gemfile: [
25-
"gemfiles/Gemfile-rails.5.2.x",
26-
"gemfiles/Gemfile-rails.6.0.x",
27-
"gemfiles/Gemfile-rails.6.1.x"
28-
]
14+
ruby:
15+
- 2.7
16+
- "3.0"
17+
gemfile:
18+
- gemfiles/Gemfile-rails.5.2.x
19+
- gemfiles/Gemfile-rails.6.0.x
20+
- gemfiles/Gemfile-rails.6.1.x
2921
exclude:
30-
- ruby: 2.4
31-
gemfile: gemfiles/Gemfile-rails.6.0.x
32-
- ruby: 2.4
33-
gemfile: gemfiles/Gemfile-rails.6.1.x
3422
- ruby: 2.5
3523
gemfile: gemfiles/Gemfile-rails.6.1.x
36-
- ruby: 3.0
24+
- ruby: "3.0"
3725
gemfile: gemfiles/Gemfile-rails.5.2.x
3826
experimental: [false]
3927
include:
4028
- ruby: 2.7
4129
os: ubuntu-latest
4230
gemfile: gemfiles/Gemfile-rails-edge
4331
experimental: true
44-
- ruby: 3.0
32+
- ruby: "3.0"
4533
os: ubuntu-latest
4634
gemfile: gemfiles/Gemfile-rails-edge
4735
experimental: true
4836

37+
env:
38+
BUNDLE_GEMFILE: ${{ matrix.gemfile }}
4939
steps:
5040
- uses: actions/checkout@v2
51-
- uses: actions/cache@v2
52-
with:
53-
path: /home/runner/bundle
54-
key: bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}-gems-${{ hashFiles(matrix.gemfile) }}-${{ hashFiles('**/*.gemspec') }}
55-
restore-keys: |
56-
bundle-use-ruby-${{ matrix.ruby }}-${{ matrix.gemfile }}-gems-
57-
58-
- name: Install yarn maybe
59-
run: which yarn || sudo npm install -g yarn
6041

6142
- uses: ruby/setup-ruby@v1
6243
with:
6344
ruby-version: ${{ matrix.ruby }}
64-
65-
- name: Bundle install
66-
run: |
67-
gem install bundler -v 2.1.4
68-
bundle config path /home/runner/bundle
69-
bundle config --global gemfile ${{ matrix.gemfile }}
70-
bundle install --jobs 4 --retry 3
45+
bundler-cache: true # Run "bundle install", and cache the result automatically.
7146

7247
- name: Ruby specs
73-
run: bundle exec rake test
48+
run: bundle exec rake

.rubocop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
require: rubocop-performance
22
AllCops:
3-
TargetRubyVersion: 2.4
3+
TargetRubyVersion: 2.7
44
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
55
# to ignore them, so only the ones explicitly set in this file are enabled.
66
DisabledByDefault: true

CONTRIBUTING.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,50 @@
33
1. Install [Yarn](https://yarnpkg.com/)
44

55
2. Run the following commands to set up the development environment.
6+
67
```
78
bundle install
89
yarn
910
```
1011

1112
## Making sure your changes pass all tests
13+
1214
There are a number of automated checks which run on GitHub Actions when a pull request is created.
15+
1316
You can run those checks on your own locally to make sure that your changes would not break the CI build.
1417

1518
### 1. Check the code for JavaScript style violations
19+
1620
```
1721
yarn lint
1822
```
1923

2024
### 2. Check the code for Ruby style violations
25+
2126
```
2227
bundle exec rubocop
2328
```
2429

2530
### 3. Run the JavaScript test suite
31+
2632
```
2733
yarn test
2834
```
2935

3036
### 4. Run the Ruby test suite
37+
3138
```
3239
bundle exec rake test
3340
```
41+
42+
#### 4.1 Run a single ruby test file
43+
44+
```
45+
bundle exec rake test TEST=test/rake_tasks_test.rb
46+
```
47+
48+
#### 4.2 Run a single ruby test
49+
50+
```
51+
ruby -I test test/rake_tasks_test.rb -n test_rake_webpacker_install
52+
```

README.md

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
Webpacker makes it easy to use the JavaScript pre-processor and bundler
1212
[Webpack v5](https://webpack.js.org/)
1313
to manage application-like JavaScript in Rails. It can coexist with the asset pipeline,
14-
leaving Webpack responsible solely for app-like JavaScript, or it can be used exclusively, making it also responsible for images, fronts, and CSS as well.
14+
leaving Webpack responsible solely for app-like JavaScript, or it can be used exclusively, making it also responsible for images, fronts, and CSS.
1515

1616
**NOTE:** The master branch now hosts the code for v6.x.x. Please refer to [5-x-stable](https://github.com/rails/webpacker/tree/5-x-stable) branch for 5.x documentation.
1717

@@ -78,10 +78,10 @@ leaving Webpack responsible solely for app-like JavaScript, or it can be used ex
7878

7979
## Installation
8080

81-
You can configure a new Rails application with Webpacker right from the start using the `--webpack` option:
81+
You can configure a new Rails application with Webpacker right from the start using the `-j webpack` option:
8282

8383
```bash
84-
rails new myapp --webpack
84+
rails new myapp -j webpack
8585
```
8686

8787
Or you can add it later by changing your `Gemfile`:
@@ -113,11 +113,10 @@ yarn install
113113
Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
114114

115115
```yml
116-
app/packs:
117-
├── entrypoints:
118-
# Only Webpack entry files here
119-
│ └── application.js
120-
│ └── application.css
116+
app/javascript:
117+
# Only Webpack entry files here
118+
└── application.js
119+
└── application.css
121120
└── src:
122121
│ └── my_component.js
123122
└── stylesheets:
@@ -139,13 +138,13 @@ packs with the chunks in your view, which creates html tags for all the chunks.
139138
The result looks like this:
140139

141140
```erb
142-
<%= javascript_pack_tag 'calendar', 'map' %>
141+
<%= javascript_pack_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
143142
144-
<script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
145-
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
146-
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
147-
<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
148-
<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
143+
<script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
144+
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
145+
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload" defer"></script>
146+
<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
147+
<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload" defer></script>
149148
```
150149

151150
**Important:** Pass all your pack names as multiple arguments, not multiple calls, when using `javascript_pack_tag` and the **`stylesheet_pack_tag`. Otherwise, you will get duplicated chunks on the page. Be especially careful if you might be calling these view helpers from your view, partials, and the layout for a page. You will need some logic to ensure you call the helpers only once with multiple arguments.
@@ -190,14 +189,15 @@ If you want to use images in your stylesheets:
190189
background-image: url('../images/logo.svg')
191190
}
192191
```
192+
##### Defer for `javascript_pack_tag`
193+
Note, the default of "defer" for the `javascript_pack_tag`. You can override that to `false`. If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/packs/entrypoints/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
193194

194195
#### Server-Side Rendering (SSR)
195196

196197
Note, if you are using server-side rendering of JavaScript with dynamic code-spliting, as is often done with extensions to Webpacker, like [React on Rails](https://github.com/shakacode/react_on_rails), your JavaScript should create the link prefetch HTML tags that you will use, so you won't need to use to `asset_pack_path` in those circumstances.
197198

198199
**Note:** In order for your styles or static assets files to be available in your view, you would need to link them in your "pack" or entry file. Otherwise, Webpack won't know to package up those files.
199200

200-
201201
### Development
202202

203203
Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`. Both are thin wrappers around the standard `webpack.js` and `webpack-dev-server.js` executables to ensure that the right configuration files and environmental variables are loaded based on your environment.
@@ -211,10 +211,19 @@ If you want to use live code reloading, or you have enough JavaScript that on-de
211211
./bin/webpack-dev-server
212212
213213
# watcher
214-
./bin/webpack --watch --colors --progress
214+
./bin/webpack --watch --progress
215215
216216
# standalone build
217-
./bin/webpack
217+
./bin/webpack --progress
218+
219+
# Help
220+
./bin/webpack help
221+
222+
# Version
223+
./bin/webpack version
224+
225+
# Info
226+
./bin/webpack info
218227
```
219228

220229
Once you start this webpack development server, Webpacker will automatically start proxying all webpack asset requests to this server. When you stop this server, Rails will detect that it's not running and Rails will revert back to on-demand compilation _if_ you have the `compile` option set to true in your `config/webpacker.yml`

docs/v6_upgrade.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@ This means you have to configure integration with frameworks yourself, but webpa
1212

1313
## How to upgrade to Webpacker 6
1414

15-
1. If your `source_path` is `app/javascript`, rename it to `app/packs`
16-
2. If your `source_entry_path` is `packs`, rename it to `entrypoints`
17-
3. Rename `config/webpack` to `config/webpack_old`
18-
4. Rename `config/webpacker.yml` to `config/webpacker_old.yml`
19-
5. Uninstall the current version of `webpack-dev-server`: `yarn remove webpack-dev-server`
20-
6. Remove .browserslistrc from the root of your Rails app
21-
7. Upgrade the Webpacker Ruby gem and NPM package
15+
1. Move your `app/javascript/packs/application.js` to `app/javascript/application.js`
16+
2. Rename `config/webpack` to `config/webpack_old`
17+
3. Rename `config/webpacker.yml` to `config/webpacker_old.yml`
18+
4. Uninstall the current version of `webpack-dev-server`: `yarn remove webpack-dev-server`
19+
5. Remove .browserslistrc from the root of your Rails app
20+
6. Upgrade the Webpacker Ruby gem and NPM package
2221

2322
Note: [Check the releases page to verify the latest version](https://github.com/rails/webpacker/releases), and make sure to install identical version numbers of webpacker gem and `@rails/webpacker` npm package. (Gems use a period and packages use a dot between the main version number and the beta version.)
2423

@@ -41,7 +40,7 @@ Example going to a specific version:
4140
bundle exec rails webpacker:install
4241
```
4342

44-
7. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` or `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/packs/entrypoints/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
43+
7. Update API usage of the view helpers by changing `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` to `javascript_pack_tag` and `stylesheet_pack_tag`. Ensure that your layouts and views will only have **at most one call** to `javascript_pack_tag` or `stylesheet_pack_tag`. You can now pass multiple bundles to these view helper methods. If you fail to changes this, you may experience performance issues, and other bugs related to multiple copies of React, like [issue 2932](https://github.com/rails/webpacker/issues/2932). If you expose jquery globally with `expose-loader,` by using `import $ from "expose-loader?exposes=$,jQuery!jquery"` in your `app/javascript/application.js`, pass the option `defer: false` to your `javascript_pack_tag`.
4544
8. If you are using any integrations like `css`, `React` or `TypeScript`. Please see https://github.com/rails/webpacker#integrations section on how they work in v6.
4645
9. Copy over any custom webpack config from `config/webpack_old`. Common code previously called 'environment' should be changed to 'base', and import `environment` changed to `webpackConfig`.
4746

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
11
/* eslint no-console:0 */
22
// This file is automatically compiled by Webpack, along with any other files
33
// present in this directory. You're encouraged to place your actual application logic in
4-
// a relevant structure within app/packs and only use these pack files to reference
4+
// a relevant structure within app/javascript and only use these pack files to reference
55
// that code so it'll be compiled.
66
//
77
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
88
// layout file, like app/views/layouts/application.html.erb
99

10-
// Uncomment to copy all static images under ../images to the output folder and reference
10+
// Uncomment to copy all static images under ./images to the output folder and reference
1111
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
1212
// or the `imagePath` JavaScript helper below.
1313
//
14-
// const images = require.context('../images', true)
14+
// const images = require.context('./images', true)
1515
// const imagePath = (name) => images(name, true)
16-
17-
// Activate Active Storage
18-
// import * as ActiveStorage from "@rails/activestorage"
19-
// ActiveStorage.start()

lib/install/bin/webpack

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
#!/usr/bin/env ruby
22

3-
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4-
ENV["NODE_ENV"] ||= "development"
5-
63
require "pathname"
7-
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
8-
Pathname.new(__FILE__).realpath)
9-
104
require "bundler/setup"
11-
125
require "webpacker"
136
require "webpacker/webpack_runner"
147

8+
ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
9+
ENV["NODE_ENV"] ||= "development"
10+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile", Pathname.new(__FILE__).realpath)
11+
1512
APP_ROOT = File.expand_path("..", __dir__)
1613
Dir.chdir(APP_ROOT) do
1714
Webpacker::WebpackRunner.run(ARGV)

lib/install/config/webpacker.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Note: You must restart bin/webpack-dev-server for changes to take effect
22

33
default: &default
4-
source_path: app/packs
5-
source_entry_path: entrypoints
4+
source_path: app/javascript
5+
source_entry_path: /
66
public_root_path: public
77
public_output_path: packs
88
cache_path: tmp/webpacker

0 commit comments

Comments
 (0)