webpacker 5.4.3 → 6.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (161) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -1
  3. data/.github/workflows/ruby.yml +12 -0
  4. data/.gitignore +2 -0
  5. data/.node-version +1 -1
  6. data/.rubocop.yml +3 -108
  7. data/6_0_upgrade.md +43 -0
  8. data/CHANGELOG.md +19 -18
  9. data/CONTRIBUTING.md +1 -1
  10. data/Gemfile.lock +91 -94
  11. data/README.md +220 -99
  12. data/gemfiles/Gemfile-rails-edge +1 -1
  13. data/lib/install/config/webpack/base.js +3 -0
  14. data/lib/install/config/webpack/development.js +2 -2
  15. data/lib/install/config/webpack/production.js +2 -2
  16. data/lib/install/config/webpack/test.js +2 -2
  17. data/lib/install/config/webpacker.yml +8 -37
  18. data/lib/install/javascript/packs/application.css +9 -0
  19. data/lib/install/javascript/packs/application.js +3 -1
  20. data/lib/install/template.rb +32 -26
  21. data/lib/tasks/webpacker/binstubs.rake +6 -4
  22. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  23. data/lib/tasks/webpacker/check_yarn.rake +1 -1
  24. data/lib/tasks/webpacker/compile.rake +4 -2
  25. data/lib/tasks/webpacker/info.rake +12 -10
  26. data/lib/tasks/webpacker/install.rake +6 -4
  27. data/lib/tasks/webpacker/verify_install.rake +2 -1
  28. data/lib/tasks/webpacker/yarn_install.rake +9 -7
  29. data/lib/tasks/webpacker.rake +2 -11
  30. data/lib/webpacker/compiler.rb +15 -8
  31. data/lib/webpacker/configuration.rb +10 -45
  32. data/lib/webpacker/dev_server_runner.rb +21 -2
  33. data/lib/webpacker/env.rb +1 -5
  34. data/lib/webpacker/helper.rb +22 -32
  35. data/lib/webpacker/manifest.rb +1 -1
  36. data/lib/webpacker/version.rb +1 -1
  37. data/lib/webpacker/webpack_runner.rb +5 -0
  38. data/package/__tests__/config.js +5 -37
  39. data/package/__tests__/development.js +9 -11
  40. data/package/__tests__/env.js +12 -4
  41. data/package/__tests__/production.js +6 -6
  42. data/package/__tests__/staging.js +7 -6
  43. data/package/__tests__/test.js +4 -5
  44. data/package/babel/preset.js +55 -0
  45. data/package/config.js +3 -11
  46. data/package/env.js +8 -2
  47. data/package/environments/__tests__/base.js +15 -47
  48. data/package/environments/base.js +62 -125
  49. data/package/environments/development.js +45 -44
  50. data/package/environments/production.js +63 -68
  51. data/package/environments/test.js +2 -2
  52. data/package/index.js +13 -8
  53. data/package/rules/babel.js +9 -7
  54. data/package/rules/coffee.js +6 -0
  55. data/package/rules/erb.js +15 -0
  56. data/package/rules/file.js +19 -19
  57. data/package/rules/index.js +15 -18
  58. data/package/rules/less.js +22 -0
  59. data/package/rules/sass.js +10 -10
  60. data/package/rules/svg.js +20 -0
  61. data/package/utils/get_style_rule.js +26 -36
  62. data/package/utils/helpers.js +26 -35
  63. data/package.json +29 -45
  64. data/test/compiler_test.rb +0 -12
  65. data/test/configuration_test.rb +1 -32
  66. data/test/dev_server_runner_test.rb +24 -5
  67. data/test/engine_rake_tasks_test.rb +39 -0
  68. data/test/helper_test.rb +24 -30
  69. data/test/mounted_app/Rakefile +4 -0
  70. data/test/mounted_app/test/dummy/Rakefile +3 -0
  71. data/test/mounted_app/test/dummy/bin/rails +3 -0
  72. data/test/mounted_app/test/dummy/bin/rake +3 -0
  73. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  74. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  75. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  76. data/test/mounted_app/test/dummy/config.ru +5 -0
  77. data/test/mounted_app/test/dummy/package.json +7 -0
  78. data/test/rake_tasks_test.rb +1 -10
  79. data/test/test_app/config/webpacker.yml +1 -25
  80. data/test/test_app/config/webpacker_public_root.yml +0 -1
  81. data/test/test_app/public/packs/manifest.json +17 -13
  82. data/test/test_app/some.config.js +0 -0
  83. data/test/webpack_runner_test.rb +9 -3
  84. data/yarn.lock +2505 -4943
  85. metadata +41 -87
  86. data/.travis.yml +0 -43
  87. data/docs/assets.md +0 -119
  88. data/docs/cloud9.md +0 -310
  89. data/docs/css.md +0 -308
  90. data/docs/deployment.md +0 -130
  91. data/docs/docker.md +0 -68
  92. data/docs/engines.md +0 -213
  93. data/docs/env.md +0 -63
  94. data/docs/es6.md +0 -72
  95. data/docs/folder-structure.md +0 -66
  96. data/docs/integrations.md +0 -220
  97. data/docs/misc.md +0 -23
  98. data/docs/props.md +0 -223
  99. data/docs/target.md +0 -22
  100. data/docs/testing.md +0 -136
  101. data/docs/troubleshooting.md +0 -158
  102. data/docs/typescript.md +0 -190
  103. data/docs/v4-upgrade.md +0 -142
  104. data/docs/webpack-dev-server.md +0 -92
  105. data/docs/webpack.md +0 -364
  106. data/docs/yarn.md +0 -23
  107. data/lib/install/angular.rb +0 -23
  108. data/lib/install/coffee.rb +0 -25
  109. data/lib/install/config/.browserslistrc +0 -1
  110. data/lib/install/config/babel.config.js +0 -82
  111. data/lib/install/config/postcss.config.js +0 -12
  112. data/lib/install/config/webpack/environment.js +0 -3
  113. data/lib/install/elm.rb +0 -39
  114. data/lib/install/erb.rb +0 -25
  115. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  116. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  117. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  118. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  119. data/lib/install/examples/angular/hello_angular.js +0 -7
  120. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  121. data/lib/install/examples/elm/Main.elm +0 -55
  122. data/lib/install/examples/elm/hello_elm.js +0 -16
  123. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  124. data/lib/install/examples/react/babel.config.js +0 -99
  125. data/lib/install/examples/react/hello_react.jsx +0 -26
  126. data/lib/install/examples/react/tsconfig.json +0 -21
  127. data/lib/install/examples/stimulus/application.js +0 -1
  128. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  129. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  130. data/lib/install/examples/svelte/app.svelte +0 -11
  131. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  132. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  133. data/lib/install/examples/typescript/tsconfig.json +0 -24
  134. data/lib/install/examples/vue/app.vue +0 -22
  135. data/lib/install/examples/vue/hello_vue.js +0 -72
  136. data/lib/install/loaders/coffee.js +0 -6
  137. data/lib/install/loaders/elm.js +0 -25
  138. data/lib/install/loaders/erb.js +0 -11
  139. data/lib/install/loaders/svelte.js +0 -9
  140. data/lib/install/loaders/vue.js +0 -6
  141. data/lib/install/react.rb +0 -18
  142. data/lib/install/stimulus.rb +0 -12
  143. data/lib/install/svelte.rb +0 -29
  144. data/lib/install/typescript.rb +0 -39
  145. data/lib/install/vue.rb +0 -49
  146. data/lib/tasks/installers.rake +0 -42
  147. data/package/config_types/__tests__/config_list.js +0 -118
  148. data/package/config_types/__tests__/config_object.js +0 -43
  149. data/package/config_types/config_list.js +0 -75
  150. data/package/config_types/config_object.js +0 -55
  151. data/package/config_types/index.js +0 -7
  152. data/package/rules/module.css.js +0 -3
  153. data/package/rules/module.sass.js +0 -8
  154. data/package/rules/node_modules.js +0 -22
  155. data/package/utils/__tests__/deep_assign.js +0 -32
  156. data/package/utils/__tests__/deep_merge.js +0 -10
  157. data/package/utils/__tests__/get_style_rule.js +0 -65
  158. data/package/utils/__tests__/objectify.js +0 -9
  159. data/package/utils/deep_assign.js +0 -22
  160. data/package/utils/deep_merge.js +0 -22
  161. data/package/utils/objectify.js +0 -3
