webpacker 6.0.0.pre.2 → 6.0.0.rc.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/jest.yml +5 -2
- data/.github/workflows/js-lint.yml +5 -2
- data/.github/workflows/rubocop.yml +1 -1
- data/.github/workflows/ruby.yml +17 -14
- data/.node-version +1 -1
- data/.rubocop.yml +106 -0
- data/CHANGELOG.md +36 -9
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +93 -90
- data/README.md +363 -107
- data/config/README.md +3 -0
- data/config/webpacker.yml +1 -0
- data/docs/deployment.md +9 -29
- data/docs/developing_webpacker.md +29 -0
- data/docs/troubleshooting.md +57 -25
- data/docs/v6_upgrade.md +75 -0
- data/gemfiles/Gemfile-rails-edge +1 -1
- data/gemfiles/Gemfile-rails.6.1.x +12 -0
- data/lib/install/config/webpacker.yml +5 -7
- data/lib/install/{javascript/packs → packs/entrypoints}/application.js +4 -3
- data/lib/install/template.rb +17 -10
- data/lib/tasks/webpacker/binstubs.rake +2 -2
- data/lib/tasks/webpacker/check_node.rake +3 -0
- data/lib/tasks/webpacker/check_yarn.rake +4 -1
- data/lib/tasks/webpacker/clobber.rake +1 -1
- data/lib/tasks/webpacker/install.rake +2 -2
- data/lib/tasks/webpacker/verify_config.rake +14 -0
- data/lib/tasks/webpacker/verify_install.rake +1 -11
- data/lib/webpacker.rb +1 -1
- data/lib/webpacker/commands.rb +2 -1
- data/lib/webpacker/compiler.rb +9 -3
- data/lib/webpacker/configuration.rb +19 -8
- data/lib/webpacker/dev_server.rb +6 -0
- data/lib/webpacker/dev_server_runner.rb +7 -2
- data/lib/webpacker/env.rb +5 -1
- data/lib/webpacker/helper.rb +26 -50
- data/lib/webpacker/instance.rb +4 -0
- data/lib/webpacker/manifest.rb +1 -2
- data/lib/webpacker/railtie.rb +1 -2
- data/lib/webpacker/runner.rb +1 -1
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +1 -0
- data/package.json +25 -29
- data/package/__tests__/development.js +3 -2
- data/package/__tests__/env.js +8 -4
- data/package/__tests__/index.js +9 -0
- data/package/babel/preset.js +24 -14
- data/package/env.js +7 -1
- data/package/environments/__tests__/base.js +7 -7
- data/package/environments/base.js +25 -25
- data/package/environments/development.js +7 -8
- data/package/environments/production.js +28 -30
- data/package/index.js +9 -2
- data/package/inliningCss.js +7 -0
- data/package/rules/babel.js +1 -1
- data/package/rules/coffee.js +5 -5
- data/package/rules/erb.js +5 -3
- data/package/rules/file.js +5 -3
- data/package/rules/index.js +9 -17
- data/package/rules/less.js +14 -10
- 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 +28 -30
- data/package/utils/helpers.js +25 -0
- data/test/configuration_test.rb +3 -3
- data/test/dev_server_runner_test.rb +13 -2
- data/test/helper_test.rb +59 -60
- data/test/manifest_test.rb +16 -0
- data/test/mounted_app/test/dummy/config/webpacker.yml +4 -4
- 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 +4 -6
- data/test/test_app/config/webpacker_other_location.yml +79 -0
- data/test/test_app/public/packs/manifest.json +19 -5
- data/test/webpacker_test.rb +17 -0
- data/yarn.lock +1567 -1039
- metadata +24 -36
- data/docs/assets.md +0 -135
- data/docs/cloud9.md +0 -310
- data/docs/css.md +0 -303
- data/docs/docker.md +0 -68
- data/docs/engines.md +0 -213
- data/docs/env.md +0 -68
- 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 -187
- data/docs/react.md +0 -183
- data/docs/target.md +0 -22
- data/docs/testing.md +0 -147
- data/docs/typescript.md +0 -190
- data/docs/v4-upgrade.md +0 -142
- data/docs/webpack-dev-server.md +0 -94
- data/docs/webpack.md +0 -315
- data/docs/yarn.md +0 -23
- data/lib/install/examples/vue3/app.vue +0 -27
- data/lib/install/examples/vue3/hello_vue.js +0 -15
- data/lib/install/javascript/packs/application.css +0 -9
- data/package/babel/preset-react.js +0 -62
- data/package/rules/svg.js +0 -23
data/config/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
../lib/install/config/webpacker.yml
|
data/docs/deployment.md
CHANGED
@@ -1,28 +1,27 @@
|
|
1
1
|
# Deployment
|
2
2
|
|
3
|
-
|
4
3
|
Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`.
|
5
|
-
If you are not using Sprockets `webpacker:compile` is automatically aliased to `assets:precompile`. Remember to set NODE_ENV environment variable to production during deployment or when running the rake task.
|
4
|
+
If you are not using Sprockets `webpacker:compile` is automatically aliased to `assets:precompile`. Remember to set `NODE_ENV` environment variable to production during deployment or when running the rake task.
|
6
5
|
|
7
6
|
The `javascript_pack_tag` and `stylesheet_pack_tag` helper method will automatically insert the correct HTML tag for compiled pack. Just like the asset pipeline does it.
|
8
7
|
|
9
8
|
By default the output will look like this in different environments:
|
10
9
|
|
11
10
|
```html
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
<!-- In production or development mode -->
|
16
|
-
<script src="/packs/js/calendar-0bd141f6d9360cf4a7f5.js"></script>
|
17
|
-
<link rel="stylesheet" media="screen" href="/packs/css/calendar-dc02976b5f94b507e3b6.css">
|
18
|
-
```
|
11
|
+
<!-- In development mode with webpack-dev-server -->
|
12
|
+
<script src="http://localhost:8080/calendar-0bd141f6d9360cf4a7f5.js"></script>
|
13
|
+
<link rel="stylesheet" media="screen" href="http://localhost:8080/calendar-dc02976b5f94b507e3b6.css">
|
19
14
|
|
15
|
+
<!-- In production or development mode -->
|
16
|
+
<script src="/packs/js/calendar-0bd141f6d9360cf4a7f5.js"></script>
|
17
|
+
<link rel="stylesheet" media="screen" href="/packs/css/calendar-dc02976b5f94b507e3b6.css">
|
18
|
+
```
|
20
19
|
|
21
20
|
## Heroku
|
22
21
|
|
23
22
|
In order for your Webpacker app to run on Heroku, you'll need to do a bit of configuration before hand.
|
24
23
|
|
25
|
-
```
|
24
|
+
```bash
|
26
25
|
heroku create my-webpacker-heroku-app
|
27
26
|
heroku addons:create heroku-postgresql:hobby-dev
|
28
27
|
heroku buildpacks:add heroku/nodejs
|
@@ -37,7 +36,6 @@ We're essentially doing the following here:
|
|
37
36
|
* Adding the Heroku NodeJS and Ruby buildpacks for your app. This allows the `npm` or `yarn` executables to properly function when compiling your app - as well as Ruby.
|
38
37
|
* Pushing our code to Heroku and kicking off the deployment
|
39
38
|
|
40
|
-
|
41
39
|
## Nginx
|
42
40
|
|
43
41
|
Webpacker doesn't serve anything in production. You’re expected to configure your web server to serve files in public/ directly.
|
@@ -128,21 +126,3 @@ namespace :deploy do
|
|
128
126
|
end
|
129
127
|
end
|
130
128
|
```
|
131
|
-
|
132
|
-
If you use [nvm](https://github.com/nvm-sh/nvm) to manage node versions for your deployment user, use the below snippet instead:
|
133
|
-
|
134
|
-
```ruby
|
135
|
-
before "deploy:assets:precompile", "deploy:yarn_install"
|
136
|
-
namespace :deploy do
|
137
|
-
desc "Run rake yarn install"
|
138
|
-
task :yarn_install do
|
139
|
-
on roles(:web) do
|
140
|
-
within release_path do
|
141
|
-
execute("source ~/.nvm/nvm.sh && cd #{release_path} && yarn install --silent --no-progress --no-audit --no-optional")
|
142
|
-
end
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
```
|
147
|
-
The `source ~/.nvm/nvm.sh` is required because [nvm is not automatically loaded in non-interactive shells](https://github.com/nvm-sh/nvm/issues/1718).
|
148
|
-
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# Developing Webpacker
|
2
|
+
|
3
|
+
It's a little trickier for Rails developers to work on the JS code of a project like rails/webpacker. So here are some tips!
|
4
|
+
|
5
|
+
## Use some test app
|
6
|
+
For example, for React on Rails Changes, I'm using [shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh](https://github.com/shakacode/react_on_rails_tutorial_with_ssr_and_hmr_fast_refresh).
|
7
|
+
This directory is the `TEST_APP_DIR`.
|
8
|
+
|
9
|
+
## Fork rails/webpacker
|
10
|
+
Let's call the rails/webpacker directory `WEBPACKER_DIR` which has rails/webpacker's `package.json`.
|
11
|
+
|
12
|
+
## Changing the Package
|
13
|
+
### Setup with Yalc
|
14
|
+
Use [`yalc`](https://github.com/wclr/yalc) unless you like yak shaving weird errors.
|
15
|
+
1. In `WEBPACKER_DIR`, run `yalc publish`
|
16
|
+
2. In `TEST_APP_DIR`, run `yarn link @rails/webpacker`
|
17
|
+
|
18
|
+
## Update the Package Code
|
19
|
+
1. Make some JS change in WEBPACKER_DIR
|
20
|
+
2. Run `yalc push` and your changes will be pushed to your `TEST_APP_DIR`'s node_modules.
|
21
|
+
3. You may need to run `yarn` in `TEST_APP_DIR` if you added or removed dependencies of rails/webpacker.
|
22
|
+
|
23
|
+
## Updating the Ruby Code
|
24
|
+
|
25
|
+
For the Ruby part, just change the gem reference `TEST_APP_DIR`, like:
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
gem "webpacker", path: "../../forks/webpacker"
|
29
|
+
```
|
data/docs/troubleshooting.md
CHANGED
@@ -4,12 +4,17 @@
|
|
4
4
|
|
5
5
|
1. Read the error message carefully. The error message will tell you the precise key value
|
6
6
|
that is not matching what Webpack expects.
|
7
|
+
|
7
8
|
2. Put a `debugger` statement in your Webpack configuration and run `bin/webpack --debug-webpacker`.
|
8
9
|
If you have a node debugger installed, you'll see the Chrome debugger for your webpack
|
9
|
-
config. For example, install the Chrome extension
|
10
|
-
|
11
|
-
|
10
|
+
config. For example, install the Chrome extension
|
11
|
+
[NiM](https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj) and
|
12
|
+
set the option for the dev tools to open automatically. Or put `chrome://inspect` in the URL bar.
|
13
|
+
For more details on debugging, see the official
|
14
|
+
[Webpack docs on debugging](https://webpack.js.org/contribute/debugging/#devtools)
|
15
|
+
|
12
16
|
3. Any arguments that you add to bin/webpack get sent to webpack. For example, you can pass `--debug` to switch loaders to debug mode. See [webpack CLI debug options](https://webpack.js.org/api/cli/#debug-options) for more information on the available options.
|
17
|
+
|
13
18
|
4. You can also pass additional options to the command to run the webpack-dev-server and start the webpack-dev-server with the option `--debug-webpacker`
|
14
19
|
|
15
20
|
## ENOENT: no such file or directory - node-sass
|
@@ -54,16 +59,15 @@ completed the compilation successfully before loading a view.
|
|
54
59
|
* If you get this error while trying to use Elm, try rebuilding Elm. You can do
|
55
60
|
so with a postinstall hook in your `package.json`:
|
56
61
|
|
57
|
-
```
|
62
|
+
```json
|
58
63
|
"scripts": {
|
59
64
|
"postinstall": "npm rebuild elm"
|
60
65
|
}
|
61
66
|
```
|
62
67
|
|
63
|
-
|
64
68
|
## webpack or webpack-dev-server not found
|
65
69
|
|
66
|
-
* This could happen if
|
70
|
+
* This could happen if `webpacker:install` step is skipped. Please run `bundle exec rails webpacker:install` to fix the issue.
|
67
71
|
|
68
72
|
* If you encounter the above error on heroku after upgrading from Rails 4.x to 5.1.x, then the problem might be related to missing `yarn` binstub. Please run following commands to update/add binstubs:
|
69
73
|
|
@@ -72,7 +76,6 @@ bundle config --delete bin
|
|
72
76
|
./bin/rails app:update:bin # or rails app:update:bin
|
73
77
|
```
|
74
78
|
|
75
|
-
|
76
79
|
## Running webpack on Windows
|
77
80
|
|
78
81
|
If you are running webpack on Windows, your command shell may not be able to interpret the preferred interpreter
|
@@ -84,7 +87,6 @@ C:\path>ruby bin\webpack
|
|
84
87
|
C:\path>ruby bin\webpack-dev-server
|
85
88
|
```
|
86
89
|
|
87
|
-
|
88
90
|
## Invalid configuration object. webpack has been initialised using a configuration object that does not match the API schema.
|
89
91
|
|
90
92
|
If you receive this error when running `$ ./bin/webpack-dev-server` ensure your configuration is correct; most likely the path to your "packs" folder is incorrect if you modified from the original "source_path" defined in `config/webpacker.yml`.
|
@@ -99,6 +101,7 @@ Basic fix involves:
|
|
99
101
|
|
100
102
|
```bash
|
101
103
|
# install sysconfcpus on CI
|
104
|
+
|
102
105
|
git clone https://github.com/obmarg/libsysconfcpus.git $HOME/dependencies/libsysconfcpus
|
103
106
|
cd libsysconfcpus
|
104
107
|
.configure --prefix=$HOME/dependencies/sysconfcpus
|
@@ -111,41 +114,39 @@ chmod +x $HOME/your_rails_app/node_modules/.bin/elm-make
|
|
111
114
|
```
|
112
115
|
|
113
116
|
## Rake assets:precompile fails. ExecJS::RuntimeError
|
114
|
-
This error occurs because you are trying to minify by terser a pack that's already been minified by Webpacker. To avoid this conflict and prevent appearing of ExecJS::RuntimeError error, you will need to disable uglifier from Rails config:
|
117
|
+
This error occurs because you are trying to minify by `terser` a pack that's already been minified by Webpacker. To avoid this conflict and prevent appearing of `ExecJS::RuntimeError` error, you will need to disable uglifier from Rails config:
|
115
118
|
|
116
119
|
```ruby
|
117
|
-
|
118
|
-
# From
|
120
|
+
# In production.rb
|
119
121
|
|
122
|
+
# From
|
120
123
|
Rails.application.config.assets.js_compressor = :uglifier
|
121
124
|
|
122
125
|
# To
|
123
|
-
|
124
126
|
Rails.application.config.assets.js_compressor = Uglifier.new(harmony: true)
|
125
|
-
|
126
127
|
```
|
127
128
|
|
128
129
|
### Angular: WARNING in ./node_modules/@angular/core/esm5/core.js, Critical dependency: the request of a dependency is an expression
|
129
130
|
|
130
|
-
To silent these warnings, please update `config/webpack/
|
131
|
-
|
131
|
+
To silent these warnings, please update `config/webpack/base.js`:
|
132
132
|
```js
|
133
|
-
// environment.js
|
134
133
|
const webpack = require('webpack')
|
135
134
|
const { resolve } = require('path')
|
136
|
-
const {
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
)
|
135
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
136
|
+
|
137
|
+
module.exports = merge(webpackConfig, {
|
138
|
+
plugins: [
|
139
|
+
new webpack.ContextReplacementPlugin(
|
140
|
+
/angular(\\|\/)core(\\|\/)(@angular|esm5)/,
|
141
|
+
resolve(config.source_path)
|
142
|
+
)
|
143
|
+
]
|
144
|
+
})
|
144
145
|
```
|
145
146
|
|
146
147
|
### Compilation Fails Silently
|
147
148
|
|
148
|
-
If compiling is not producing output files and there are no error messages to help troubleshoot. Setting the webpack_compile_output configuration variable to
|
149
|
+
If compiling is not producing output files and there are no error messages to help troubleshoot. Setting the `webpack_compile_output` configuration variable to `true` in webpacker.yml may add some helpful error information to your log file (Rails `log/development.log` or `log/production.log`)
|
149
150
|
|
150
151
|
```yml
|
151
152
|
# webpacker.yml
|
@@ -156,3 +157,34 @@ default: &default
|
|
156
157
|
public_output_path: complaints_packs
|
157
158
|
webpack_compile_output: true
|
158
159
|
```
|
160
|
+
|
161
|
+
### Using global variables for dependencies
|
162
|
+
|
163
|
+
If you want to access any dependency without importing it everywhere or use it directly in your dev tools, please check: [https://webpack.js.org/plugins/provide-plugin/](https://webpack.js.org/plugins/provide-plugin/)
|
164
|
+
|
165
|
+
**You don't need to assign dependencies on `window`.**
|
166
|
+
|
167
|
+
For instance, with [jQuery](https://jquery.com/):
|
168
|
+
```diff
|
169
|
+
// app/packs/entrypoints/application.js
|
170
|
+
|
171
|
+
- import jQuery from 'jquery'
|
172
|
+
- window.jQuery = jQuery
|
173
|
+
```
|
174
|
+
|
175
|
+
Instead do:
|
176
|
+
```js
|
177
|
+
// config/webpack/base.js
|
178
|
+
|
179
|
+
const webpack = require('webpack')
|
180
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
181
|
+
|
182
|
+
module.exports = merge(webpackConfig, {
|
183
|
+
plugins: [
|
184
|
+
new webpack.ProvidePlugin({
|
185
|
+
$: 'jquery',
|
186
|
+
jQuery: 'jquery',
|
187
|
+
})
|
188
|
+
],
|
189
|
+
})
|
190
|
+
```
|
data/docs/v6_upgrade.md
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
# Upgrading from Webpacker 5 to 6
|
2
|
+
|
3
|
+
There are several substantial changes in Webpacker 6 that you need to manually account for when coming from Webpacker 5. This guide will help you through it.
|
4
|
+
|
5
|
+
## Webpacker has become a slimmer wrapper around Webpack
|
6
|
+
|
7
|
+
By default, Webpacker 6 is focused on compiling and bundling JavaScript. This pairs with the existing asset pipeline in Rails that's setup to transpile CSS and static images using [Sprockets](https://github.com/rails/sprockets). For most developers, that's the recommended combination. But if you'd like to use Webpacker for CSS and static assets as well, please see [integrations](https://github.com/rails/webpacker#integrations) for more information.
|
8
|
+
|
9
|
+
Webpacker used to configure Webpack indirectly, which lead to a [complicated secondary configuration process](https://github.com/rails/webpacker/blob/5-x-stable/docs/webpack.md). This was done in order to provide default configurations for the most popular frameworks, but ended up creating more complexity than it cured. So now Webpacker delegates all configuration directly to Webpack's default configuration setup.
|
10
|
+
|
11
|
+
This means you have to configure integration with frameworks yourself, but webpack-merge helps with this. See this example for [Vue](https://github.com/rails/webpacker#other-frameworks).
|
12
|
+
|
13
|
+
## How to upgrade to Webpacker 6
|
14
|
+
|
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. Upgrade the Webpacker Ruby gem and NPM package
|
21
|
+
|
22
|
+
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.)
|
23
|
+
|
24
|
+
Example going to a specific (beta) version:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
# Gemfile
|
28
|
+
gem 'webpacker', '6.0.0.beta.7'
|
29
|
+
```
|
30
|
+
|
31
|
+
Do *not* specify `'^6.0.0.beta.7'` (with a caret) or you will accidentally install `6.0.0.pre.2` which is months older than `beta.7`.
|
32
|
+
|
33
|
+
```bash
|
34
|
+
bundle install
|
35
|
+
```
|
36
|
+
|
37
|
+
```bash
|
38
|
+
yarn add @rails/webpacker@6.0.0-beta.7 --exact
|
39
|
+
```
|
40
|
+
|
41
|
+
```bash
|
42
|
+
bundle exec rails webpacker:install
|
43
|
+
```
|
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).
|
45
|
+
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.
|
46
|
+
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`.
|
47
|
+
|
48
|
+
```js
|
49
|
+
// config/webpack/base.js
|
50
|
+
const { webpackConfig, merge } = require('@rails/webpacker')
|
51
|
+
const customConfig = require('./custom')
|
52
|
+
|
53
|
+
module.exports = merge(webpackConfig, customConfig)
|
54
|
+
```
|
55
|
+
|
56
|
+
10. Copy over custom browserlist config from `.browserslistrc` if it exists into the `"browserslist"` key in `package.json` and remove `.browserslistrc`.
|
57
|
+
|
58
|
+
11. Remove `babel.config.js` if you never changed it. Be sure to have this config in your `package.json`:
|
59
|
+
```json
|
60
|
+
"babel": {
|
61
|
+
"presets": [
|
62
|
+
"./node_modules/@rails/webpacker/package/babel/preset.js"
|
63
|
+
]
|
64
|
+
}
|
65
|
+
```
|
66
|
+
12. Remove `postcss.config.js` if you don't use `PostCSS`.
|
67
|
+
13. `extensions` was removed from the `webpacker.yml` file. Move custom extensions to your configuration by merging an object like this. For more details, see docs for [Webpack Configuration](https://github.com/rails/webpacker/blob/master/README.md#webpack-configuration)
|
68
|
+
|
69
|
+
```js
|
70
|
+
{
|
71
|
+
resolve: {
|
72
|
+
extensions: ['.ts', '.tsx', '.vue', '.css']
|
73
|
+
}
|
74
|
+
}
|
75
|
+
```
|
data/gemfiles/Gemfile-rails-edge
CHANGED
@@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
|
4
4
|
|
5
5
|
gemspec path: "../"
|
6
6
|
|
7
|
-
gem "rails", github: "rails/rails"
|
7
|
+
gem "rails", github: "rails/rails", branch: "main"
|
8
8
|
gem "arel", github: "rails/arel"
|
9
9
|
gem "rake", ">= 11.1"
|
10
10
|
gem "rack-proxy", require: false
|
@@ -0,0 +1,12 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
|
4
|
+
|
5
|
+
gemspec path: "../"
|
6
|
+
|
7
|
+
gem "rails", '~>6.1.0'
|
8
|
+
gem "arel", github: "rails/arel"
|
9
|
+
gem "rake", ">= 11.1"
|
10
|
+
gem "rack-proxy", require: false
|
11
|
+
gem "minitest", "~> 5.0"
|
12
|
+
gem "byebug"
|
@@ -1,14 +1,14 @@
|
|
1
1
|
# Note: You must restart bin/webpack-dev-server for changes to take effect
|
2
2
|
|
3
3
|
default: &default
|
4
|
-
source_path: app/
|
5
|
-
source_entry_path:
|
4
|
+
source_path: app/packs
|
5
|
+
source_entry_path: entrypoints
|
6
6
|
public_root_path: public
|
7
7
|
public_output_path: packs
|
8
|
-
cache_path: tmp/
|
8
|
+
cache_path: tmp/webpacker
|
9
9
|
webpack_compile_output: true
|
10
10
|
|
11
|
-
# Additional paths webpack should
|
11
|
+
# Additional paths webpack should look up modules
|
12
12
|
# ['app/assets', 'engine/foo/app/assets']
|
13
13
|
additional_paths: []
|
14
14
|
|
@@ -27,8 +27,6 @@ development:
|
|
27
27
|
public: localhost:3035
|
28
28
|
# Hot Module Replacement updates modules while the application is running without a full reload
|
29
29
|
hmr: false
|
30
|
-
# Inline should be set to true if using HMR; it inserts a script to take care of live reloading
|
31
|
-
inline: true
|
32
30
|
# Should we show a full-screen overlay in the browser when there are compiler errors or warnings?
|
33
31
|
overlay: true
|
34
32
|
# Should we use gzip compression?
|
@@ -40,7 +38,7 @@ development:
|
|
40
38
|
# When enabled, nothing except the initial startup information will be written to the console.
|
41
39
|
# This also means that errors or warnings from webpack are not visible.
|
42
40
|
quiet: false
|
43
|
-
pretty:
|
41
|
+
pretty: true
|
44
42
|
headers:
|
45
43
|
'Access-Control-Allow-Origin': '*'
|
46
44
|
watch_options:
|
@@ -1,13 +1,12 @@
|
|
1
1
|
/* eslint no-console:0 */
|
2
2
|
// This file is automatically compiled by Webpack, along with any other files
|
3
3
|
// present in this directory. You're encouraged to place your actual application logic in
|
4
|
-
// a relevant structure within app/
|
4
|
+
// a relevant structure within app/packs and only use these pack files to reference
|
5
5
|
// that code so it'll be compiled.
|
6
6
|
//
|
7
7
|
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
|
8
8
|
// layout file, like app/views/layouts/application.html.erb
|
9
9
|
|
10
|
-
|
11
10
|
// Uncomment to copy all static images under ../images to the output folder and reference
|
12
11
|
// them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
|
13
12
|
// or the `imagePath` JavaScript helper below.
|
@@ -15,4 +14,6 @@
|
|
15
14
|
// const images = require.context('../images', true)
|
16
15
|
// const imagePath = (name) => images(name, true)
|
17
16
|
|
18
|
-
|
17
|
+
// Activate Active Storage
|
18
|
+
// import * as ActiveStorage from "@rails/activestorage"
|
19
|
+
// ActiveStorage.start()
|
data/lib/install/template.rb
CHANGED
@@ -5,10 +5,10 @@ say "Copying webpack core config"
|
|
5
5
|
directory "#{__dir__}/config/webpack", "config/webpack"
|
6
6
|
|
7
7
|
if Dir.exists?(Webpacker.config.source_path)
|
8
|
-
say "The
|
8
|
+
say "The packs app source directory already exists"
|
9
9
|
else
|
10
|
-
say "Creating
|
11
|
-
directory "#{__dir__}/
|
10
|
+
say "Creating packs app source directory"
|
11
|
+
directory "#{__dir__}/packs", Webpacker.config.source_path
|
12
12
|
end
|
13
13
|
|
14
14
|
apply "#{__dir__}/binstubs.rb"
|
@@ -26,13 +26,15 @@ if File.exists?(git_ignore_path)
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
results = []
|
30
|
+
|
29
31
|
Dir.chdir(Rails.root) do
|
30
|
-
if Webpacker::VERSION
|
32
|
+
if Webpacker::VERSION.match?(/^[0-9]+\.[0-9]+\.[0-9]+$/)
|
31
33
|
say "Installing all JavaScript dependencies [#{Webpacker::VERSION}]"
|
32
|
-
run
|
34
|
+
results << run("yarn add @rails/webpacker@#{Webpacker::VERSION}")
|
33
35
|
else
|
34
36
|
say "Installing all JavaScript dependencies [from prerelease rails/webpacker]"
|
35
|
-
run
|
37
|
+
results << run("yarn add @rails/webpacker@next")
|
36
38
|
end
|
37
39
|
|
38
40
|
package_json = File.read("#{__dir__}/../../package.json")
|
@@ -41,17 +43,19 @@ Dir.chdir(Rails.root) do
|
|
41
43
|
|
42
44
|
# needed for experimental Yarn 2 support and should not harm Yarn 1
|
43
45
|
say "Installing webpack and webpack-cli as direct dependencies"
|
44
|
-
run
|
46
|
+
results << run("yarn add webpack@#{webpack_version} webpack-cli@#{webpack_cli_version}")
|
45
47
|
|
46
48
|
say "Installing dev server for live reloading"
|
47
|
-
run
|
49
|
+
results << run("yarn add --dev webpack-dev-server @webpack-cli/serve")
|
48
50
|
end
|
49
51
|
|
50
52
|
insert_into_file Rails.root.join("package.json").to_s, before: /\n}\n*$/ do
|
51
53
|
<<~JSON.chomp
|
52
54
|
,
|
53
55
|
"babel": {
|
54
|
-
"presets": [
|
56
|
+
"presets": [
|
57
|
+
"./node_modules/@rails/webpacker/package/babel/preset.js"
|
58
|
+
]
|
55
59
|
},
|
56
60
|
"browserslist": [
|
57
61
|
"defaults"
|
@@ -66,4 +70,7 @@ if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
|
|
66
70
|
say "policy.connect_src :self, :https, \"http://localhost:3035\", \"ws://localhost:3035\" if Rails.env.development?", :yellow
|
67
71
|
end
|
68
72
|
|
69
|
-
|
73
|
+
unless results.all?
|
74
|
+
say "Webpacker installation failed 😭 See above for details.", :red
|
75
|
+
exit 1
|
76
|
+
end
|