webpacker 5.2.1 → 6.0.0.beta.4
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/.eslintrc.js +1 -1
- data/.github/workflows/jest.yml +1 -1
- data/.github/workflows/js-lint.yml +1 -1
- data/.github/workflows/ruby.yml +9 -6
- data/.gitignore +2 -0
- data/.node-version +1 -1
- data/.rubocop.yml +11 -16
- data/6_0_upgrade.md +48 -0
- data/CHANGELOG.md +27 -0
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +23 -15
- data/README.md +252 -103
- data/config/README.md +3 -0
- data/config/webpacker.yml +1 -0
- data/lib/install/config/webpack/base.js +3 -0
- data/lib/install/config/webpack/development.js +2 -2
- data/lib/install/config/webpack/production.js +2 -2
- data/lib/install/config/webpack/test.js +2 -2
- data/lib/install/config/webpacker.yml +12 -39
- data/lib/install/{javascript/packs → packs/entrypoints}/application.js +5 -3
- data/lib/install/template.rb +36 -22
- data/lib/tasks/webpacker.rake +2 -11
- data/lib/tasks/webpacker/binstubs.rake +6 -4
- data/lib/tasks/webpacker/check_binstubs.rake +4 -4
- data/lib/tasks/webpacker/check_yarn.rake +1 -2
- data/lib/tasks/webpacker/compile.rake +4 -2
- data/lib/tasks/webpacker/info.rake +12 -10
- data/lib/tasks/webpacker/install.rake +6 -4
- data/lib/tasks/webpacker/verify_install.rake +2 -1
- data/lib/tasks/webpacker/yarn_install.rake +9 -1
- data/lib/webpacker/commands.rb +3 -2
- data/lib/webpacker/compiler.rb +16 -9
- data/lib/webpacker/configuration.rb +6 -30
- data/lib/webpacker/dev_server_runner.rb +23 -2
- data/lib/webpacker/helper.rb +26 -36
- data/lib/webpacker/manifest.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +6 -0
- data/package.json +23 -39
- data/package/__tests__/config.js +5 -37
- data/package/__tests__/development.js +11 -12
- data/package/__tests__/env.js +12 -4
- data/package/__tests__/index.js +9 -0
- data/package/__tests__/production.js +6 -6
- data/package/__tests__/staging.js +7 -6
- data/package/__tests__/test.js +4 -5
- data/package/babel/preset.js +55 -0
- data/package/config.js +3 -11
- data/package/env.js +8 -2
- data/package/environments/__tests__/base.js +19 -51
- data/package/environments/base.js +65 -125
- data/package/environments/development.js +46 -44
- data/package/environments/production.js +66 -64
- data/package/environments/test.js +2 -2
- data/package/index.js +13 -8
- data/package/rules/babel.js +9 -7
- data/package/rules/coffee.js +6 -0
- data/package/rules/erb.js +15 -0
- data/package/rules/file.js +21 -19
- data/package/rules/index.js +16 -18
- data/package/rules/less.js +22 -0
- data/package/rules/raw.js +5 -0
- data/package/rules/sass.js +12 -9
- data/package/rules/stylus.js +26 -0
- data/package/utils/get_style_rule.js +26 -36
- data/package/utils/helpers.js +26 -35
- data/test/compiler_test.rb +0 -12
- data/test/configuration_test.rb +3 -34
- data/test/dev_server_runner_test.rb +33 -6
- data/test/engine_rake_tasks_test.rb +39 -0
- data/test/helper_test.rb +15 -9
- data/test/mounted_app/Rakefile +4 -0
- data/test/mounted_app/test/dummy/Rakefile +3 -0
- data/test/mounted_app/test/dummy/bin/rails +3 -0
- data/test/mounted_app/test/dummy/bin/rake +3 -0
- data/test/mounted_app/test/dummy/config.ru +5 -0
- data/test/mounted_app/test/dummy/config/application.rb +10 -0
- data/test/mounted_app/test/dummy/config/environment.rb +3 -0
- data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
- data/test/mounted_app/test/dummy/package.json +7 -0
- data/test/rake_tasks_test.rb +1 -10
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.css +0 -0
- data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.js +0 -0
- data/test/test_app/config/webpacker.yml +3 -27
- data/test/test_app/config/webpacker_public_root.yml +0 -1
- data/test/test_app/public/packs/manifest.json +17 -13
- data/test/test_app/some.config.js +0 -0
- data/test/webpack_runner_test.rb +9 -3
- data/webpacker.gemspec +1 -1
- data/yarn.lock +1858 -4915
- metadata +54 -97
- data/.travis.yml +0 -43
- data/docs/assets.md +0 -119
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -308
- data/docs/deployment.md +0 -130
- data/docs/docker.md +0 -68
- data/docs/engines.md +0 -213
- data/docs/env.md +0 -63
- data/docs/es6.md +0 -72
- data/docs/folder-structure.md +0 -66
- data/docs/integrations.md +0 -220
- data/docs/misc.md +0 -23
- data/docs/props.md +0 -223
- data/docs/target.md +0 -22
- data/docs/testing.md +0 -136
- data/docs/troubleshooting.md +0 -158
- data/docs/typescript.md +0 -190
- data/docs/v4-upgrade.md +0 -142
- data/docs/webpack-dev-server.md +0 -92
- data/docs/webpack.md +0 -364
- data/docs/yarn.md +0 -23
- data/lib/install/angular.rb +0 -23
- data/lib/install/coffee.rb +0 -25
- data/lib/install/config/.browserslistrc +0 -1
- data/lib/install/config/babel.config.js +0 -70
- data/lib/install/config/postcss.config.js +0 -12
- data/lib/install/config/webpack/environment.js +0 -3
- data/lib/install/elm.rb +0 -39
- data/lib/install/erb.rb +0 -25
- data/lib/install/examples/angular/hello_angular.js +0 -7
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
- data/lib/install/examples/angular/hello_angular/index.ts +0 -8
- data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
- data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
- data/lib/install/examples/elm/Main.elm +0 -55
- data/lib/install/examples/elm/hello_elm.js +0 -16
- data/lib/install/examples/erb/hello_erb.js.erb +0 -6
- data/lib/install/examples/react/babel.config.js +0 -87
- data/lib/install/examples/react/hello_react.jsx +0 -26
- data/lib/install/examples/react/tsconfig.json +0 -21
- data/lib/install/examples/stimulus/application.js +0 -1
- data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
- data/lib/install/examples/stimulus/controllers/index.js +0 -9
- data/lib/install/examples/svelte/app.svelte +0 -11
- data/lib/install/examples/svelte/hello_svelte.js +0 -20
- data/lib/install/examples/typescript/hello_typescript.ts +0 -4
- data/lib/install/examples/typescript/tsconfig.json +0 -24
- data/lib/install/examples/vue/app.vue +0 -22
- data/lib/install/examples/vue/hello_vue.js +0 -72
- data/lib/install/loaders/coffee.js +0 -6
- data/lib/install/loaders/elm.js +0 -25
- data/lib/install/loaders/erb.js +0 -11
- data/lib/install/loaders/svelte.js +0 -9
- data/lib/install/loaders/vue.js +0 -6
- data/lib/install/react.rb +0 -18
- data/lib/install/stimulus.rb +0 -12
- data/lib/install/svelte.rb +0 -29
- data/lib/install/typescript.rb +0 -39
- data/lib/install/vue.rb +0 -49
- data/lib/tasks/installers.rake +0 -42
- data/package/config_types/__tests__/config_list.js +0 -118
- data/package/config_types/__tests__/config_object.js +0 -43
- data/package/config_types/config_list.js +0 -75
- data/package/config_types/config_object.js +0 -55
- data/package/config_types/index.js +0 -7
- data/package/rules/module.css.js +0 -3
- data/package/rules/module.sass.js +0 -8
- data/package/rules/node_modules.js +0 -22
- data/package/utils/__tests__/deep_assign.js +0 -32
- data/package/utils/__tests__/deep_merge.js +0 -10
- data/package/utils/__tests__/get_style_rule.js +0 -65
- data/package/utils/__tests__/objectify.js +0 -9
- data/package/utils/deep_assign.js +0 -22
- data/package/utils/deep_merge.js +0 -22
- data/package/utils/objectify.js +0 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fadee7aff74c3363618d5296a2cac880299b70d4d897249176662811ad7565d8
|
|
4
|
+
data.tar.gz: 9f5ab7267a7c1e88e9bf13a285407701e61ed0c15c74eceb5b4453d63ea245e7
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ce8f40137463fb0ac076ab3174a43ee8ab6ef3977e61e6302878827823227f11bd3191438e185d5cd11725e27d79184e40d598fbbbe4d0b2eed1e91bf6f45f36
|
|
7
|
+
data.tar.gz: 8741c6f00b555663a78e714a9930f764350ccf4d8f65809462b8930ce520059ca0f8d77833c9c3c8a0a7f47c6de1920949e9d73dad4400e5afcf4abfa46278e0
|
data/.eslintrc.js
CHANGED
data/.github/workflows/jest.yml
CHANGED
data/.github/workflows/ruby.yml
CHANGED
|
@@ -18,7 +18,8 @@ jobs:
|
|
|
18
18
|
2.4,
|
|
19
19
|
2.5,
|
|
20
20
|
2.6,
|
|
21
|
-
2.7
|
|
21
|
+
2.7,
|
|
22
|
+
3.0
|
|
22
23
|
]
|
|
23
24
|
gemfile: [
|
|
24
25
|
"gemfiles/Gemfile-rails.5.2.x",
|
|
@@ -27,13 +28,11 @@ jobs:
|
|
|
27
28
|
exclude:
|
|
28
29
|
- ruby: "2.4"
|
|
29
30
|
gemfile: gemfiles/Gemfile-rails.6.0.x
|
|
31
|
+
- ruby: "3.0"
|
|
32
|
+
gemfile: gemfiles/Gemfile-rails.5.2.x
|
|
30
33
|
experimental: [false]
|
|
31
34
|
include:
|
|
32
|
-
- ruby:
|
|
33
|
-
os: ubuntu-latest
|
|
34
|
-
gemfile: gemfiles/Gemfile-rails.6.0.x
|
|
35
|
-
experimental: true
|
|
36
|
-
- ruby: head
|
|
35
|
+
- ruby: 2.5
|
|
37
36
|
os: ubuntu-latest
|
|
38
37
|
gemfile: gemfiles/Gemfile-rails-edge
|
|
39
38
|
experimental: true
|
|
@@ -45,6 +44,10 @@ jobs:
|
|
|
45
44
|
os: ubuntu-latest
|
|
46
45
|
gemfile: gemfiles/Gemfile-rails-edge
|
|
47
46
|
experimental: true
|
|
47
|
+
- ruby: 3.0
|
|
48
|
+
os: ubuntu-latest
|
|
49
|
+
gemfile: gemfiles/Gemfile-rails-edge
|
|
50
|
+
experimental: true
|
|
48
51
|
|
|
49
52
|
steps:
|
|
50
53
|
- uses: actions/checkout@v2
|
data/.gitignore
CHANGED
data/.node-version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
10.
|
|
1
|
+
10.22.1
|
data/.rubocop.yml
CHANGED
|
@@ -1,23 +1,18 @@
|
|
|
1
1
|
require: rubocop-performance
|
|
2
2
|
AllCops:
|
|
3
|
-
TargetRubyVersion: 2.
|
|
3
|
+
TargetRubyVersion: 2.4
|
|
4
4
|
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
|
|
5
5
|
# to ignore them, so only the ones explicitly set in this file are enabled.
|
|
6
6
|
DisabledByDefault: true
|
|
7
7
|
Exclude:
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
8
|
+
- "lib/install/templates/**"
|
|
9
|
+
- "vendor/**/*"
|
|
10
|
+
- "node_modules/**/*"
|
|
11
11
|
|
|
12
12
|
# Prefer &&/|| over and/or.
|
|
13
13
|
Style/AndOr:
|
|
14
14
|
Enabled: true
|
|
15
15
|
|
|
16
|
-
# Do not use braces for hash literals when they are the last argument of a
|
|
17
|
-
# method call.
|
|
18
|
-
Style/BracesAroundHashParameters:
|
|
19
|
-
Enabled: true
|
|
20
|
-
|
|
21
16
|
# Align `when` with `case`.
|
|
22
17
|
Layout/CaseIndentation:
|
|
23
18
|
Enabled: true
|
|
@@ -50,7 +45,11 @@ Style/HashSyntax:
|
|
|
50
45
|
# extra level of indentation.
|
|
51
46
|
Layout/IndentationConsistency:
|
|
52
47
|
Enabled: true
|
|
53
|
-
EnforcedStyle:
|
|
48
|
+
EnforcedStyle: indented_internal_methods
|
|
49
|
+
|
|
50
|
+
# Detect hard tabs, no hard tabs.
|
|
51
|
+
Layout/IndentationStyle:
|
|
52
|
+
Enabled: true
|
|
54
53
|
|
|
55
54
|
# Two spaces, no tabs (for indentation).
|
|
56
55
|
Layout/IndentationWidth:
|
|
@@ -98,12 +97,8 @@ Style/StringLiterals:
|
|
|
98
97
|
Enabled: true
|
|
99
98
|
EnforcedStyle: double_quotes
|
|
100
99
|
|
|
101
|
-
# Detect hard tabs, no hard tabs.
|
|
102
|
-
Layout/Tab:
|
|
103
|
-
Enabled: true
|
|
104
|
-
|
|
105
100
|
# Blank lines should not have any spaces.
|
|
106
|
-
Layout/
|
|
101
|
+
Layout/TrailingEmptyLines:
|
|
107
102
|
Enabled: true
|
|
108
103
|
|
|
109
104
|
# No trailing whitespace.
|
|
@@ -111,7 +106,7 @@ Layout/TrailingWhitespace:
|
|
|
111
106
|
Enabled: true
|
|
112
107
|
|
|
113
108
|
# Use quotes for string literals when they are enough.
|
|
114
|
-
Style/
|
|
109
|
+
Style/RedundantPercentQ:
|
|
115
110
|
Enabled: true
|
|
116
111
|
|
|
117
112
|
# Align `end` with the matching keyword or starting expression except for
|
data/6_0_upgrade.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# To webpacker v6 from v5
|
|
2
|
+
|
|
3
|
+
This guide aims to help you migrating to webpacker 6. If you are using
|
|
4
|
+
vanilla webpacker install then hopefully, the upgrade should be really
|
|
5
|
+
straightforward.
|
|
6
|
+
|
|
7
|
+
## Preparation
|
|
8
|
+
|
|
9
|
+
1. If your `source_path` is `app/javascript`, rename it to `app/packs`
|
|
10
|
+
2. If your `source_entry_path` is `app/javascript/packs`, rename it to `app/packs/entrypoints`
|
|
11
|
+
3. Rename `config/webpack` to `config/webpack_old`
|
|
12
|
+
4. Rename `config/webpacker.yml` to `config/webpacker_old.yml`
|
|
13
|
+
5. Uninstall the current version of `webpack-dev-server`: `yarn remove webpack-dev-server`
|
|
14
|
+
6. Upgrade webpacker
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
# Gemfile
|
|
18
|
+
gem 'webpacker', '~> 6.0.0.pre.2'
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
bundle install
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
yarn add @rails/webpacker@next
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
bundle exec rails webpacker:install
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
- Change `javascript_pack_tag` and `stylesheet_pack_tag` to `javascript_packs_with_chunks_tag` and
|
|
34
|
+
`stylesheet_packs_with_chunks_tag`
|
|
35
|
+
|
|
36
|
+
7. 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.0.
|
|
37
|
+
|
|
38
|
+
8. Copy over any custom webpack config from `config/webpack_old`
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
// config/webpack/base.js
|
|
42
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
|
43
|
+
const customConfig = require('./custom')
|
|
44
|
+
|
|
45
|
+
module.exports = merge(webpackConfig, customConfig)
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
9. Copy over custom browserlist config from `.browserlistrc` if it exists into the `"browserlist"` key in `package.json` and remove `.browserslistrc`.
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,33 @@
|
|
|
2
2
|
|
|
3
3
|
**Please note that Webpacker 4.1.0 has an installer bug. Please use 4.2.0 or above**
|
|
4
4
|
|
|
5
|
+
## [[6.0.0]](https://github.com/rails/webpacker/compare/v5.1.1...master) - 2021-TBD
|
|
6
|
+
|
|
7
|
+
- `node_modules` will no longer be compiled by default. This primarily fixes [rails issue #35501](https://github.com/rails/rails/issues/35501) as well as [numerous other webpacker issues](https://github.com/rails/webpacker/issues/2131#issuecomment-581618497). The disabled loader can still be required explicitly via:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
const nodeModules = require('@rails/webpacker/rules/node_modules.js')
|
|
11
|
+
environment.loaders.append('nodeModules', nodeModules)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
- If you have added `environment.loaders.delete('nodeModules')` to your `environment.js`, this must be removed or you will receive an error (`Item nodeModules not found`).
|
|
15
|
+
- The install task will now set the `extract_css` default to `true` in all environments and generate a separate `application.css` file for the default `application` pack, as supported by multiple files per entry introduced in 5.0.0. [#2608](https://github.com/rails/webpacker/pull/2608)
|
|
16
|
+
- Webpacker's wrapper to the `splitChunks()` API will now default `runtimeChunk: 'single'` which will help prevent potential issues when using multiple entry points per page [#2708](https://github.com/rails/webpacker/pull/2708).
|
|
17
|
+
- Changes `@babel/preset-env` modules option to `'auto'` per recommendation in the Babel docs [#2709](https://github.com/rails/webpacker/pull/2709)
|
|
18
|
+
- Adds experimental Yarn 2 support. Note you must manually set `nodeLinker: node-modules` in your `.yarnrc.yml`.
|
|
19
|
+
|
|
20
|
+
- Fixes dev server issues [#2898](https://github.com/rails/webpacker/pull/2898)
|
|
21
|
+
|
|
22
|
+
### Breaking changes
|
|
23
|
+
|
|
24
|
+
- Simple webpack config
|
|
25
|
+
- Removed integration installers
|
|
26
|
+
- Splitchunks enabled by default
|
|
27
|
+
- CSS extraction enabled by default
|
|
28
|
+
- Optional CSS support
|
|
29
|
+
|
|
30
|
+
Please see upgrade [guide](./6_0_upgrade.md)
|
|
31
|
+
|
|
5
32
|
## [[5.2.1]](https://github.com/rails/webpacker/compare/v5.2.0...5.2.1) - 2020-08-17
|
|
6
33
|
|
|
7
34
|
- Revert [#1311](https://github.com/rails/webpacker/pull/1311).
|
data/CONTRIBUTING.md
CHANGED
|
@@ -9,7 +9,7 @@ yarn
|
|
|
9
9
|
```
|
|
10
10
|
|
|
11
11
|
## Making sure your changes pass all tests
|
|
12
|
-
There are a number of automated checks which run on
|
|
12
|
+
There are a number of automated checks which run on GitHub Actions when a pull request is created.
|
|
13
13
|
You can run those checks on your own locally to make sure that your changes would not break the CI build.
|
|
14
14
|
|
|
15
15
|
### 1. Check the code for JavaScript style violations
|
data/Gemfile.lock
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
webpacker (
|
|
4
|
+
webpacker (6.0.0.beta.4)
|
|
5
5
|
activesupport (>= 5.2)
|
|
6
6
|
rack-proxy (>= 0.6.1)
|
|
7
7
|
railties (>= 5.2)
|
|
@@ -75,7 +75,6 @@ GEM
|
|
|
75
75
|
activesupport (>= 4.2.0)
|
|
76
76
|
i18n (1.8.5)
|
|
77
77
|
concurrent-ruby (~> 1.0)
|
|
78
|
-
jaro_winkler (1.5.4)
|
|
79
78
|
loofah (2.6.0)
|
|
80
79
|
crass (~> 1.0.2)
|
|
81
80
|
nokogiri (>= 1.5.9)
|
|
@@ -86,14 +85,16 @@ GEM
|
|
|
86
85
|
method_source (1.0.0)
|
|
87
86
|
mimemagic (0.3.5)
|
|
88
87
|
mini_mime (1.0.2)
|
|
89
|
-
mini_portile2 (2.
|
|
90
|
-
minitest (5.14.
|
|
88
|
+
mini_portile2 (2.5.0)
|
|
89
|
+
minitest (5.14.3)
|
|
91
90
|
nio4r (2.5.2)
|
|
92
|
-
nokogiri (1.
|
|
93
|
-
mini_portile2 (~> 2.
|
|
91
|
+
nokogiri (1.11.1)
|
|
92
|
+
mini_portile2 (~> 2.5.0)
|
|
93
|
+
racc (~> 1.4)
|
|
94
94
|
parallel (1.19.2)
|
|
95
|
-
parser (2.7.
|
|
95
|
+
parser (2.7.2.0)
|
|
96
96
|
ast (~> 2.4.1)
|
|
97
|
+
racc (1.5.2)
|
|
97
98
|
rack (2.2.3)
|
|
98
99
|
rack-proxy (0.6.5)
|
|
99
100
|
rack
|
|
@@ -127,15 +128,22 @@ GEM
|
|
|
127
128
|
thor (>= 0.20.3, < 2.0)
|
|
128
129
|
rainbow (3.0.0)
|
|
129
130
|
rake (13.0.1)
|
|
130
|
-
|
|
131
|
-
|
|
131
|
+
regexp_parser (1.8.2)
|
|
132
|
+
rexml (3.2.4)
|
|
133
|
+
rubocop (0.93.1)
|
|
132
134
|
parallel (~> 1.10)
|
|
133
|
-
parser (>= 2.
|
|
135
|
+
parser (>= 2.7.1.5)
|
|
134
136
|
rainbow (>= 2.2.2, < 4.0)
|
|
137
|
+
regexp_parser (>= 1.8)
|
|
138
|
+
rexml
|
|
139
|
+
rubocop-ast (>= 0.6.0)
|
|
135
140
|
ruby-progressbar (~> 1.7)
|
|
136
|
-
unicode-display_width (>= 1.4.0, <
|
|
137
|
-
rubocop-
|
|
138
|
-
|
|
141
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
|
142
|
+
rubocop-ast (0.8.0)
|
|
143
|
+
parser (>= 2.7.1.5)
|
|
144
|
+
rubocop-performance (1.8.1)
|
|
145
|
+
rubocop (>= 0.87.0)
|
|
146
|
+
rubocop-ast (>= 0.4.0)
|
|
139
147
|
ruby-progressbar (1.10.1)
|
|
140
148
|
semantic_range (2.3.0)
|
|
141
149
|
sprockets (4.0.2)
|
|
@@ -149,7 +157,7 @@ GEM
|
|
|
149
157
|
thread_safe (0.3.6)
|
|
150
158
|
tzinfo (1.2.7)
|
|
151
159
|
thread_safe (~> 0.1)
|
|
152
|
-
unicode-display_width (1.
|
|
160
|
+
unicode-display_width (1.7.0)
|
|
153
161
|
websocket-driver (0.7.3)
|
|
154
162
|
websocket-extensions (>= 0.1.0)
|
|
155
163
|
websocket-extensions (0.1.5)
|
|
@@ -165,7 +173,7 @@ DEPENDENCIES
|
|
|
165
173
|
rack-proxy
|
|
166
174
|
rails
|
|
167
175
|
rake (>= 11.1)
|
|
168
|
-
rubocop (
|
|
176
|
+
rubocop (= 0.93.1)
|
|
169
177
|
rubocop-performance
|
|
170
178
|
semantic_range
|
|
171
179
|
webpacker!
|
data/README.md
CHANGED
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
# Webpacker
|
|
2
2
|
|
|
3
|
-
[](https://github.com/rails/webpacker/actions)
|
|
4
|
+
[](https://github.com/rails/webpacker/actions)
|
|
5
|
+
[](https://github.com/rails/webpacker/actions)
|
|
6
|
+
[](https://github.com/rails/webpacker/actions)
|
|
7
|
+
|
|
4
8
|
[](https://www.npmjs.com/package/@rails/webpacker)
|
|
5
9
|
[](https://rubygems.org/gems/webpacker)
|
|
6
10
|
|
|
7
11
|
Webpacker makes it easy to use the JavaScript pre-processor and bundler
|
|
8
|
-
[webpack
|
|
12
|
+
[webpack 5.x.x+](https://webpack.js.org/)
|
|
9
13
|
to manage application-like JavaScript in Rails. It coexists with the asset pipeline,
|
|
10
14
|
as the primary purpose for webpack is app-like JavaScript, not images, CSS, or
|
|
11
15
|
even JavaScript Sprinkles (that all continues to live in app/assets).
|
|
@@ -13,7 +17,7 @@ even JavaScript Sprinkles (that all continues to live in app/assets).
|
|
|
13
17
|
However, it is possible to use Webpacker for CSS, images and fonts assets as well,
|
|
14
18
|
in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
|
|
15
19
|
|
|
16
|
-
**NOTE:** The master branch now hosts the code for
|
|
20
|
+
**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.
|
|
17
21
|
|
|
18
22
|
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
|
|
19
23
|
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
|
|
@@ -28,16 +32,6 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
|
28
32
|
- [Webpack Configuration](#webpack-configuration)
|
|
29
33
|
- [Custom Rails environments](#custom-rails-environments)
|
|
30
34
|
- [Upgrading](#upgrading)
|
|
31
|
-
- [Integrations](#integrations)
|
|
32
|
-
- [React](./docs/integrations.md#react)
|
|
33
|
-
- [Angular with TypeScript](./docs/integrations.md#angular-with-typescript)
|
|
34
|
-
- [Vue](./docs/integrations.md#vue)
|
|
35
|
-
- [Elm](./docs/integrations.md#elm)
|
|
36
|
-
- [Stimulus](./docs/integrations.md#stimulus)
|
|
37
|
-
- [Svelte](./docs/integrations.md#svelte)
|
|
38
|
-
- [Typescript](./docs/typescript.md)
|
|
39
|
-
- [CoffeeScript](./docs/integrations.md#coffeescript)
|
|
40
|
-
- [Erb](./docs/integrations.md#erb)
|
|
41
35
|
- [Paths](#paths)
|
|
42
36
|
- [Resolved](#resolved)
|
|
43
37
|
- [Watched](#watched)
|
|
@@ -52,23 +46,28 @@ in which case you may not even need the asset pipeline. This is mostly relevant
|
|
|
52
46
|
|
|
53
47
|
- Ruby 2.4+
|
|
54
48
|
- Rails 5.2+
|
|
55
|
-
- Node.js 10.
|
|
49
|
+
- Node.js 10.22.1+ || 12+ || 14+
|
|
56
50
|
- Yarn 1.x+
|
|
57
51
|
|
|
58
52
|
## Features
|
|
59
53
|
|
|
60
|
-
- [webpack
|
|
54
|
+
- [webpack 5.x.x](https://webpack.js.org/)
|
|
61
55
|
- ES6 with [babel](https://babeljs.io/)
|
|
62
56
|
- Automatic code splitting using multiple entry points
|
|
63
|
-
- Stylesheets - Sass and CSS
|
|
64
|
-
- Images and fonts
|
|
65
|
-
- PostCSS - Auto-Prefixer
|
|
66
57
|
- Asset compression, source-maps, and minification
|
|
67
58
|
- CDN support
|
|
68
|
-
- React, Angular, Elm and Vue support out-of-the-box
|
|
69
59
|
- Rails view helpers
|
|
70
60
|
- Extensible and configurable
|
|
71
61
|
|
|
62
|
+
### Optional support\*
|
|
63
|
+
|
|
64
|
+
_requires extra packages to be installed_
|
|
65
|
+
|
|
66
|
+
- Stylesheets - Sass, Less, Stylus and Css, PostCSS
|
|
67
|
+
- CoffeeScript
|
|
68
|
+
- TypeScript
|
|
69
|
+
- React
|
|
70
|
+
|
|
72
71
|
## Installation
|
|
73
72
|
|
|
74
73
|
You can either add Webpacker during setup of a new Rails 5.1+ application
|
|
@@ -83,12 +82,11 @@ Or add it to your `Gemfile`:
|
|
|
83
82
|
|
|
84
83
|
```ruby
|
|
85
84
|
# Gemfile
|
|
86
|
-
gem 'webpacker', '~>
|
|
85
|
+
gem 'webpacker', '~> 6.x'
|
|
87
86
|
|
|
88
87
|
# OR if you prefer to use master
|
|
89
88
|
gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
|
|
90
89
|
yarn add https://github.com/rails/webpacker.git
|
|
91
|
-
yarn add core-js regenerator-runtime
|
|
92
90
|
```
|
|
93
91
|
|
|
94
92
|
Finally, run the following to install Webpacker:
|
|
@@ -118,9 +116,9 @@ yarn install
|
|
|
118
116
|
Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
|
|
119
117
|
|
|
120
118
|
```yml
|
|
121
|
-
app/
|
|
122
|
-
├──
|
|
123
|
-
│ #
|
|
119
|
+
app/packs:
|
|
120
|
+
├── entrypoints:
|
|
121
|
+
│ # Only webpack entry files here
|
|
124
122
|
│ └── application.js
|
|
125
123
|
│ └── application.css
|
|
126
124
|
└── src:
|
|
@@ -131,56 +129,44 @@ app/javascript:
|
|
|
131
129
|
└── logo.svg
|
|
132
130
|
```
|
|
133
131
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
```js
|
|
137
|
-
import 'core-js/stable'
|
|
138
|
-
import 'regenerator-runtime/runtime'
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
|
|
142
|
-
If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
|
|
132
|
+
You can then link the JavaScript pack in Rails views using the `javascript_packs_with_chunks_tag` helper. If you have styles imported in your pack file, you can link them by using `stylesheet_packs_with_chunks_tag`:
|
|
143
133
|
|
|
144
134
|
```erb
|
|
145
|
-
<%=
|
|
146
|
-
<%=
|
|
135
|
+
<%= javascript_packs_with_chunks_tag 'application' %>
|
|
136
|
+
<%= stylesheet_packs_with_chunks_tag 'application' %>
|
|
147
137
|
```
|
|
148
138
|
|
|
149
|
-
If you want to link a static asset for `<
|
|
150
|
-
can use the `asset_pack_path` helper:
|
|
151
|
-
|
|
139
|
+
If you want to link a static asset for `<img />` tag, you can use the `asset_pack_path` helper:
|
|
152
140
|
```erb
|
|
153
|
-
<link rel="prefetch" href="<%= asset_pack_path 'application.css' %>" />
|
|
154
141
|
<img src="<%= asset_pack_path 'images/logo.svg' %>" />
|
|
155
142
|
```
|
|
156
143
|
|
|
157
|
-
|
|
158
|
-
tags for a pack and all the dependent chunks.
|
|
159
|
-
|
|
144
|
+
Or use the dedicated helper:
|
|
160
145
|
```erb
|
|
161
|
-
<%=
|
|
162
|
-
|
|
163
|
-
<script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
|
164
|
-
<script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
|
165
|
-
<script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
|
166
|
-
<script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
|
167
|
-
<script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
|
|
146
|
+
<%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
|
|
147
|
+
<%= image_pack_tag 'picture.png', srcset: { 'picture-2x.png' => '2x' } %>
|
|
168
148
|
```
|
|
169
149
|
|
|
170
|
-
|
|
171
|
-
|
|
150
|
+
If you want to create a favicon:
|
|
151
|
+
```erb
|
|
152
|
+
<%= favicon_pack_tag 'mb-icon.png', rel: 'apple-touch-icon', type: 'image/png' %>
|
|
153
|
+
```
|
|
172
154
|
|
|
155
|
+
If you want to preload a static asset in your `<head>`, you can use the `preload_pack_asset` helper:
|
|
173
156
|
```erb
|
|
174
|
-
|
|
175
|
-
|
|
157
|
+
<%= preload_pack_asset 'fonts/fa-regular-400.woff2' %>
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
If you want to use images in your stylesheets:
|
|
176
161
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
162
|
+
```css
|
|
163
|
+
.foo {
|
|
164
|
+
background-image: url('../images/logo.svg')
|
|
165
|
+
}
|
|
180
166
|
```
|
|
181
167
|
|
|
182
168
|
**Note:** In order for your styles or static assets files to be available in your view,
|
|
183
|
-
you would need to link them in your
|
|
169
|
+
you would need to link them in your `pack` or entry file.
|
|
184
170
|
|
|
185
171
|
### Development
|
|
186
172
|
|
|
@@ -196,7 +182,7 @@ to the standard Rails log.
|
|
|
196
182
|
|
|
197
183
|
If you want to use live code reloading, or you have enough JavaScript that on-demand compilation is too slow, you'll need to run `./bin/webpack-dev-server` or `ruby ./bin/webpack-dev-server`. Windows users will need to run these commands
|
|
198
184
|
in a terminal separate from `bundle exec rails s`. This process will watch for changes
|
|
199
|
-
in the `app/
|
|
185
|
+
in the `app/packs/entrypoints/*.js` files and automatically reload the browser to match.
|
|
200
186
|
|
|
201
187
|
```bash
|
|
202
188
|
# webpack dev server
|
|
@@ -244,7 +230,208 @@ WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
|
|
|
244
230
|
|
|
245
231
|
### Webpack Configuration
|
|
246
232
|
|
|
247
|
-
|
|
233
|
+
Webpacker gives you a default set of configuration files for test, development and
|
|
234
|
+
production environments in `config/webpack/*.js`. You can configure each individual
|
|
235
|
+
environment in their respective files or configure them all in the base
|
|
236
|
+
`config/webpack/base.js` file.
|
|
237
|
+
|
|
238
|
+
By default, you don't need to make any changes to `config/webpack/*.js`
|
|
239
|
+
files since it's all standard production-ready configuration. However,
|
|
240
|
+
if you do need to customize or add a new loader, this is where you would go.
|
|
241
|
+
|
|
242
|
+
Here is how you can modify webpack configuration:
|
|
243
|
+
|
|
244
|
+
You might add separate files to keep your code more organized.
|
|
245
|
+
|
|
246
|
+
```js
|
|
247
|
+
// config/webpack/custom.js
|
|
248
|
+
module.exports = {
|
|
249
|
+
resolve: {
|
|
250
|
+
alias: {
|
|
251
|
+
jquery: 'jquery/src/jquery',
|
|
252
|
+
vue: 'vue/dist/vue.js',
|
|
253
|
+
React: 'react',
|
|
254
|
+
ReactDOM: 'react-dom',
|
|
255
|
+
vue_resource: 'vue-resource/dist/vue-resource'
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
Then `require` this file in your `config/webpack/base.js`:
|
|
262
|
+
|
|
263
|
+
```js
|
|
264
|
+
// config/webpack/base.js
|
|
265
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
|
266
|
+
const customConfig = require('./custom')
|
|
267
|
+
|
|
268
|
+
module.exports = merge(webpackConfig, customConfig)
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
If you need access to configs within Webpacker's configuration,
|
|
272
|
+
you can import them like so:
|
|
273
|
+
|
|
274
|
+
```js
|
|
275
|
+
// config/webpack/base.js
|
|
276
|
+
const { webpackConfig } = require('@rails/webpacker')
|
|
277
|
+
|
|
278
|
+
console.log(webpackConfig.output_path)
|
|
279
|
+
console.log(webpackConfig.source_path)
|
|
280
|
+
```
|
|
281
|
+
|
|
282
|
+
### Integrations
|
|
283
|
+
|
|
284
|
+
Webpacker out of the box supports JS and static assets (fonts, images etc.)
|
|
285
|
+
compilation. To enable support for CoffeeScript or TypeScript install
|
|
286
|
+
relevant packages,
|
|
287
|
+
|
|
288
|
+
#### CoffeeScript
|
|
289
|
+
|
|
290
|
+
```bash
|
|
291
|
+
yarn add coffeescript coffee-loader
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
#### TypeScript
|
|
295
|
+
|
|
296
|
+
```bash
|
|
297
|
+
yarn add typescript @babel/preset-typescript
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
Add tsconfig.json
|
|
301
|
+
|
|
302
|
+
```json
|
|
303
|
+
{
|
|
304
|
+
"compilerOptions": {
|
|
305
|
+
"declaration": false,
|
|
306
|
+
"emitDecoratorMetadata": true,
|
|
307
|
+
"experimentalDecorators": true,
|
|
308
|
+
"lib": ["es6", "dom"],
|
|
309
|
+
"module": "es6",
|
|
310
|
+
"moduleResolution": "node",
|
|
311
|
+
"baseUrl": ".",
|
|
312
|
+
"paths": {
|
|
313
|
+
"*": ["node_modules/*", "app/packs/*"]
|
|
314
|
+
},
|
|
315
|
+
"sourceMap": true,
|
|
316
|
+
"target": "es5",
|
|
317
|
+
"noEmit": true
|
|
318
|
+
},
|
|
319
|
+
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
|
320
|
+
"compileOnSave": false
|
|
321
|
+
}
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
#### CSS
|
|
325
|
+
|
|
326
|
+
To enable CSS support in your application, add following packages,
|
|
327
|
+
|
|
328
|
+
```bash
|
|
329
|
+
yarn add css-loader mini-css-extract-plugin css-minimizer-webpack-plugin
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
optionally, add css extension to webpack config for easy resolution
|
|
333
|
+
|
|
334
|
+
```js
|
|
335
|
+
// config/webpack/base.js
|
|
336
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
|
337
|
+
const customConfig = {
|
|
338
|
+
resolve: {
|
|
339
|
+
extensions: ['.css']
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
module.exports = merge(webpackConfig, customConfig)
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
To enable postcss, sass or less support, add css support first and
|
|
347
|
+
then add the relevant pre-processors:
|
|
348
|
+
|
|
349
|
+
#### Postcss
|
|
350
|
+
|
|
351
|
+
```bash
|
|
352
|
+
yarn add postcss-loader
|
|
353
|
+
```
|
|
354
|
+
|
|
355
|
+
#### Sass
|
|
356
|
+
|
|
357
|
+
```bash
|
|
358
|
+
yarn add sass sass-loader
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
#### Less
|
|
362
|
+
|
|
363
|
+
```bash
|
|
364
|
+
yarn add less less-loader
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
#### Stylus
|
|
368
|
+
|
|
369
|
+
```bash
|
|
370
|
+
yarn add stylus stylus-loader
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
#### React
|
|
374
|
+
|
|
375
|
+
React is supported and you just need to add relevant packages,
|
|
376
|
+
|
|
377
|
+
```bash
|
|
378
|
+
yarn add react react-dom @babel/preset-react
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
if you are using typescript, update your `tsconfig.json`
|
|
382
|
+
|
|
383
|
+
```json
|
|
384
|
+
{
|
|
385
|
+
"compilerOptions": {
|
|
386
|
+
"declaration": false,
|
|
387
|
+
"emitDecoratorMetadata": true,
|
|
388
|
+
"experimentalDecorators": true,
|
|
389
|
+
"lib": ["es6", "dom"],
|
|
390
|
+
"module": "es6",
|
|
391
|
+
"moduleResolution": "node",
|
|
392
|
+
"sourceMap": true,
|
|
393
|
+
"target": "es5",
|
|
394
|
+
"jsx": "react",
|
|
395
|
+
"noEmit": true
|
|
396
|
+
},
|
|
397
|
+
"exclude": ["**/*.spec.ts", "node_modules", "vendor", "public"],
|
|
398
|
+
"compileOnSave": false
|
|
399
|
+
}
|
|
400
|
+
```
|
|
401
|
+
|
|
402
|
+
#### Other frameworks
|
|
403
|
+
|
|
404
|
+
Please follow webpack integration guide for relevant framework or library,
|
|
405
|
+
|
|
406
|
+
1. [Svelte](https://github.com/sveltejs/svelte-loader#install)
|
|
407
|
+
2. [Angular](https://v2.angular.io/docs/ts/latest/guide/webpack.html#!#configure-webpack)
|
|
408
|
+
3. [Vue](https://vue-loader.vuejs.org/guide/)
|
|
409
|
+
|
|
410
|
+
For example to add Vue support:
|
|
411
|
+
```js
|
|
412
|
+
// config/webpack/rules/vue.js
|
|
413
|
+
const VueLoaderPlugin = require('vue-loader/lib/plugin')
|
|
414
|
+
|
|
415
|
+
module.exports = {
|
|
416
|
+
module: {
|
|
417
|
+
rules: [
|
|
418
|
+
{
|
|
419
|
+
test: /\.vue$/,
|
|
420
|
+
loader: 'vue-loader'
|
|
421
|
+
}
|
|
422
|
+
]
|
|
423
|
+
},
|
|
424
|
+
plugins: [new VueLoaderPlugin()]
|
|
425
|
+
}
|
|
426
|
+
```
|
|
427
|
+
|
|
428
|
+
```js
|
|
429
|
+
// config/webpack/base.js
|
|
430
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
|
431
|
+
const vueConfig = require('./rules/vue')
|
|
432
|
+
|
|
433
|
+
module.exports = merge(webpackConfig, vueConfig)
|
|
434
|
+
```
|
|
248
435
|
|
|
249
436
|
### Custom Rails environments
|
|
250
437
|
|
|
@@ -301,7 +488,7 @@ You can run following commands to upgrade Webpacker to the latest stable version
|
|
|
301
488
|
|
|
302
489
|
```bash
|
|
303
490
|
bundle update webpacker
|
|
304
|
-
rails webpacker:
|
|
491
|
+
rails webpacker:install
|
|
305
492
|
yarn upgrade @rails/webpacker --latest
|
|
306
493
|
yarn upgrade webpack-dev-server --latest
|
|
307
494
|
|
|
@@ -309,24 +496,6 @@ yarn upgrade webpack-dev-server --latest
|
|
|
309
496
|
yarn add @rails/webpacker@next
|
|
310
497
|
```
|
|
311
498
|
|
|
312
|
-
## Integrations
|
|
313
|
-
|
|
314
|
-
Webpacker ships with basic out-of-the-box integration. You can see a list of available commands/tasks by running `bundle exec rails webpacker`.
|
|
315
|
-
|
|
316
|
-
Included install integrations:
|
|
317
|
-
|
|
318
|
-
- [React](./docs/integrations.md#React)
|
|
319
|
-
- [Angular with TypeScript](./docs/integrations.md#Angular-with-TypeScript)
|
|
320
|
-
- [Vue](./docs/integrations.md#Vue)
|
|
321
|
-
- [Elm](./docs/integrations.md#Elm)
|
|
322
|
-
- [Svelte](./docs/integrations.md#Svelte)
|
|
323
|
-
- [Stimulus](./docs/integrations.md#Stimulus)
|
|
324
|
-
- [CoffeeScript](./docs/integrations.md#CoffeeScript)
|
|
325
|
-
- [Typescript](./docs/typescript.md)
|
|
326
|
-
- [Erb](./docs/integrations.md#Erb)
|
|
327
|
-
|
|
328
|
-
See [Integrations](./docs/integrations.md) for further details.
|
|
329
|
-
|
|
330
499
|
## Paths
|
|
331
500
|
|
|
332
501
|
By default, Webpacker ships with simple conventions for where the JavaScript
|
|
@@ -334,13 +503,13 @@ app files and compiled webpack bundles will go in your Rails app.
|
|
|
334
503
|
All these options are configurable from `config/webpacker.yml` file.
|
|
335
504
|
|
|
336
505
|
The configuration for what webpack is supposed to compile by default rests
|
|
337
|
-
on the convention that every file in `app/
|
|
506
|
+
on the convention that every file in `app/packs/entrypoints/*`**(default)**
|
|
338
507
|
or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration
|
|
339
508
|
is turned into their own output files (or entry points, as webpack calls it). Therefore you don't want to put anything inside `packs` directory that you do not want to be
|
|
340
509
|
an entry file. As a rule of thumb, put all files you want to link in your views inside
|
|
341
|
-
"packs" directory and keep everything else under `app/
|
|
510
|
+
"packs" directory and keep everything else under `app/packs`.
|
|
342
511
|
|
|
343
|
-
Suppose you want to change the source directory from `app/
|
|
512
|
+
Suppose you want to change the source directory from `app/packs`
|
|
344
513
|
to `frontend` and output to `assets/packs`. This is how you would do it:
|
|
345
514
|
|
|
346
515
|
```yml
|
|
@@ -362,7 +531,7 @@ development:
|
|
|
362
531
|
|
|
363
532
|
If you have `hmr` turned to true, then the `stylesheet_pack_tag` generates no output, as you will want to configure your styles to be inlined in your JavaScript for hot reloading. During production and testing, the `stylesheet_pack_tag` will create the appropriate HTML tags.
|
|
364
533
|
|
|
365
|
-
###
|
|
534
|
+
### Additional paths
|
|
366
535
|
|
|
367
536
|
If you are adding Webpacker to an existing app that has most of the assets inside
|
|
368
537
|
`app/assets` or inside an engine, and you want to share that
|
|
@@ -371,7 +540,7 @@ option available in `config/webpacker.yml`. This lets you
|
|
|
371
540
|
add additional paths that webpack should lookup when resolving modules:
|
|
372
541
|
|
|
373
542
|
```yml
|
|
374
|
-
additional_paths: ['app/assets']
|
|
543
|
+
additional_paths: ['app/assets/**/*', 'vendor/assets/**/*.css', 'Gemfile']
|
|
375
544
|
```
|
|
376
545
|
|
|
377
546
|
You can then import these items inside your modules like so:
|
|
@@ -392,26 +561,6 @@ Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which
|
|
|
392
561
|
|
|
393
562
|
When compiling assets for production on a remote server, such as a continuous integration environment, it's recommended to use `yarn install --frozen-lockfile` to install NPM packages on the remote host to ensure that the installed packages match the `yarn.lock` file.
|
|
394
563
|
|
|
395
|
-
## Docs
|
|
396
|
-
|
|
397
|
-
- [Development](https://github.com/rails/webpacker#development)
|
|
398
|
-
- [Webpack](./docs/webpack.md)
|
|
399
|
-
- [Webpack-dev-server](./docs/webpack-dev-server.md)
|
|
400
|
-
- [Environment Variables](./docs/env.md)
|
|
401
|
-
- [Folder Structure](./docs/folder-structure.md)
|
|
402
|
-
- [Assets](./docs/assets.md) - [CSS, Sass and SCSS](./docs/css.md) - [ES6](./docs/es6.md), [Target browsers](./docs/target.md)
|
|
403
|
-
- [Props](./docs/props.md)
|
|
404
|
-
- [Typescript](./docs/typescript.md)
|
|
405
|
-
- [Yarn](./docs/yarn.md)
|
|
406
|
-
- [Misc](./docs/misc.md)
|
|
407
|
-
- [Deployment](./docs/deployment.md)
|
|
408
|
-
- [Docker](./docs/docker.md)
|
|
409
|
-
- [Using in Rails engines](./docs/engines.md)
|
|
410
|
-
- [Webpacker on Cloud9](./docs/cloud9.md)
|
|
411
|
-
- [Testing](./docs/testing.md)
|
|
412
|
-
- [Troubleshooting](./docs/troubleshooting.md)
|
|
413
|
-
- [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
|
|
414
|
-
|
|
415
564
|
## Contributing
|
|
416
565
|
|
|
417
566
|
[](https://www.codetriage.com/rails/webpacker)
|