jetpacker 0.2.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (88) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +8 -8
  3. data/.github/workflows/jest.yml +38 -0
  4. data/.github/workflows/js-lint.yml +39 -0
  5. data/.github/workflows/rubocop.yml +39 -0
  6. data/.github/workflows/ruby.yml +70 -0
  7. data/.node-version +1 -1
  8. data/.travis.yml +8 -21
  9. data/CHANGELOG.jetpacker.md +18 -0
  10. data/CHANGELOG.md +44 -2
  11. data/Gemfile +1 -0
  12. data/Gemfile.lock +115 -101
  13. data/README.md +24 -649
  14. data/docs/css.md +58 -3
  15. data/docs/deployment.md +2 -2
  16. data/docs/docker.md +17 -17
  17. data/docs/engines.md +13 -0
  18. data/docs/env.md +0 -2
  19. data/docs/integrations.md +220 -0
  20. data/docs/target.md +22 -0
  21. data/docs/testing.md +2 -3
  22. data/docs/troubleshooting.md +3 -1
  23. data/docs/typescript.md +92 -28
  24. data/docs/webpack-dev-server.md +1 -1
  25. data/jetpacker.gemspec +6 -5
  26. data/lib/install/config/babel.config.js +1 -3
  27. data/lib/install/config/webpacker.yml +11 -6
  28. data/lib/install/examples/react/tsconfig.json +2 -1
  29. data/lib/install/examples/typescript/tsconfig.json +2 -1
  30. data/lib/install/loaders/svelte.js +2 -2
  31. data/lib/install/template.rb +7 -7
  32. data/lib/install/typescript.rb +5 -1
  33. data/lib/jetpacker.rb +1 -0
  34. data/lib/jetpacker/version.rb +1 -1
  35. data/lib/tasks/webpacker/check_node.rake +15 -8
  36. data/lib/tasks/webpacker/check_yarn.rake +17 -10
  37. data/lib/tasks/webpacker/clean.rake +12 -8
  38. data/lib/tasks/webpacker/clobber.rake +8 -4
  39. data/lib/tasks/webpacker/yarn_install.rake +5 -16
  40. data/lib/webpacker.rb +1 -1
  41. data/lib/webpacker/commands.rb +33 -9
  42. data/lib/webpacker/compiler.rb +9 -5
  43. data/lib/webpacker/configuration.rb +13 -9
  44. data/lib/webpacker/dev_server_proxy.rb +3 -1
  45. data/lib/webpacker/dev_server_runner.rb +2 -2
  46. data/lib/webpacker/helper.rb +37 -18
  47. data/lib/webpacker/manifest.rb +4 -4
  48. data/lib/webpacker/railtie.rb +0 -43
  49. data/lib/webpacker/runner.rb +1 -0
  50. data/lib/webpacker/turbine.rb +36 -0
  51. data/lib/webpacker/version.rb +1 -1
  52. data/lib/webpacker/webpack_runner.rb +2 -2
  53. data/package.json +39 -39
  54. data/package/__tests__/config.js +12 -1
  55. data/package/__tests__/dev_server.js +2 -0
  56. data/package/__tests__/development.js +14 -1
  57. data/package/config.js +4 -1
  58. data/package/configPath.js +3 -0
  59. data/package/dev_server.js +1 -1
  60. data/package/env.js +1 -2
  61. data/package/environments/__tests__/base.js +29 -2
  62. data/package/environments/base.js +17 -7
  63. data/package/environments/development.js +39 -37
  64. data/package/environments/production.js +1 -3
  65. data/package/rules/babel.js +12 -5
  66. data/package/rules/file.js +1 -0
  67. data/package/rules/node_modules.js +1 -3
  68. data/package/rules/sass.js +7 -1
  69. data/package/utils/helpers.js +1 -1
  70. data/test/compiler_test.rb +8 -3
  71. data/test/configuration_test.rb +8 -7
  72. data/test/dev_server_runner_test.rb +1 -1
  73. data/test/helper_test.rb +3 -0
  74. data/test/manifest_test.rb +37 -6
  75. data/test/rake_tasks_test.rb +11 -0
  76. data/test/test_app/app/javascript/packs/multi_entry.css +4 -0
  77. data/test/test_app/app/javascript/packs/multi_entry.js +4 -0
  78. data/test/test_app/config/application.rb +0 -1
  79. data/test/test_app/config/webpacker.yml +7 -1
  80. data/test/test_app/public/packs/manifest.json +1 -0
  81. data/test/webpack_runner_test.rb +1 -1
  82. data/yarn.lock +3405 -2836
  83. metadata +38 -16
  84. data/gemfiles/Gemfile-rails.4.2.x +0 -9
  85. data/gemfiles/Gemfile-rails.5.0.x +0 -9
  86. data/gemfiles/Gemfile-rails.5.1.x +0 -9
  87. data/lib/install/javascript/packs/application.js +0 -18
  88. data/lib/install/loaders/typescript.js +0 -11
