webpacker 5.2.1 → 6.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (160) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -1
  3. data/.gitignore +2 -0
  4. data/.node-version +1 -1
  5. data/.rubocop.yml +11 -16
  6. data/6_0_upgrade.md +43 -0
  7. data/CHANGELOG.md +25 -0
  8. data/CONTRIBUTING.md +1 -1
  9. data/Gemfile.lock +17 -11
  10. data/README.md +220 -99
  11. data/lib/install/config/webpack/base.js +3 -0
  12. data/lib/install/config/webpack/development.js +2 -2
  13. data/lib/install/config/webpack/production.js +2 -2
  14. data/lib/install/config/webpack/test.js +2 -2
  15. data/lib/install/config/webpacker.yml +8 -37
  16. data/lib/install/javascript/packs/application.css +9 -0
  17. data/lib/install/javascript/packs/application.js +3 -1
  18. data/lib/install/template.rb +33 -19
  19. data/lib/tasks/webpacker.rake +2 -11
  20. data/lib/tasks/webpacker/binstubs.rake +6 -4
  21. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  22. data/lib/tasks/webpacker/check_yarn.rake +1 -2
  23. data/lib/tasks/webpacker/compile.rake +4 -2
  24. data/lib/tasks/webpacker/info.rake +12 -10
  25. data/lib/tasks/webpacker/install.rake +6 -4
  26. data/lib/tasks/webpacker/verify_install.rake +2 -1
  27. data/lib/tasks/webpacker/yarn_install.rake +9 -1
  28. data/lib/webpacker/commands.rb +1 -1
  29. data/lib/webpacker/compiler.rb +15 -8
  30. data/lib/webpacker/configuration.rb +6 -30
  31. data/lib/webpacker/dev_server_runner.rb +21 -2
  32. data/lib/webpacker/helper.rb +22 -32
  33. data/lib/webpacker/manifest.rb +1 -1
  34. data/lib/webpacker/version.rb +1 -1
  35. data/lib/webpacker/webpack_runner.rb +5 -0
  36. data/package.json +23 -39
  37. data/package/__tests__/config.js +5 -37
  38. data/package/__tests__/development.js +9 -11
  39. data/package/__tests__/env.js +12 -4
  40. data/package/__tests__/production.js +6 -6
  41. data/package/__tests__/staging.js +7 -6
  42. data/package/__tests__/test.js +4 -5
  43. data/package/babel/preset.js +55 -0
  44. data/package/config.js +3 -11
  45. data/package/env.js +8 -2
  46. data/package/environments/__tests__/base.js +15 -47
  47. data/package/environments/base.js +62 -125
  48. data/package/environments/development.js +45 -44
  49. data/package/environments/production.js +63 -68
  50. data/package/environments/test.js +2 -2
  51. data/package/index.js +13 -8
  52. data/package/rules/babel.js +9 -7
  53. data/package/rules/coffee.js +6 -0
  54. data/package/rules/erb.js +15 -0
  55. data/package/rules/file.js +19 -19
  56. data/package/rules/index.js +15 -18
  57. data/package/rules/less.js +22 -0
  58. data/package/rules/sass.js +12 -9
  59. data/package/rules/svg.js +20 -0
  60. data/package/utils/get_style_rule.js +26 -36
  61. data/package/utils/helpers.js +26 -35
  62. data/test/compiler_test.rb +0 -12
  63. data/test/configuration_test.rb +1 -32
  64. data/test/dev_server_runner_test.rb +24 -5
  65. data/test/engine_rake_tasks_test.rb +39 -0
  66. data/test/helper_test.rb +15 -9
  67. data/test/mounted_app/Rakefile +4 -0
  68. data/test/mounted_app/test/dummy/Rakefile +3 -0
  69. data/test/mounted_app/test/dummy/bin/rails +3 -0
  70. data/test/mounted_app/test/dummy/bin/rake +3 -0
  71. data/test/mounted_app/test/dummy/config.ru +5 -0
  72. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  73. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  74. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  75. data/test/mounted_app/test/dummy/package.json +7 -0
  76. data/test/rake_tasks_test.rb +1 -10
  77. data/test/test_app/config/webpacker.yml +1 -25
  78. data/test/test_app/config/webpacker_public_root.yml +0 -1
  79. data/test/test_app/public/packs/manifest.json +17 -13
  80. data/test/test_app/some.config.js +0 -0
  81. data/test/webpack_runner_test.rb +9 -3
  82. data/webpacker.gemspec +1 -1
  83. data/yarn.lock +1858 -4915
  84. metadata +44 -90
  85. data/.travis.yml +0 -43
  86. data/docs/assets.md +0 -119
  87. data/docs/cloud9.md +0 -310
  88. data/docs/css.md +0 -308
  89. data/docs/deployment.md +0 -130
  90. data/docs/docker.md +0 -68
  91. data/docs/engines.md +0 -213
  92. data/docs/env.md +0 -63
  93. data/docs/es6.md +0 -72
  94. data/docs/folder-structure.md +0 -66
  95. data/docs/integrations.md +0 -220
  96. data/docs/misc.md +0 -23
  97. data/docs/props.md +0 -223
  98. data/docs/target.md +0 -22
  99. data/docs/testing.md +0 -136
  100. data/docs/troubleshooting.md +0 -158
  101. data/docs/typescript.md +0 -190
  102. data/docs/v4-upgrade.md +0 -142
  103. data/docs/webpack-dev-server.md +0 -92
  104. data/docs/webpack.md +0 -364
  105. data/docs/yarn.md +0 -23
  106. data/lib/install/angular.rb +0 -23
  107. data/lib/install/coffee.rb +0 -25
  108. data/lib/install/config/.browserslistrc +0 -1
  109. data/lib/install/config/babel.config.js +0 -70
  110. data/lib/install/config/postcss.config.js +0 -12
  111. data/lib/install/config/webpack/environment.js +0 -3
  112. data/lib/install/elm.rb +0 -39
  113. data/lib/install/erb.rb +0 -25
  114. data/lib/install/examples/angular/hello_angular.js +0 -7
  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/coffee/hello_coffee.coffee +0 -4
  120. data/lib/install/examples/elm/Main.elm +0 -55
  121. data/lib/install/examples/elm/hello_elm.js +0 -16
  122. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  123. data/lib/install/examples/react/babel.config.js +0 -87
  124. data/lib/install/examples/react/hello_react.jsx +0 -26
  125. data/lib/install/examples/react/tsconfig.json +0 -21
  126. data/lib/install/examples/stimulus/application.js +0 -1
  127. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  128. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  129. data/lib/install/examples/svelte/app.svelte +0 -11
  130. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  131. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  132. data/lib/install/examples/typescript/tsconfig.json +0 -24
  133. data/lib/install/examples/vue/app.vue +0 -22
  134. data/lib/install/examples/vue/hello_vue.js +0 -72
  135. data/lib/install/loaders/coffee.js +0 -6
  136. data/lib/install/loaders/elm.js +0 -25
  137. data/lib/install/loaders/erb.js +0 -11
  138. data/lib/install/loaders/svelte.js +0 -9
  139. data/lib/install/loaders/vue.js +0 -6
  140. data/lib/install/react.rb +0 -18
  141. data/lib/install/stimulus.rb +0 -12
  142. data/lib/install/svelte.rb +0 -29
  143. data/lib/install/typescript.rb +0 -39
  144. data/lib/install/vue.rb +0 -49
  145. data/lib/tasks/installers.rake +0 -42
  146. data/package/config_types/__tests__/config_list.js +0 -118
  147. data/package/config_types/__tests__/config_object.js +0 -43
  148. data/package/config_types/config_list.js +0 -75
  149. data/package/config_types/config_object.js +0 -55
  150. data/package/config_types/index.js +0 -7
  151. data/package/rules/module.css.js +0 -3
  152. data/package/rules/module.sass.js +0 -8
  153. data/package/rules/node_modules.js +0 -22
  154. data/package/utils/__tests__/deep_assign.js +0 -32
  155. data/package/utils/__tests__/deep_merge.js +0 -10
  156. data/package/utils/__tests__/get_style_rule.js +0 -65
  157. data/package/utils/__tests__/objectify.js +0 -9
  158. data/package/utils/deep_assign.js +0 -22
  159. data/package/utils/deep_merge.js +0 -22
  160. data/package/utils/objectify.js +0 -3