@@ -1,158 +0,0 @@
1
- # Troubleshooting
2
-
3
- ## Debugging your webpack config
4
-
5
- 1. Read the error message carefully. The error message will tell you the precise key value
6
- that is not matching what Webpack expects.
7
- 2. Put a `debugger` statement in your Webpack configuration and run `bin/webpack --debug-webpacker`.
8
- If you have a node debugger installed, you'll see the Chrome debugger for your webpack
9
- config. For example, install the Chrome extension [NiM](https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj) and
10
- set the option for the dev tools to open automatically. For more details on debugging,
11
- see the official [Webpack docs on debugging](https://webpack.js.org/contribute/debugging/#devtools)
12
- 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.
13
- 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
-
15
- ## ENOENT: no such file or directory - node-sass
16
-
17
- If you get the error `ENOENT: no such file or directory - node-sass` on deploy with
18
- `assets:precompile` or `bundle exec rails webpacker:compile` you may need to
19
- move Sass to production `dependencies`.
20
-
21
- Move any packages that related to Sass (e.g. `node-sass` or `sass-loader`) from
22
- `devDependencies` to `dependencies` in `package.json`. This is because
23
- webpacker is running on a production system with the Rails workflow to build
24
- the assets. Particularly on hosting providers that try to detect and do the right
25
- thing, like Heroku.
26
-
27
- However, if you get this on local development, or not during a deploy then you
28
- may need to rebuild `node-sass`. It's a bit of a weird error; basically, it
29
- can't find the `node-sass` binary. An easy solution is to create a postinstall
30
- hook to ensure `node-sass` is rebuilt whenever new modules are installed.
31
-
32
- In `package.json`:
33
-
34
- ```json
35
- "scripts": {
36
- "postinstall": "npm rebuild node-sass"
37
- }
38
- ```
39
-
40
- ## Can't find hello_react.js in manifest.json
41
-
42
- * If you get this error `Can't find hello_react.js in manifest.json`
43
- when loading a view in the browser it's because webpack is still compiling packs.
44
- Webpacker uses a `manifest.json` file to keep track of packs in all environments,
45
- however since this file is generated after packs are compiled by webpack. So,
46
- if you load a view in browser whilst webpack is compiling you will get this error.
47
- Therefore, make sure webpack
48
- (i.e `./bin/webpack-dev-server`) is running and has
49
- completed the compilation successfully before loading a view.
50
-
51
-
52
- ## throw er; // Unhandled 'error' event
53
-
54
- * If you get this error while trying to use Elm, try rebuilding Elm. You can do
55
- so with a postinstall hook in your `package.json`:
56
-
57
- ```
58
- "scripts": {
59
- "postinstall": "npm rebuild elm"
60
- }
61
- ```
62
-
63
-
64
- ## webpack or webpack-dev-server not found
65
-
66
- * This could happen if `webpacker:install` step is skipped. Please run `bundle exec rails webpacker:install` to fix the issue.
67
-
68
- * 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
-
70
- ```bash
71
- bundle config --delete bin
72
- ./bin/rails app:update:bin # or rails app:update:bin
73
- ```
74
-
75
-
76
- ## Running webpack on Windows
77
-
78
- If you are running webpack on Windows, your command shell may not be able to interpret the preferred interpreter
79
- for the scripts generated in `bin/webpack` and `bin/webpack-dev-server`. Instead you'll want to run the scripts
80
- manually with Ruby:
81
-
82
- ```
83
- C:\path>ruby bin\webpack
84
- C:\path>ruby bin\webpack-dev-server
85
- ```
86
-
87
-
88
- ## Invalid configuration object. webpack has been initialised using a configuration object that does not match the API schema.
89
-
90
- 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`.
91
-
92
- ## Running Elm on Continuous Integration (CI) services such as CircleCI, CodeShip, Travis CI
93
-
94
- If your tests are timing out or erroring on CI it is likely that you are experiencing the slow Elm compilation issue described here: [elm-compiler issue #1473](https://github.com/elm-lang/elm-compiler/issues/1473)
95
-
96
- The issue is related to CPU count exposed by the underlying service. The basic solution involves using [libsysconfcpus](https://github.com/obmarg/libsysconfcpus) to change the reported CPU count.
97
-
98
- Basic fix involves:
99
-
100
- ```bash
101
- # install sysconfcpus on CI
102
- git clone https://github.com/obmarg/libsysconfcpus.git $HOME/dependencies/libsysconfcpus
103
- cd libsysconfcpus
104
- .configure --prefix=$HOME/dependencies/sysconfcpus
105
- make && make install
106
-
107
- # use sysconfcpus with elm-make
108
- mv $HOME/your_rails_app/node_modules/.bin/elm-make $HOME/your_rails_app/node_modules/.bin/elm-make-old
109
- printf "#\041/bin/bash\n\necho \"Running elm-make with sysconfcpus -n 2\"\n\n$HOME/dependencies/sysconfcpus/bin/sysconfcpus -n 2 $HOME/your_rails_app/node_modules/.bin/elm-make-old \"\$@\"" > $HOME/your_rails_app/node_modules/.bin/elm-make
110
- chmod +x $HOME/your_rails_app/node_modules/.bin/elm-make
111
- ```
112
-
113
- ## 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:
115
-
116
- ```ruby
117
- // production.rb
118
- # From
119
-
120
- Rails.application.config.assets.js_compressor = :uglifier
121
-
122
- # To
123
-
124
- Rails.application.config.assets.js_compressor = Uglifier.new(harmony: true)
125
-
126
- ```
127
-
128
- ### Angular: WARNING in ./node_modules/@angular/core/esm5/core.js, Critical dependency: the request of a dependency is an expression
129
-
130
- To silent these warnings, please update `config/webpack/environment.js`
131
-
132
- ```js
133
- // environment.js
134
- const webpack = require('webpack')
135
- const { resolve } = require('path')
136
- const { environment, config } = require('@rails/webpacker')
137
-
138
- environment.plugins.append('ContextReplacement',
139
- new webpack.ContextReplacementPlugin(
140
- /angular(\\|\/)core(\\|\/)(@angular|esm5)/,
141
- resolve(config.source_path)
142
- )
143
- )
144
- ```
145
-
146
- ### Compilation Fails Silently
147
-
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 'true' in webpacker.yml may add some helpful error information to your log file (Rails log/development.log or log/production.log)
149
-
150
- ```yml
151
- # webpacker.yml
152
- default: &default
153
- source_path: app/javascript
154
- source_entry_path: packs
155
- public_root_path: public
156
- public_output_path: complaints_packs
157
- webpack_compile_output: true
158
- ```
data/docs/typescript.md DELETED
@@ -1,190 +0,0 @@
1
- # TypeScript
2
-
3
- ## Installation
4
-
5
- 1. Run the TypeScript installer
6
-
7
- ```bash
8
- bundle exec rails webpacker:install:typescript
9
- ```
10
-
11
- After that, a new file called `hello_typescript.ts` will be present in your `packs` directory (or rather the `source_entry_path` of your `webpacker.yml` configuration). You're now ready to write TypeScript.
12
-
13
- ## (Optional) Adding Compile-Time Type Checking
14
-
15
- The default installation only transpiles your TypeScript code using Babel. If you would like to enable type checking as part of the Webpack compilation process (i.e. fail the build if there are TS errors), you can do the following:
16
-
17
- 1. Install the Fork TS Checker Webpack Plugin
18
-
19
- ```sh
20
- yarn add --dev fork-ts-checker-webpack-plugin
21
- ```
22
-
23
- 2. Then add it to your development environment config in `config/webpack/development.js`
24
-
25
- ```js
26
- const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
27
- const path = require("path");
28
-
29
- environment.plugins.append(
30
- "ForkTsCheckerWebpackPlugin",
31
- new ForkTsCheckerWebpackPlugin({
32
- typescript: {
33
- configFile: path.resolve(__dirname, "../../tsconfig.json"),
34
- },
35
- async: false,
36
- })
37
- );
38
- ```
39
-
40
- If you are `fork-ts-checker-webpack-plugin` older than 5.0, the `tsconfig` option also needs to be specified:
41
-
42
- ```js
43
- const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
44
- const path = require("path");
45
-
46
- environment.plugins.append(
47
- "ForkTsCheckerWebpackPlugin",
48
- new ForkTsCheckerWebpackPlugin({
49
- // this is a relative path to your project's TypeScript config
50
- tsconfig: path.resolve(__dirname, "../../tsconfig.json"),
51
- // non-async so type checking will block compilation
52
- async: false,
53
- })
54
- );
55
- ```
56
-
57
- ## Upgrading to 5.1
58
-
59
- If you update your App to `webpacker >= 5.1` and had TypeScript installed before, you need to add some new/remove some old configurations:
60
-
61
- 1. Remove old packages:
62
- - `yarn remove ts-loader`
63
-
64
- 2. Add new packages:
65
- - `yarn add @babel/preset-typescript`
66
-
67
- 3. Remove old configuration files:
68
- - Delete this file: `config/webpack/loaders/typescript.js`
69
-
70
- 4. Remove the following lines from `config/webpack/environment.js`:
71
- - `const typescript = require('./loaders/typescript')`
72
- - `environment.loaders.prepend('typescript', typescript)`
73
-
74
- 5. Add the TypeScript preset to your `babel.config.js`:
75
- - This line `['@babel/preset-typescript', { 'allExtensions': true, 'isTSX': true }]` has to be added as the last item to the `presets` array in your `babel.config.js`
76
-
77
- ### Upgrading to 5.1 for Vue users
78
-
79
- 1. Remove old packages:
80
- - `yarn remove ts-loader pnp-webpack-plugin`
81
-
82
- 2. Follow point 3 and 4 from the `TypeScript with Vue components` section
83
-
84
- ## TypeScript with React
85
-
86
- 1. Setup react using Webpacker [react installer](../README.md#react). Then run the TypeScript installer
87
-
88
- ```bash
89
- bundle exec rails webpacker:install:typescript
90
- ```
91
-
92
- 2. Rename the generated `hello_react.js` to `hello_react.tsx`. Make the file valid TypeScript and
93
- now you can use TypeScript, JSX with React.
94
-
95
- ## TypeScript with Vue components
96
-
97
- 1. Setup Vue using the Webpacker [Vue installer](../README.md#vue). Then run the TypeScript installer
98
-
99
- ```bash
100
- bundle exec rails webpacker:install:typescript
101
- ```
102
-
103
- 2. Rename generated `hello_vue.js` to `hello_vue.ts`.
104
- 3. Install the right Babel preset: `yarn add babel-preset-typescript-vue`
105
- 4. Change the generated `babel.config.js` from
106
-
107
- ```js
108
- ["@babel/preset-typescript", { "allExtensions": true, "isTSX": true }]
109
- ```
110
-
111
- to
112
-
113
- ```js
114
- ["babel-preset-typescript-vue", { "allExtensions": true, "isTSX": true }]
115
- ```
116
-
117
- and now you can use `<script lang="ts">` in your `.vue` component files. See [the babel-preset-typescript-vue docs](https://www.npmjs.com/package/babel-preset-typescript-vue) for more info.
118
-
119
- ## HTML templates with TypeScript and Angular
120
-
121
- After you have installed Angular using `bundle exec rails webpacker:install:angular`
122
- you would need to follow these steps to add HTML templates support:
123
-
124
- 1. Use `yarn` to add html-loader
125
-
126
- ```bash
127
- yarn add html-loader
128
- ```
129
-
130
- 2. Add html-loader to `config/webpack/environment.js`
131
-
132
- ```js
133
- environment.loaders.append('html', {
134
- test: /\.html$/,
135
- use: [{
136
- loader: 'html-loader',
137
- options: {
138
- minimize: true,
139
- removeAttributeQuotes: false,
140
- caseSensitive: true,
141
- customAttrSurround: [ [/#/, /(?:)/], [/\*/, /(?:)/], [/\[?\(?/, /(?:)/] ],
142
- customAttrAssign: [ /\)?\]?=/ ]
143
- }
144
- }]
145
- })
146
- ```
147
-
148
- 3. Add `.html` to `config/webpacker.yml`
149
-
150
- ```yml
151
- extensions:
152
- - .elm
153
- - .coffee
154
- - .html
155
- ```
156
-
157
- 4. Setup a custom `d.ts` definition
158
-
159
- ```ts
160
- // app/javascript/hello_angular/html.d.ts
161
-
162
- declare module "*.html" {
163
- const content: string
164
- export default content
165
- }
166
- ```
167
-
168
- 5. Add a template.html file relative to `app.component.ts`
169
-
170
- ```html
171
- <h1>Hello {{name}}</h1>
172
- ```
173
-
174
- 6. Import template into `app.component.ts`
175
-
176
- ```ts
177
- import { Component } from '@angular/core'
178
- import templateString from './template.html'
179
-
180
- @Component({
181
- selector: 'hello-angular',
182
- template: templateString
183
- })
184
-
185
- export class AppComponent {
186
- name = 'Angular!'
187
- }
188
- ```
189
-
190
- That's all. Voila!
data/docs/v4-upgrade.md DELETED
@@ -1,142 +0,0 @@
1
- # Webpacker Upgrade Guide
2
-
3
-
4
- To update a Webpacker v3.5 app to v4, follow these steps:
5
-
6
- 1. Update the `webpacker` gem and the `@rails/webpacker` package to v4. This will upgrade Webpack itself from 3.x to 4.x, make sure you're aware of [any deprecations which might effect you](https://webpack.js.org/migrate/4/). Also make sure any other packages you depend on support Webpack 4 and don't require any changes, e.g. if you explicitly include `webpack` you need to upgrade it to 4.x, and if you use `webpack-dev-server` you need to upgrade it to 3.x.
7
-
8
- 2. Browser support definitions have been moved from [`.browserslistrc`](../lib/install/config/.browserslistrc) to `/`.
9
-
10
- 3. Merge any differences between [`config/webpacker.yml`](../lib/install/config/webpacker.yml) and your `config/webpacker.yml`.
11
-
12
- 4. Webpacker v4 upgrades Babel to [v7](https://babeljs.io/docs/en/v7-migration), see also [the release blog post](https://babeljs.io/blog/2018/08/27/7.0.0). Many packages were moved to the `@babel/` namespace, any babel plugins you have will need to be updated. It may be worth checking out [babel-upgrade](https://github.com/babel/babel-upgrade) if you have problems. ([#1564](https://github.com/rails/webpacker/pull/1564))
13
-
14
- 5. `.babelrc` should be replaced with `babel.config.js` and `.postcssrc.yml` should be replaced with `postcss.config.js` ([#1822](https://github.com/rails/webpacker/pull/1822)). If you never changed these files from their defaults, the versions of [babel.config.js](../lib/install/config/babel.config.js) and [postcss.config.js](../lib/install/config/postcss.config.js) in the webpacker repository should be usable.
15
-
16
- 6. Due to the change in [#1625](https://github.com/rails/webpacker/pull/1625), you'll want to make sure that `extract_css` is set to true for the `default` environment in `webpacker.yml` if you want to have Webpacker supply your CSS.
17
-
18
- ## SplitChunks Configuration
19
-
20
- If you used the `CommonsChunkPlugin` you'll need to upgrade to using the new `splitChunks`.
21
-
22
- Originally, chunks (and modules imported inside them) were connected by a parent-child relationship in the internal Webpack graph. The `CommonsChunkPlugin` was used to avoid duplicated dependencies across them, but further optimizations were not possible.
23
-
24
- In Webpack v4, the `CommonsChunkPlugin` was removed in favor of `optimization.splitChunks`.
25
-
26
- For the full configuration options of `splitChunks`, see the [Webpack documentation](https://webpack.js.org/plugins/split-chunks-plugin/).
27
-
28
- ```js
29
- // config/webpack/environment.js
30
- const WebpackAssetsManifest = require('webpack-assets-manifest');
31
-
32
- // Enable the default config
33
- environment.splitChunks()
34
-
35
- // or using custom config
36
- environment.splitChunks((config) => Object.assign({}, config, { optimization: { splitChunks: false }}))
37
- ```
38
-
39
- Then use the `javascript_packs_with_chunks_tag` and `stylesheet_packs_with_chunks_tag` helpers to include all the transpiled
40
- packs with the chunks in your view, which creates html tags for all the chunks.
41
-
42
- ```erb
43
- <%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
44
-
45
- <!-- Creates the following: -->
46
- <script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
47
- <script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
48
- <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
49
- <script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
50
- <script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
51
- ```
52
-
53
- **Important:** Pass all your pack names to the helper otherwise you will get duplicated chunks on the page.
54
-
55
- ```erb
56
- <%# DO %>
57
- <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
58
-
59
- <%# DON'T %>
60
- <%= javascript_packs_with_chunks_tag 'calendar' %>
61
- <%= javascript_packs_with_chunks_tag 'map' %>
62
- ```
63
-
64
- ## Package-Specific Notes
65
-
66
- - If you're using React, you need to add `"@babel/preset-react"`, to the list of `presets` in your babel config.
67
- - If you're using Vue Loader, you'll need to upgrade to [v15](https://vue-loader.vuejs.org/migrating.html) for Webpack 4.
68
- - To see what Webpacker generates for a given framework with v4, you may want to re-run `bundle exec rake webpacker:install:FRAMEWORK` and let it override the files for your given JavaScript framework, and then compare them to see what changes you'll need to make.
69
-
70
- ## Excluding node_modules From Being Transpiled By Babel-Loader
71
-
72
- One change to take into consideration, is that Webpacker 4 transpiles the
73
- `node_modules` folder with the `babel-loader`. This folder used to be ignored by
74
- Webpacker 3. The new behavior helps in case some library contains ES6 code, but in
75
- some cases it can lead to issues. To avoid running `babel-loader` in the
76
- `node_modules` folder, replicating the same behavior as Webpacker 3, the
77
- following code can be added to `config/webpack/environment.js`:
78
-
79
- ```javascript
80
- environment.loaders.delete('nodeModules')
81
- ```
82
-
83
- Alternatively, in order to skip only a specific library in the `node_modules`
84
- folder, this code can be added:
85
-
86
- ```javascript
87
- const nodeModulesLoader = environment.loaders.get('nodeModules')
88
- if (!Array.isArray(nodeModulesLoader.exclude)) {
89
- nodeModulesLoader.exclude = (nodeModulesLoader.exclude == null)
90
- ? []
91
- : [nodeModulesLoader.exclude]
92
- }
93
- nodeModulesLoader.exclude.push(/some-library/) // replace `some-library` with
94
- // the actual path to exclude
95
- ```
96
-
97
- ## Source Maps Enabled By Default
98
-
99
- Source maps are now enabled in production to make debugging in production easier. Enabling source maps doesn't have drawbacks for most of the applications since maps are compressed by default and aren't loaded by browsers unless Dev Tools are opened.
100
-
101
- If you want to keep the old behavior source maps can be disabled in any environment configuration, e.g:
102
-
103
- ```js
104
- // config/webpack/production.js
105
-
106
- const environment = require('./environment')
107
- environment.config.merge({ devtool: false })
108
-
109
- module.exports = environment.toWebpackConfig()
110
- ```
111
-
112
- ## Namespaces
113
-
114
- The compiled packs in the public directory are now stored under namespaces:
115
-
116
- - JavaScripts are stored under `js`
117
- - Stylesheets are stored under `css`
118
- - Other resources are stored under `media`
119
-
120
- ```rb
121
- # Before
122
- "runtime~hello_react" => "/packs/runtime~hello_react-da2baf7fd07b0e8b6d17.js"
123
-
124
- # After
125
- "runtime~hello_react" => "/packs/js/runtime~hello_react-da2baf7fd07b0e8b6d17.js"
126
- ```
127
-
128
- ## Upgrading projects with custom Webpack setups that use only the view helpers
129
- The default value for `extract_css` is **false** in `config/webpack.yml`. Custom webpack builds that extract the CSS such as often used with [React on Rails](https://github.com/shakacode/react_on_rails) should set this value to true or else no CSS link tags are generated.
130
-
131
- ```yml
132
- default: &default
133
- # other stuff
134
- extract_css: true
135
- # by default, extract and emit a css file. The default is false
136
- ```
137
-
138
- ## Example Upgrades
139
-
140
- This is what an upgrade to Webpacker 4 looked like for existing Rails apps (please contribute yours!):
141
-
142
- - https://github.com/connorshea/ContinueFromCheckpoint/pull/77
@@ -1,92 +0,0 @@
1
- # webpack-dev-server
2
-
3
-
4
- ## HTTPS
5
-
6
- If you're using the `webpack-dev-server` in development, you can serve your packs over HTTPS
7
- by setting the `https` option for `webpack-dev-server` to `true` in `config/webpacker.yml`,
8
- then start the dev server as usual with `./bin/webpack-dev-server`.
9
-
10
- Please note that the `webpack-dev-server` will use a self-signed certificate,
11
- so your web browser will display a warning/exception upon accessing the page. If you get
12
- `https://localhost:3035/sockjs-node/info?t=1503127986584 net::ERR_INSECURE_RESPONSE`
13
- in your console, simply open the link in your browser and accept the SSL exception.
14
- Now if you refresh your Rails view everything should work as expected.
15
-
16
-
17
- ## HOT module replacement
18
-
19
- Webpacker out-of-the-box supports HMR with `webpack-dev-server` and
20
- you can toggle it by setting `dev_server/hmr` option inside `webpacker.yml`.
21
-
22
- Check out this guide for more information:
23
-
24
- - https://webpack.js.org/configuration/dev-server/#devserver-hot
25
-
26
- To support HMR with React you would need to add `react-hot-loader`. Checkout this guide for
27
- more information:
28
-
29
- - https://gaearon.github.io/react-hot-loader/getstarted/
30
-
31
- **Note:** Don't forget to disable `HMR` if you are not running `webpack-dev-server`
32
- otherwise you will get not found error for stylesheets.
33
-
34
-
35
- ## Nginx
36
-
37
- If you use Nginx in development to proxy requests to your Rails server from
38
- another domain, like `myapp.dev`, the Webpacker middleware will be able to
39
- forward requests for "packs" to the webpack dev server.
40
-
41
- If you're using `inline` mode behind Nginx, you may also need to provide the
42
- hostname to webpack dev server so it can initiate the websocket connection for
43
- live reloading ([Webpack
44
- docs](https://webpack.js.org/configuration/dev-server/#devserver-public)).
45
-
46
- To do so, set the `public` option in `config/webpacker.yml`:
47
-
48
- ```yaml
49
- development:
50
- # ...
51
- dev_server:
52
- # ...
53
- public: myapp.dev
54
- ```
55
-
56
- You may also need to add the following location block to your local Nginx server
57
- configuration for your Rails app.
58
-
59
- ```
60
- server {
61
- listen 80;
62
- server_name myapp.dev
63
-
64
- # Proxy webpack dev server websocket requests
65
- location /sockjs-node {
66
- proxy_redirect off;
67
- proxy_http_version 1.1;
68
- proxy_set_header Upgrade $http_upgrade;
69
- proxy_set_header Connection "upgrade";
70
- proxy_pass http://127.0.0.1:3035; # change to match your webpack-dev-server host
71
- }
72
-
73
- # ...
74
- }
75
- ```
76
-
77
- ## Customizing Logging
78
-
79
- By default, the dev server will display a colored progress notification while
80
- your code is being compiled. (Under the hood, we are using `webpack-dev-server
81
- --progress --color`). However, this might cause issues if you don't use
82
- `foreman` and/or try to log webpack-dev-server's output to a file. You can
83
- disable this stylized output by adding `pretty: false` to your `dev_server`
84
- config:
85
-
86
- ```yaml
87
- development:
88
- # ...
89
- dev_server:
90
- # ...
91
- pretty: false
92
- ```