data/README.md CHANGED
@@ -20,6 +20,7 @@ Summarizing the changes because they're impossible to remember 🤦🏻‍♂️
20
20
  * add `Jets.version` to info command
21
21
  * Fix generators by using `Rails::Generators::AppGenerator` directly instead of `bin/stubs`
22
22
  * 2 separate versions: `Jetpacker::VERSION` and `Webpacker::VERSION`
23
+ * Default `extract_css: true`
23
24
 
24
25
  Happy Hackin' 😁
25
26
  Tung
@@ -28,667 +29,41 @@ Tung
28
29
 
29
30
  Here's info on the git branch and tags strategy.
30
31
 
32
+ * the latest upstream webpacker version that has been merged back in is v5.2.1
31
33
  * master: jetpacker fork with latest changes
32
- * forkpoint-1: git tag of point at which forked from rails/webpacker and changes were made. For diff: `git diff forkpoint-1..v0.2.0`
34
+ * forkpoint-1: git tag of point at which forked from rails/webpacker and **original** changes were made. For diff: `git diff forkpoint-1..v0.2.0`
33
35
  * rails git origin: upstream origin with rails/webpacker origin
34
36
 
35
- ## Original README Below
37
+ ## Upgrade Notes
36
38
 
37
- [![Build Status](https://travis-ci.org/rails/webpacker.svg?branch=master)](https://travis-ci.org/rails/webpacker)
38
- [![node.js](https://img.shields.io/badge/node-%3E%3D%208.16.0-brightgreen.svg)](https://nodejs.org/en/)
39
- [![Gem](https://img.shields.io/gem/v/webpacker.svg)](https://github.com/rails/webpacker)
39
+ If you run bundle so that jetpacker is updated. IE:
40
40
 
41
+ bundle update
42
+ # or
43
+ bundle update jetpacker
41
44
 
42
- Webpacker makes it easy to use the JavaScript pre-processor and bundler
43
- [webpack 4.x.x+](https://webpack.js.org/)
44
- to manage application-like JavaScript in Rails. It coexists with the asset pipeline,
45
- as the primary purpose for webpack is app-like JavaScript, not images, CSS, or
46
- even JavaScript Sprinkles (that all continues to live in app/assets).
45
+ You can update the webpacker-related files with:
47
46
 
48
- However, it is possible to use Webpacker for CSS, images and fonts assets as well,
49
- in which case you may not even need the asset pipeline. This is mostly relevant when exclusively using component-based JavaScript frameworks.
47
+ jets webpacker:install
50
48
 
51
- **NOTE:** The master branch now hosts the code for v4.x.x. Please refer to [3-x-stable](https://github.com/rails/webpacker/tree/3-x-stable) branch for 3.x documentation. See the [v4-upgrade guide](docs/v4-upgrade.md) for an overview of the changes.
49
+ Then update the manually the environment.js
52
50
 
53
- <!-- START doctoc generated TOC please keep comment here to allow auto update -->
54
- <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
55
- ## Table of Contents
51
+ config/webpacker/environment.js:
56
52
 
57
- - [Prerequisites](#prerequisites)
58
- - [Features](#features)
59
- - [Installation](#installation)
60
- - [Usage](#usage)
61
- - [Development](#development)
62
- - [Webpack Configuration](#webpack-configuration)
63
- - [Custom Rails environments](#custom-rails-environments)
64
- - [Upgrading](#upgrading)
65
- - [Yarn Integrity](#yarn-integrity)
66
- - [Integrations](#integrations)
67
- - [React](#react)
68
- - [Angular with TypeScript](#angular-with-typescript)
69
- - [Vue](#vue)
70
- - [Elm](#elm)
71
- - [Stimulus](#stimulus)
72
- - [Svelte](#svelte)
73
- - [CoffeeScript](#coffeescript)
74
- - [Erb](#erb)
75
- - [Paths](#paths)
76
- - [Resolved](#resolved)
77
- - [Watched](#watched)
78
- - [Deployment](#deployment)
79
- - [Docs](#docs)
80
- - [Contributing](#contributing)
81
- - [License](#license)
53
+ ```javascript
54
+ const { environment } = require('@rails/webpacker')
55
+ const webpack = require('webpack')
56
+ environment.plugins.prepend('Provide', new webpack.ProvidePlugin({
57
+ $: 'jquery',
58
+ jQuery: 'jquery',
59
+ Popper: ['popper.js', 'default']
60
+ }))
82
61
 
83
- <!-- END doctoc generated TOC please keep comment here to allow auto update -->
84
-
85
-
86
- ## Prerequisites
87
-
88
- * Ruby 2.2+
89
- * Rails 4.2+
90
- * Node.js 8.16.0+
91
- * Yarn 1.x+
92
-
93
-
94
- ## Features
95
-
96
- * [webpack 4.x.x](https://webpack.js.org/)
97
- * ES6 with [babel](https://babeljs.io/)
98
- * Automatic code splitting using multiple entry points
99
- * Stylesheets - Sass and CSS
100
- * Images and fonts
101
- * PostCSS - Auto-Prefixer
102
- * Asset compression, source-maps, and minification
103
- * CDN support
104
- * React, Angular, Elm and Vue support out-of-the-box
105
- * Rails view helpers
106
- * Extensible and configurable
107
-
108
-
109
- ## Installation
110
-
111
- You can either add Webpacker during setup of a new Rails 5.1+ application
112
- using new `--webpack` option:
113
-
114
- ```bash
115
- # Available Rails 5.1+
116
- rails new myapp --webpack
117
- ```
118
-
119
- Or add it to your `Gemfile`:
120
-
121
- ```ruby
122
- # Gemfile
123
- gem 'webpacker', '~> 4.x'
124
-
125
- # OR if you prefer to use master
126
- gem 'webpacker', git: 'https://github.com/rails/webpacker.git'
127
- yarn add https://github.com/rails/webpacker.git
128
- yarn add core-js regenerator-runtime
129
- ```
130
-
131
- Finally, run the following to install Webpacker:
132
-
133
- ```bash
134
- bundle
135
- bundle exec rails webpacker:install
136
-
137
- # OR (on rails version < 5.0)
138
- bundle exec rake webpacker:install
139
- ```
140
-
141
- Optional: To fix ["unmet peer dependency" warnings](https://github.com/rails/webpacker/issues/1078),
142
-
143
- ```bash
144
- yarn upgrade
145
- ```
146
-
147
- ### Usage
148
-
149
- Once installed, you can start writing modern ES6-flavored JavaScript apps right away:
150
-
151
- ```yml
152
- app/javascript:
153
- ├── packs:
154
- │ # only webpack entry files here
155
- │ └── application.js
156
- └── src:
157
- │ └── application.css
158
- └── images:
159
- └── logo.svg
160
- ```
161
-
162
- In `/packs/application.js`, include this at the top of the file:
163
-
164
- ```js
165
- import "core-js/stable";
166
- import "regenerator-runtime/runtime";
167
- ```
168
-
169
- You can then link the JavaScript pack in Rails views using the `javascript_pack_tag` helper.
170
- If you have styles imported in your pack file, you can link them by using `stylesheet_pack_tag`:
171
-
172
- ```erb
173
- <%= javascript_pack_tag 'application' %>
174
- <%= stylesheet_pack_tag 'application' %>
175
- ```
176
-
177
- If you want to link a static asset for `<link rel="prefetch">` or `<img />` tag, you
178
- can use the `asset_pack_path` helper:
179
-
180
- ```erb
181
- <link rel="prefetch" href="<%= asset_pack_path 'application.css' %>" />
182
- <img src="<%= asset_pack_path 'images/logo.svg' %>" />
183
- ```
184
-
185
- If you are using new webpack 4 split chunks API, then consider using `javascript_packs_with_chunks_tag` helper, which creates html
186
- tags for a pack and all the dependent chunks.
187
-
188
- ```erb
189
- <%= javascript_packs_with_chunks_tag 'calendar', 'map', 'data-turbolinks-track': 'reload' %>
190
-
191
- <script src="/packs/vendor-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
192
- <script src="/packs/calendar~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
193
- <script src="/packs/calendar-1016838bab065ae1e314.js" data-turbolinks-track="reload"></script>
194
- <script src="/packs/map~runtime-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
195
- <script src="/packs/map-16838bab065ae1e314.js" data-turbolinks-track="reload"></script>
196
- ```
197
-
198
- **Important:** Pass all your pack names when using `javascript_packs_with_chunks_tag`
199
- helper otherwise you will get duplicated chunks on the page.
200
-
201
- ```erb
202
- <%# DO %>
203
- <%= javascript_packs_with_chunks_tag 'calendar', 'map' %>
204
-
205
- <%# DON'T %>
206
- <%= javascript_packs_with_chunks_tag 'calendar' %>
207
- <%= javascript_packs_with_chunks_tag 'map' %>
208
- ```
209
-
210
- **Note:** In order for your styles or static assets files to be available in your view,
211
- you would need to link them in your "pack" or entry file.
212
-
213
-
214
- ### Development
215
-
216
- Webpacker ships with two binstubs: `./bin/webpack` and `./bin/webpack-dev-server`.
217
- Both are thin wrappers around the standard `webpack.js` and `webpack-dev-server.js`
218
- executables to ensure that the right configuration files and environmental variables
219
- are loaded based on your environment.
220
-
221
- In development, Webpacker compiles on demand rather than upfront by default. This
222
- happens when you refer to any of the pack assets using the Webpacker helper methods.
223
- This means that you don't have to run any separate processes. Compilation errors are logged
224
- to the standard Rails log.
225
-
226
- 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
227
- in a terminal separate from `bundle exec rails s`. This process will watch for changes
228
- in the `app/javascript/packs/*.js` files and automatically reload the browser to match.
229
-
230
- ```bash
231
- # webpack dev server
232
- ./bin/webpack-dev-server
233
-
234
- # watcher
235
- ./bin/webpack --watch --colors --progress
236
-
237
- # standalone build
238
- ./bin/webpack
239
- ```
240
-
241
- Once you start this development server, Webpacker will automatically start proxying all
242
- webpack asset requests to this server. When you stop the server, it'll revert back to
243
- on-demand compilation.
244
-
245
- You can use environment variables as options supported by
246
- [webpack-dev-server](https://webpack.js.org/configuration/dev-server/) in the
247
- form `WEBPACKER_DEV_SERVER_<OPTION>`. Please note that these environmental
248
- variables will always take precedence over the ones already set in the
249
- configuration file, and that the _same_ environmental variables must
250
- be available to the `rails server` process.
251
-
252
- ```bash
253
- WEBPACKER_DEV_SERVER_HOST=example.com WEBPACKER_DEV_SERVER_INLINE=true WEBPACKER_DEV_SERVER_HOT=false ./bin/webpack-dev-server
254
- ```
255
-
256
- By default, the webpack dev server listens on `localhost` in development for security purposes.
257
- However, if you want your app to be available over local LAN IP or a VM instance like vagrant,
258
- you can set the `host` when running `./bin/webpack-dev-server` binstub:
259
-
260
- ```bash
261
- WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
262
- ```
263
-
264
- **Note:** You need to allow webpack-dev-server host as an allowed origin for `connect-src` if you are running your application in a restrict CSP environment (like Rails 5.2+). This can be done in Rails 5.2+ in the CSP initializer `config/initializers/content_security_policy.rb` with a snippet like this:
265
-
266
- ```ruby
267
- Rails.application.config.content_security_policy do |policy|
268
- policy.connect_src :self, :https, 'http://localhost:3035', 'ws://localhost:3035' if Rails.env.development?
269
- end
270
- ```
271
-
272
- **Note:** Don't forget to prefix `ruby` when running these binstubs on Windows
273
-
274
- ### Webpack Configuration
275
-
276
- See [docs/webpack](docs/webpack.md) for modifying webpack configuration and loaders.
277
-
278
-
279
- ### Custom Rails environments
280
-
281
- Out of the box Webpacker ships with - development, test and production environments in `config/webpacker.yml` however, in most production apps extra environments are needed as part of deployment workflow. Webpacker supports this out of the box from version 3.4.0+ onwards.
282
-
283
- You can choose to define additional environment configurations in webpacker.yml,
284
-
285
- ```yml
286
- staging:
287
- <<: *default
288
-
289
- # Production depends on precompilation of packs prior to booting for performance.
290
- compile: false
291
-
292
- # Cache manifest.json for performance
293
- cache_manifest: true
294
-
295
- # Compile staging packs to a separate directory
296
- public_output_path: packs-staging
297
- ```
298
-
299
- or, Webpacker will use production environment as a fallback environment for loading configurations. Please note, `NODE_ENV` can either be set to `production`, `development` or `test`.
300
- This means you don't need to create additional environment files inside `config/webpacker/*` and instead use webpacker.yml to load different configurations using `RAILS_ENV`.
301
-
302
- For example, the below command will compile assets in production mode but will use staging configurations from `config/webpacker.yml` if available or use fallback production environment configuration:
303
-
304
- ```bash
305
- RAILS_ENV=staging bundle exec rails assets:precompile
306
- ```
307
-
308
- And, this will compile in development mode and load configuration for cucumber environment
309
- if defined in webpacker.yml or fallback to production configuration
310
-
311
- ```bash
312
- RAILS_ENV=cucumber NODE_ENV=development bundle exec rails assets:precompile
313
- ```
314
-
315
- Please note, binstubs compiles in development mode however rake tasks
316
- compiles in production mode.
317
-
318
- ```bash
319
- # Compiles in development mode unless NODE_ENV is specified
320
- ./bin/webpack
321
- ./bin/webpack-dev-server
322
-
323
- # compiles in production mode by default unless NODE_ENV is specified
324
- bundle exec rails assets:precompile
325
- bundle exec rails webpacker:compile
326
- ```
327
-
328
-
329
- ### Upgrading
330
-
331
- You can run following commands to upgrade Webpacker to the latest stable version. This process involves upgrading the gem and related JavaScript packages:
332
-
333
- ```bash
334
- bundle update webpacker
335
- rails webpacker:binstubs
336
- yarn upgrade @rails/webpacker --latest
337
- yarn upgrade webpack-dev-server --latest
338
-
339
- # Or to install the latest release (including pre-releases)
340
- yarn add @rails/webpacker@next
341
- ```
342
-
343
- ### Yarn Integrity
344
-
345
- By default, in development, webpacker runs a yarn integrity check to ensure that all local JavaScript packages are up-to-date. This is similar to what bundler does currently in Rails, but for JavaScript packages. If your system is out of date, then Rails will not initialize. You will be asked to upgrade your local JavaScript packages by running `yarn install`.
346
-
347
- To turn off this option, you will need to change the default setting in `config/webpacker.yml`:
348
-
349
- ```yaml
350
- # config/webpacker.yml
351
- development:
352
- ...
353
- # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
354
- check_yarn_integrity: false
355
- ```
356
-
357
- You may also turn on this feature by adding the config option for any Rails environment in `config/webpacker.yml`:
358
-
359
- ```yaml
360
- check_yarn_integrity: true
361
- ```
362
-
363
- ## Integrations
364
-
365
- Webpacker ships with basic out-of-the-box integration for React, Angular, Vue and Elm.
366
- You can see a list of available commands/tasks by running `bundle exec rails webpacker`:
367
-
368
- ### React
369
-
370
- To use Webpacker with [React](https://facebook.github.io/react/), create a
371
- new Rails 5.1+ app using `--webpack=react` option:
372
-
373
- ```bash
374
- # Rails 5.1+
375
- rails new myapp --webpack=react
376
- ```
377
-
378
- (or run `bundle exec rails webpacker:install:react` in an existing Rails app already
379
- setup with Webpacker).
380
-
381
- The installer will add all relevant dependencies using Yarn, changes
382
- to the configuration files, and an example React component to your
383
- project in `app/javascript/packs` so that you can experiment with React right away.
384
-
385
-
386
- ### Angular with TypeScript
387
-
388
- To use Webpacker with [Angular](https://angular.io/), create a
389
- new Rails 5.1+ app using `--webpack=angular` option:
390
-
391
- ```bash
392
- # Rails 5.1+
393
- rails new myapp --webpack=angular
394
- ```
395
-
396
- (or run `bundle exec rails webpacker:install:angular` on a Rails app already
397
- setup with Webpacker).
398
-
399
- The installer will add the TypeScript and Angular core libraries using Yarn alongside
400
- a few changes to the configuration files. An example component written in
401
- TypeScript will also be added to your project in `app/javascript` so that
402
- you can experiment with Angular right away.
403
-
404
- By default, Angular uses a JIT compiler for development environment. This
405
- compiler is not compatible with restrictive CSP (Content Security
406
- Policy) environments like Rails 5.2+. You can use Angular AOT compiler
407
- in development with the [@ngtools/webpack](https://www.npmjs.com/package/@ngtools/webpack#usage) plugin.
408
-
409
- Alternatively if you're using Rails 5.2+ you can enable `unsafe-eval` rule for your
410
- development environment. This can be done in the `config/initializers/content_security_policy.rb`
411
- with the following code:
412
-
413
- ```ruby
414
- Rails.application.config.content_security_policy do |policy|
415
- if Rails.env.development?
416
- policy.script_src :self, :https, :unsafe_eval
417
- else
418
- policy.script_src :self, :https
419
- end
420
- end
421
- ```
422
-
423
-
424
- ### Vue
425
-
426
- To use Webpacker with [Vue](https://vuejs.org/), create a
427
- new Rails 5.1+ app using `--webpack=vue` option:
428
-
429
- ```bash
430
- # Rails 5.1+
431
- rails new myapp --webpack=vue
432
- ```
433
- (or run `bundle exec rails webpacker:install:vue` on a Rails app already setup with Webpacker).
434
-
435
- The installer will add Vue and its required libraries using Yarn alongside
436
- automatically applying changes needed to the configuration files. An example component will
437
- be added to your project in `app/javascript` so that you can experiment with Vue right away.
438
-
439
- If you're using Rails 5.2+ you'll need to enable `unsafe-eval` rule for your development environment.
440
- This can be done in the `config/initializers/content_security_policy.rb` with the following
441
- configuration:
442
-
443
- ```ruby
444
- Rails.application.config.content_security_policy do |policy|
445
- if Rails.env.development?
446
- policy.script_src :self, :https, :unsafe_eval
447
- else
448
- policy.script_src :self, :https
449
- end
450
- end
451
- ```
452
- You can read more about this in the [Vue docs](https://vuejs.org/v2/guide/installation.html#CSP-environments).
453
-
454
- #### Lazy loading integration
455
-
456
- See [docs/es6](docs/es6.md) to know more about Webpack and Webpacker configuration.
457
-
458
- For instance, you can lazy load Vue JS components:
459
-
460
- Before:
461
- ```js
462
- import Vue from 'vue'
463
- import { VCard } from 'vuetify/lib'
464
-
465
- Vue.component('VCard', VCard)
466
- ```
467
-
468
- After:
469
- ```js
470
- import Vue from 'vue'
471
-
472
- // With destructuring assignment
473
- Vue.component('VCard', import('vuetify/lib').then(({ VCard }) => VCard)
474
-
475
- // Or without destructuring assignment
476
- Vue.component('OtherComponent', () => import('./OtherComponent'))
477
- ```
478
-
479
- You can use it in a Single File Component as well:
480
-
481
- ```html
482
- <template>
483
- ...
484
- </template>
485
-
486
- <script>
487
- export default {
488
- components: {
489
- OtherComponent: () => import('./OtherComponent')
490
- }
491
- }
492
- </script>
493
- ```
494
-
495
- By wrapping the import function into an arrow function, Vue will execute it only when it gets requested, loading the module in that moment.
496
-
497
- ##### Automatic registration
498
-
499
- ```js
500
- /**
501
- * The following block of code may be used to automatically register your
502
- * Vue components. It will recursively scan this directory for the Vue
503
- * components and automatically register them with their "basename".
504
- *
505
- * Eg. ./components/OtherComponent.vue -> <other-component></other-component>
506
- * Eg. ./UI/ButtonComponent.vue -> <button-component></button-component>
507
- */
508
-
509
- const files = require.context('./', true, /\.vue$/i)
510
- files.keys().map(key => {
511
- const component = key.split('/').pop().split('.')[0]
512
-
513
- // With Lazy Loading
514
- Vue.component(component, () => import(`${key}`))
515
-
516
- // Or without Lazy Loading
517
- Vue.component(component, files(key).default)
518
- })
519
- ```
520
-
521
- ### Elm
522
-
523
- To use Webpacker with [Elm](http://elm-lang.org), create a
524
- new Rails 5.1+ app using `--webpack=elm` option:
525
-
526
- ```
527
- # Rails 5.1+
528
- rails new myapp --webpack=elm
529
- ```
530
-
531
- (or run `bundle exec rails webpacker:install:elm` on a Rails app already setup with Webpacker).
532
-
533
- The Elm library and its core packages will be added via Yarn and Elm.
534
- An example `Main.elm` app will also be added to your project in `app/javascript`
535
- so that you can experiment with Elm right away.
536
-
537
- ### Svelte
538
-
539
- To use Webpacker with [Svelte](https://svelte.dev), create a
540
- new Rails 5.1+ app using `--webpack=svelte` option:
541
-
542
- ```
543
- # Rails 5.1+
544
- rails new myapp --webpack=svelte
545
- ```
546
-
547
- (or run `bundle exec rails webpacker:install:svelte` on a Rails app already setup with Webpacker).
548
-
549
- Please play with the [Svelte Tutorial](https://svelte.dev/tutorial/basics) or learn more about its API at https://svelte.dev/docs
550
-
551
- ### Stimulus
552
-
553
- To use Webpacker with [Stimulus](http://stimulusjs.org), create a
554
- new Rails 5.1+ app using `--webpack=stimulus` option:
555
-
556
- ```
557
- # Rails 5.1+
558
- rails new myapp --webpack=stimulus
559
- ```
560
-
561
- (or run `bundle exec rails webpacker:install:stimulus` on a Rails app already setup with Webpacker).
562
-
563
- Please read [The Stimulus Handbook](https://stimulusjs.org/handbook/introduction) or learn more about its source code at https://github.com/stimulusjs/stimulus
564
-
565
- ### CoffeeScript
566
-
567
- To add [CoffeeScript](http://coffeescript.org/) support,
568
- run `bundle exec rails webpacker:install:coffee` on a Rails app already
569
- setup with Webpacker.
570
-
571
- An example `hello_coffee.coffee` file will also be added to your project
572
- in `app/javascript/packs` so that you can experiment with CoffeeScript right away.
573
-
574
- ### Erb
575
-
576
- To add [Erb](https://apidock.com/ruby/ERB) support in your JS templates,
577
- run `bundle exec rails webpacker:install:erb` on a Rails app already
578
- setup with Webpacker.
579
-
580
- An example `hello_erb.js.erb` file will also be added to your project
581
- in `app/javascript/packs` so that you can experiment with Erb-flavoured
582
- javascript right away.
583
-
584
-
585
- ## Paths
586
-
587
- By default, Webpacker ships with simple conventions for where the JavaScript
588
- app files and compiled webpack bundles will go in your Rails app.
589
- All these options are configurable from `config/webpacker.yml` file.
590
-
591
- The configuration for what webpack is supposed to compile by default rests
592
- on the convention that every file in `app/javascript/packs/*`**(default)**
593
- or whatever path you set for `source_entry_path` in the `webpacker.yml` configuration
594
- 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
595
- an entry file. As a rule of thumb, put all files you want to link in your views inside
596
- "packs" directory and keep everything else under `app/javascript`.
597
-
598
- Suppose you want to change the source directory from `app/javascript`
599
- to `frontend` and output to `assets/packs`. This is how you would do it:
600
-
601
- ```yml
602
- # config/webpacker.yml
603
- source_path: frontend
604
- source_entry_path: packs
605
- public_output_path: assets/packs # outputs to => public/assets/packs
62
+ module.exports = environment
606
63
  ```
607
64
 
608
- Similarly you can also control and configure `webpack-dev-server` settings from `config/webpacker.yml` file:
609
-
610
- ```yml
611
- # config/webpacker.yml
612
- development:
613
- dev_server:
614
- host: localhost
615
- port: 3035
616
- ```
617
-
618
- 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.
619
-
620
-
621
- ### Resolved
622
-
623
- If you are adding Webpacker to an existing app that has most of the assets inside
624
- `app/assets` or inside an engine, and you want to share that
625
- with webpack modules, you can use the `resolved_paths`
626
- option available in `config/webpacker.yml`. This lets you
627
- add additional paths that webpack should lookup when resolving modules:
628
-
629
- ```yml
630
- resolved_paths: ['app/assets']
631
- ```
632
-
633
- You can then import these items inside your modules like so:
634
-
635
- ```js
636
- // Note it's relative to parent directory i.e. app/assets
637
- import 'stylesheets/main'
638
- import 'images/rails.png'
639
- ```
640
-
641
- **Note:** Please be careful when adding paths here otherwise it
642
- will make the compilation slow, consider adding specific paths instead of
643
- whole parent directory if you just need to reference one or two modules
644
-
645
-
646
- ### Watched
647
-
648
- By default, the lazy compilation is cached until a file is changed under your
649
- tracked paths. You can configure which paths are tracked
650
- by adding new paths to `watched_paths` array. This is much like Rails' `autoload_paths`:
651
-
652
- ```rb
653
- # config/initializers/webpacker.rb
654
- # or config/application.rb
655
- Webpacker::Compiler.watched_paths << 'bower_components'
656
- ```
657
-
658
-
659
- ## Deployment
660
-
661
- Webpacker hooks up a new `webpacker:compile` task to `assets:precompile`, which gets run whenever you run `assets:precompile`. If you are not using Sprockets, `webpacker:compile` is automatically aliased to `assets:precompile`. Similar to sprockets both rake tasks will compile packs in production mode but will use `RAILS_ENV` to load configuration from `config/webpacker.yml` (if available).
662
-
663
-
664
- ## Docs
665
-
666
- - [Development](https://github.com/rails/webpacker#development)
667
- - [Webpack](./docs/webpack.md)
668
- - [Webpack-dev-server](./docs/webpack-dev-server.md)
669
- - [Environment Variables](./docs/env.md)
670
- - [Folder Structure](./docs/folder-structure.md)
671
- - [Assets](./docs/assets.md)
672
- - [CSS, Sass and SCSS](./docs/css.md)
673
- - [ES6](./docs/es6.md)
674
- - [Props](./docs/props.md)
675
- - [Typescript](./docs/typescript.md)
676
- - [Yarn](./docs/yarn.md)
677
- - [Misc](./docs/misc.md)
678
- - [Deployment](./docs/deployment.md)
679
- - [Docker](./docs/docker.md)
680
- - [Using in Rails engines](./docs/engines.md)
681
- - [Webpacker on Cloud9](./docs/cloud9.md)
682
- - [Testing](./docs/testing.md)
683
- - [Troubleshooting](./docs/troubleshooting.md)
684
- - [v3 to v4 Upgrade Guide](./docs/v4-upgrade.md)
685
-
686
-
687
- ## Contributing
688
- [![Code Helpers](https://www.codetriage.com/rails/webpacker/badges/users.svg)](https://www.codetriage.com/rails/webpacker)
689
-
690
- We encourage you to contribute to Webpacker! See [CONTRIBUTING](CONTRIBUTING.md) for guidelines about how to proceed.
65
+ This adds jquery so the crud.js works.
691
66
 
67
+ ## Original README
692
68
 
693
- ## License
694
- Webpacker is released under the [MIT License](https://opensource.org/licenses/MIT).
69
+ https://github.com/rails/webpacker