@@ -1,308 +0,0 @@
1
- # CSS, Sass and SCSS
2
-
3
-
4
- Webpacker supports importing CSS, Sass and SCSS files directly into your JavaScript files.
5
-
6
- Importing and loading styles is a two step process:
7
-
8
- 1. You need to tell webpack which file(s) it has to compile and know how to load
9
-
10
- When you do `import '../scss/application.scss'`, you're telling webpack to include `application.scss` in the build. This does not mean it's going to be compiled into your javascript, only that webpack now compiles and knows how to load this file. (How that file compilation is handled is depending on how your loaders (`css-loader`, `sass-loader`, `file-loader`, etc.) are configured.)
11
-
12
- 2. You need to load those files in your views
13
-
14
- In order to have styles load in production, you need to include `stylesheet_pack_tag` with the same name as the javascript file that imports the styles.
15
-
16
- When you do `<%= stylesheet_pack_tag 'application' %>`, that's a run-time inclusion from Rails, where Rails gets the correct "asset path" to that file from webpack.
17
-
18
-
19
- ## Import global styles into your JS app
20
-
21
- ### Importing CSS as a multi-file pack (Webpacker v5)
22
-
23
- When you add a CSS/SCSS/SASS file to `app/javascript/packs/` directory, make sure to use the same pack name as its complementary JavaScript pack, e.g. `application.js` and `application.css`. By Webpacker convention (as of Webpacker v5), this will bundle `application.js` and `application.scss` as part of the same entry point (also described as [a multi-file entry point in the webpack docs](https://webpack.js.org/concepts/entry-points/#single-entry-shorthand-syntax)). With this approach, you can avoid importing CSS from JS, if desired.
24
-
25
- ```
26
- app/
27
- javascript/
28
- packs/
29
- application.js
30
- application.scss
31
- ```
32
-
33
- ### Importing CSS from CSS
34
-
35
- You can import additional CSS/SCSS/SASS files from within a CSS file:
36
-
37
- ```
38
- app/
39
- javascript/
40
- stylesheets/
41
- application.scss
42
- posts.scss
43
- comments.scss
44
- ```
45
-
46
- ```css
47
- /* app/javascript/stylesheets/application.scss */
48
-
49
- @import './posts';
50
- @import './comments';
51
- ```
52
-
53
- ### Importing CSS provided by an NPM package from SCSS/CSS
54
-
55
- Given your application installs an NPM package that provides CSS, such as `flatpickr`, you can import the CSS file(s) by path from the package directory within `node_modules/`:
56
-
57
- ```js
58
- /* app/javascript/stylesheets/application.scss */
59
-
60
- @import "flatpickr/dist/flatpickr.css"
61
- ```
62
-
63
-
64
- ### Importing CSS from JS
65
-
66
- ```sass
67
- // app/javascript/hello_react/styles/hello-react.sass
68
-
69
- .hello-react
70
- padding: 20px
71
- font-size: 12px
72
- ```
73
-
74
- ```js
75
- // React component example
76
- // app/javascript/packs/hello_react.jsx
77
-
78
- import React from 'react'
79
- import helloIcon from '../hello_react/images/icon.png'
80
- import '../hello_react/styles/hello-react'
81
-
82
- const Hello = props => (
83
- <div className="hello-react">
84
- <img src={helloIcon} alt="hello-icon" />
85
- <p>Hello {props.name}!</p>
86
- </div>
87
- )
88
- ```
89
-
90
- ### Importing CSS provided by an NPM package from JS
91
-
92
- Given your application installs an NPM package that provides CSS, such as `flatpickr`, you can import the CSS file(s) by path from the package directory within `node_modules/`. This is an alternative to importing from within a CSS file, as above:
93
-
94
- ```js
95
- // app/javascript/packs/application.js
96
-
97
- import "flatpickr/dist/flatpickr.css"
98
- ```
99
-
100
- ## Import scoped styles into your JS app
101
-
102
- Stylesheets that end with `.module.*` are treated as [CSS Modules](https://github.com/css-modules/css-modules).
103
-
104
- ```sass
105
- // app/javascript/hello_react/styles/hello-react.module.sass
106
-
107
- .helloReact
108
- padding: 20px
109
- font-size: 12px
110
- ```
111
-
112
- ```js
113
- // React component example
114
- // app/javascript/packs/hello_react.jsx
115
-
116
- import React from 'react'
117
- import helloIcon from '../hello_react/images/icon.png'
118
- import styles from '../hello_react/styles/hello-react'
119
-
120
- const Hello = props => (
121
- <div className={styles.helloReact}>
122
- <img src={helloIcon} alt="hello-icon" />
123
- <p>Hello {props.name}!</p>
124
- </div>
125
- )
126
- ```
127
-
128
- **Note:** Declared class is referenced as object property in JavaScript.
129
-
130
- ## Import scoped styles into your TypeScript app
131
-
132
- Using CSS modules with a TypeScript application requires a few differences from a JavaScript app. The CSS / Sass files are the same:
133
-
134
- ```sass
135
- // app/javascript/hello_react/styles/hello-react.module.sass
136
-
137
- .helloReact
138
- padding: 20px
139
- font-size: 12px
140
- ```
141
-
142
- There must also be a type definition file for these styles:
143
-
144
- ```typescript
145
- export const helloReact: string;
146
- ```
147
-
148
- You can then import the styles like this:
149
-
150
- ```typescript
151
- // React component example
152
- // app/javascripts/packs/hello_react.tsx
153
-
154
- import React from 'react'
155
- import helloIcon from '../hello_react/images/icon.png'
156
- import * as styles from '../hello_react/styles/hello-react.module.sass'
157
-
158
- const Hello = props => (
159
- <div className={styles.helloReact}>
160
- <img src={helloIcon} alt="hello-icon" />
161
- <p>Hello {props.name}!</p>
162
- </div>
163
- )
164
- ```
165
-
166
- You can automatically generate type definitions for the styles by installing the `typed-scss-modules` as a development dependency:
167
-
168
- ```
169
- yarn add typed-scss-modules --dev
170
- ```
171
-
172
- Then by adding these lines to your `package.json`:
173
-
174
- ```
175
- "scripts": {
176
- "gen-typings": "yarn run tsm app/javascript/**/*.sass",
177
- "watch-typings": "yarn run tsm app/javascript/**/*.sass -w"
178
- },
179
- ```
180
-
181
- You can generate the typings for the stylesheet by running the command `yarn gen-typings` when you've finished writing CSS, or run `yarn watch-typings` to have it automatically generate them as you go.
182
-
183
-
184
- ## Link styles from your Rails views
185
-
186
- Under the hood webpack uses
187
- [mini-css-extract-plugin](https://github.com/webpack-contrib/mini-css-extract-plugin) plugin to extract all the referenced styles within your app and compile it into
188
- a separate `[pack_name].css` bundle so that in your view you can use the
189
- `stylesheet_pack_tag` helper.
190
-
191
- ```erb
192
- <%= stylesheet_pack_tag 'hello_react' %>
193
- ```
194
-
195
- Webpacker emits css files only if `extract_css` is set to true in webpacker.yml otherwise `stylesheet_pack_tag` returns nil.
196
-
197
- ## Add bootstrap
198
-
199
- You can use Yarn to add bootstrap or any other modules available on npm:
200
-
201
- ```bash
202
- yarn add bootstrap
203
- ```
204
-
205
- Import Bootstrap and theme (optional) CSS in your app/javascript/packs/application.js file:
206
-
207
- ```js
208
- import 'bootstrap/dist/css/bootstrap'
209
- import 'bootstrap/dist/css/bootstrap-theme'
210
- ```
211
-
212
- Or in your app/javascript/packs/application.sass file:
213
-
214
- ```sass
215
- // ~ to tell that this is not a relative import
216
-
217
- @import '~bootstrap/dist/css/bootstrap'
218
- @import '~bootstrap/dist/css/bootstrap-theme'
219
- ```
220
-
221
-
222
- ## Post-Processing CSS
223
-
224
- Webpacker out-of-the-box provides CSS post-processing using
225
- [postcss-loader](https://github.com/postcss/postcss-loader)
226
- and the installer sets up a standard `postcss.config.js`
227
- file in your app root with standard plugins.
228
-
229
- ```js
230
- module.exports = {
231
- plugins: [
232
- require('postcss-import'),
233
- require('postcss-flexbugs-fixes'),
234
- require('postcss-preset-env')({
235
- autoprefixer: {
236
- flexbox: 'no-2009'
237
- },
238
- stage: 3
239
- })
240
- ]
241
- }
242
- ```
243
-
244
- ## Using CSS with [vue-loader](https://github.com/vuejs/vue-loader)
245
-
246
- Vue templates require loading the stylesheet in your application in
247
- order for CSS to work. This is in addition to loading the JavaScript
248
- file for the entry point. Loading the stylesheet will also load the
249
- CSS for any nested components.
250
-
251
- ```erb
252
- <%= stylesheet_pack_tag 'hello_vue' %>
253
- <%= javascript_pack_tag 'hello_vue' %>
254
- ```
255
-
256
- ## Resolve url loader
257
-
258
- Since `Sass/libsass` does not provide url rewriting, all linked assets must be relative to the output. Add the missing url rewriting using the resolve-url-loader. Place it directly after the sass-loader in the loader chain.
259
-
260
-
261
- ```bash
262
- yarn add resolve-url-loader
263
- ```
264
-
265
- ```js
266
- // webpack/environment.js
267
- const { environment } = require('@rails/webpacker')
268
-
269
- // resolve-url-loader must be used before sass-loader
270
- environment.loaders.get('sass').use.splice(-1, 0, {
271
- loader: 'resolve-url-loader'
272
- });
273
-
274
- module.exports = environment
275
- ```
276
-
277
- ## Working with TypeScript
278
-
279
- In order to get CSS to work with typescript you have two options.
280
- You can either use `require` to bypass typescript special `import`.
281
-
282
- ```ts
283
- const styles = require('../hello_react/styles/hello-react');
284
- ```
285
- You may also use the package [typings-for-css-modules-loader](https://github.com/Jimdo/typings-for-css-modules-loader) instead of `css-loader` to automatically generate typescript `.d.ts` files in order to help resolve any css/scss styles. To do that:
286
-
287
- ```js
288
- // app/javascript/packs/hello_react.jsx
289
- import * as styles from '../hello_react.styles/hello-react.module.scss';
290
- ```
291
-
292
- ```bash
293
- yarn add --dev typings-for-css-modules-loader
294
- ```
295
-
296
- ```js
297
- // webpack/environment.js
298
- const { environment } = require('@rails/webpacker')
299
-
300
- // replace css-loader with typings-for-css-modules-loader
301
- environment.loaders.get('moduleSass').use = environment.loaders.get('moduleSass').use.map((u) => {
302
- if(u.loader == 'css-loader') {
303
- return { ...u, loader: 'typings-for-css-modules-loader' };
304
- } else {
305
- return u;
306
- }
307
- });
308
- ```
@@ -1,130 +0,0 @@
1
- # Deployment
2
-
3
-
4
- 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.
6
-
7
- 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
-
9
- By default the output will look like this in different environments:
10
-
11
- ```html
12
- <!-- In development mode with webpack-dev-server -->
13
- <script src="http://localhost:8080/calendar-0bd141f6d9360cf4a7f5.js"></script>
14
- <link rel="stylesheet" media="screen" href="http://localhost:8080/calendar-dc02976b5f94b507e3b6.css">
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
- ```
19
-
20
-
21
- ## Heroku
22
-
23
- In order for your Webpacker app to run on Heroku, you'll need to do a bit of configuration before hand.
24
-
25
- ```
26
- heroku create my-webpacker-heroku-app
27
- heroku addons:create heroku-postgresql:hobby-dev
28
- heroku buildpacks:add heroku/nodejs
29
- heroku buildpacks:add heroku/ruby
30
- git push heroku master
31
- ```
32
-
33
- We're essentially doing the following here:
34
-
35
- * Creating an app on Heroku
36
- * Creating a Postgres database for the app (this is assuming that you're using Heroku Postgres for your app)
37
- * 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
- * Pushing our code to Heroku and kicking off the deployment
39
-
40
-
41
- ## Nginx
42
-
43
- Webpacker doesn't serve anything in production. You’re expected to configure your web server to serve files in public/ directly.
44
-
45
- Some servers support sending precompressed versions of files when they're available. For example, nginx offers a `gzip_static` directive that serves files with the `.gz` extension to supported clients. With an optional module, nginx can also serve Brotli compressed files with the `.br` extension (see below for installation and configuration instructions).
46
-
47
- Here's a sample nginx site config for a Rails app using Webpacker:
48
-
49
- ```nginx
50
- upstream app {
51
- # server unix:///path/to/app/tmp/puma.sock;
52
- }
53
-
54
- server {
55
- listen 80;
56
- server_name www.example.com;
57
- root /path/to/app/public;
58
-
59
- location @app {
60
- proxy_pass http://app;
61
- proxy_redirect off;
62
-
63
- proxy_set_header Host $host;
64
- proxy_set_header X-Real-IP $remote_addr;
65
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
66
- proxy_set_header X-Forwarded-Proto $scheme;
67
- }
68
-
69
- location / {
70
- try_files $uri @app;
71
- }
72
-
73
- location = /favicon.ico { access_log off; log_not_found off; }
74
- location = /robots.txt { access_log off; log_not_found off; }
75
-
76
- location ~ /\.(?!well-known).* {
77
- deny all;
78
- }
79
-
80
- location ~ ^/(assets|packs)/ {
81
- gzip_static on;
82
- brotli_static on; # Optional, see below
83
- expires max;
84
- add_header Cache-Control public;
85
- }
86
- }
87
- ```
88
-
89
- ### Installing the ngx_brotli module
90
-
91
- If you want to serve Brotli compressed files with nginx, you will need to install the `nginx_brotli` module. Installation instructions from source can be found in the official [google/ngx_brotli](https://github.com/google/ngx_brotli) git repository. Alternatively, depending on your platform, the module might be available via a pre-compiled package.
92
-
93
- Once installed, you need to load the module. As we want to serve the pre-compressed files, we only need the static module. Add the following line to your `nginx.conf` file and reload nginx:
94
-
95
- ```
96
- load_module modules/ngx_http_brotli_static_module.so;
97
- ```
98
-
99
- Now, you can set `brotli_static on;` in your nginx site config, as per the config in the last section above.
100
-
101
- ## CDN
102
-
103
- Webpacker out-of-the-box provides CDN support using your Rails app `config.action_controller.asset_host` setting. If you already have [CDN](http://guides.rubyonrails.org/asset_pipeline.html#cdns) added in your Rails app
104
- you don't need to do anything extra for Webpacker, it just works.
105
-
106
- ## Capistrano
107
-
108
- ### Assets compiling on every deployment even if JavaScript and CSS files are not changed
109
-
110
- Make sure you have `public/packs` and `node_modules` in `:linked_dirs`
111
-
112
- ```ruby
113
- append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/packs", ".bundle", "node_modules"
114
- ```
115
-
116
- If you have `node_modules` added to `:linked_dirs` you'll need to run yarn install before `deploy:assets:precompile`, so you can add this code snippet at the bottom deploy.rb
117
-
118
- ```ruby
119
- before "deploy:assets:precompile", "deploy:yarn_install"
120
- namespace :deploy do
121
- desc "Run rake yarn install"
122
- task :yarn_install do
123
- on roles(:web) do
124
- within release_path do
125
- execute("cd #{release_path} && yarn install --silent --no-progress --no-audit --no-optional")
126
- end
127
- end
128
- end
129
- end
130
- ```
@@ -1,68 +0,0 @@
1
- # Docker
2
-
3
- To setup webpacker with a dockerized Rails application.
4
-
5
- First, add a new service for webpacker in docker-compose.yml:
6
-
7
- ```Dockerfile
8
- version: '3'
9
- services:
10
- webpacker:
11
- build: .
12
- environment:
13
- - NODE_ENV=development
14
- - RAILS_ENV=development
15
- - WEBPACKER_DEV_SERVER_HOST=0.0.0.0
16
- command: ./bin/webpack-dev-server
17
- volumes:
18
- - .:/webpacker-example-app
19
- ports:
20
- - '3035:3035'
21
- ```
22
-
23
- add nodejs and yarn as dependencies in Dockerfile,
24
-
25
- ```dockerfile
26
- FROM ruby:2.4.1
27
-
28
- RUN apt-get update -qq && apt-get install -y build-essential nodejs \
29
- && rm -rf /var/lib/apt/lists/* \
30
- && curl -o- -L https://yarnpkg.com/install.sh | bash
31
-
32
- # Rest of the commands....
33
- ```
34
-
35
- Please note: if using `assets:precompile` in the Dockerfile or have issues with the snippet above then try:
36
-
37
- ```dockerfile
38
- FROM ruby:2.4.1
39
-
40
- RUN curl -sL https://deb.nodesource.com/setup_8.x | bash \
41
- && apt-get update && apt-get install -y nodejs && rm -rf /var/lib/apt/lists/* \
42
- && curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
43
- && echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
44
- && apt-get update && apt-get install -y yarn && rm -rf /var/lib/apt/lists/*
45
-
46
- # Rest of the commands....
47
- ```
48
-
49
- then add the webpacker host name environment variable to the web/app service:
50
-
51
- ```Dockerfile
52
- web:
53
- build:
54
- context: .
55
- command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3000 -b '0.0.0.0'"
56
- volumes:
57
- - .:/usr/src/app
58
- ports:
59
- - "3000:3000"
60
- environment:
61
- - WEBPACKER_DEV_SERVER_HOST=webpacker
62
- ```
63
-
64
- Lastly, rebuild your container:
65
-
66
- ```bash
67
- docker-compose up --build
68
- ```