webpacker 5.4.4 → 6.0.0.rc.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -1
  3. data/.github/workflows/jest.yml +7 -15
  4. data/.github/workflows/js-lint.yml +7 -15
  5. data/.github/workflows/rubocop.yml +1 -1
  6. data/.github/workflows/ruby.yml +18 -16
  7. data/.gitignore +2 -0
  8. data/.node-version +1 -1
  9. data/.rubocop.yml +5 -7
  10. data/CHANGELOG.md +30 -12
  11. data/CONTRIBUTING.md +20 -1
  12. data/Gemfile.lock +83 -83
  13. data/README.md +389 -179
  14. data/config/README.md +3 -0
  15. data/config/webpacker.yml +1 -0
  16. data/docs/deployment.md +9 -11
  17. data/docs/developing_webpacker.md +29 -0
  18. data/docs/troubleshooting.md +61 -25
  19. data/docs/v6_upgrade.md +113 -0
  20. data/gemfiles/Gemfile-rails.6.1.x +12 -0
  21. data/lib/install/{javascript/packs/application.js → application.js} +2 -5
  22. data/lib/install/bin/webpack +4 -7
  23. data/lib/install/bin/yarn +18 -0
  24. data/lib/install/config/webpack/base.js +3 -0
  25. data/lib/install/config/webpack/development.js +2 -2
  26. data/lib/install/config/webpack/production.js +2 -2
  27. data/lib/install/config/webpack/test.js +2 -2
  28. data/lib/install/config/webpacker.yml +21 -49
  29. data/lib/install/package.json +15 -0
  30. data/lib/install/template.rb +64 -29
  31. data/lib/tasks/webpacker/binstubs.rake +6 -4
  32. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  33. data/lib/tasks/webpacker/check_node.rake +3 -0
  34. data/lib/tasks/webpacker/check_yarn.rake +3 -0
  35. data/lib/tasks/webpacker/clobber.rake +1 -1
  36. data/lib/tasks/webpacker/compile.rake +4 -2
  37. data/lib/tasks/webpacker/info.rake +12 -10
  38. data/lib/tasks/webpacker/install.rake +6 -4
  39. data/lib/tasks/webpacker/verify_config.rake +14 -0
  40. data/lib/tasks/webpacker/verify_install.rake +1 -10
  41. data/lib/tasks/webpacker/yarn_install.rake +9 -7
  42. data/lib/tasks/webpacker.rake +2 -11
  43. data/lib/tasks/yarn.rake +38 -0
  44. data/lib/webpacker/commands.rb +21 -16
  45. data/lib/webpacker/compiler.rb +16 -9
  46. data/lib/webpacker/configuration.rb +8 -32
  47. data/lib/webpacker/dev_server.rb +6 -0
  48. data/lib/webpacker/dev_server_runner.rb +28 -4
  49. data/lib/webpacker/helper.rb +47 -81
  50. data/lib/webpacker/instance.rb +4 -0
  51. data/lib/webpacker/manifest.rb +2 -3
  52. data/lib/webpacker/railtie.rb +8 -2
  53. data/lib/webpacker/runner.rb +1 -1
  54. data/lib/webpacker/version.rb +1 -1
  55. data/lib/webpacker/webpack_runner.rb +29 -3
  56. data/lib/webpacker.rb +1 -1
  57. data/package/__tests__/config.js +5 -37
  58. data/package/__tests__/development.js +13 -21
  59. data/package/__tests__/env.js +16 -4
  60. data/package/__tests__/index.js +9 -0
  61. data/package/__tests__/production.js +6 -6
  62. data/package/__tests__/staging.js +7 -6
  63. data/package/__tests__/test.js +4 -5
  64. data/package/babel/preset.js +54 -0
  65. data/package/config.js +6 -14
  66. data/package/env.js +13 -4
  67. data/package/environments/__tests__/base.js +20 -52
  68. data/package/environments/base.js +68 -128
  69. data/package/environments/development.js +49 -47
  70. data/package/environments/production.js +66 -64
  71. data/package/environments/test.js +2 -2
  72. data/package/index.js +15 -8
  73. data/package/inliningCss.js +7 -0
  74. data/package/rules/babel.js +10 -8
  75. data/package/rules/coffee.js +6 -0
  76. data/package/rules/erb.js +15 -0
  77. data/package/rules/file.js +21 -19
  78. data/package/rules/index.js +16 -18
  79. data/package/rules/less.js +22 -0
  80. data/package/rules/raw.js +5 -0
  81. data/package/rules/sass.js +9 -10
  82. data/package/rules/stylus.js +26 -0
  83. data/package/utils/get_style_rule.js +28 -36
  84. data/package/utils/helpers.js +28 -35
  85. data/package.json +18 -38
  86. data/test/command_test.rb +76 -0
  87. data/test/compiler_test.rb +0 -12
  88. data/test/configuration_test.rb +4 -35
  89. data/test/dev_server_runner_test.rb +36 -6
  90. data/test/engine_rake_tasks_test.rb +39 -0
  91. data/test/helper_test.rb +79 -77
  92. data/test/manifest_test.rb +16 -0
  93. data/test/mounted_app/Rakefile +4 -0
  94. data/test/mounted_app/test/dummy/Rakefile +3 -0
  95. data/test/mounted_app/test/dummy/bin/rails +3 -0
  96. data/test/mounted_app/test/dummy/bin/rake +3 -0
  97. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  98. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  99. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  100. data/test/mounted_app/test/dummy/config.ru +5 -0
  101. data/test/mounted_app/test/dummy/package.json +7 -0
  102. data/test/rake_tasks_test.rb +1 -10
  103. data/test/test_app/app/{javascript/packs → packs/entrypoints}/application.js +1 -1
  104. data/test/test_app/config/initializers/inspect_autoload_paths.rb +1 -0
  105. data/test/test_app/config/webpacker.yml +5 -31
  106. data/test/test_app/config/webpacker_other_location.yml +79 -0
  107. data/test/test_app/config/webpacker_public_root.yml +0 -1
  108. data/test/test_app/public/packs/manifest.json +36 -18
  109. data/test/test_app/some.config.js +0 -0
  110. data/test/webpack_runner_test.rb +9 -3
  111. data/test/webpacker_test.rb +21 -0
  112. data/webpacker.gemspec +2 -2
  113. data/yarn.lock +1277 -4620
  114. metadata +63 -92
  115. data/docs/assets.md +0 -119
  116. data/docs/cloud9.md +0 -310
  117. data/docs/css.md +0 -308
  118. data/docs/docker.md +0 -68
  119. data/docs/engines.md +0 -213
  120. data/docs/env.md +0 -63
  121. data/docs/es6.md +0 -72
  122. data/docs/folder-structure.md +0 -66
  123. data/docs/integrations.md +0 -220
  124. data/docs/misc.md +0 -23
  125. data/docs/props.md +0 -223
  126. data/docs/target.md +0 -22
  127. data/docs/testing.md +0 -136
  128. data/docs/typescript.md +0 -190
  129. data/docs/v4-upgrade.md +0 -142
  130. data/docs/webpack-dev-server.md +0 -92
  131. data/docs/webpack.md +0 -364
  132. data/docs/yarn.md +0 -23
  133. data/lib/install/angular.rb +0 -23
  134. data/lib/install/coffee.rb +0 -25
  135. data/lib/install/config/.browserslistrc +0 -1
  136. data/lib/install/config/babel.config.js +0 -82
  137. data/lib/install/config/postcss.config.js +0 -12
  138. data/lib/install/config/webpack/environment.js +0 -3
  139. data/lib/install/elm.rb +0 -39
  140. data/lib/install/erb.rb +0 -25
  141. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  142. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  143. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  144. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  145. data/lib/install/examples/angular/hello_angular.js +0 -7
  146. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  147. data/lib/install/examples/elm/Main.elm +0 -55
  148. data/lib/install/examples/elm/hello_elm.js +0 -16
  149. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  150. data/lib/install/examples/react/babel.config.js +0 -99
  151. data/lib/install/examples/react/hello_react.jsx +0 -26
  152. data/lib/install/examples/react/tsconfig.json +0 -21
  153. data/lib/install/examples/stimulus/application.js +0 -1
  154. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  155. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  156. data/lib/install/examples/svelte/app.svelte +0 -11
  157. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  158. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  159. data/lib/install/examples/typescript/tsconfig.json +0 -24
  160. data/lib/install/examples/vue/app.vue +0 -22
  161. data/lib/install/examples/vue/hello_vue.js +0 -72
  162. data/lib/install/loaders/coffee.js +0 -6
  163. data/lib/install/loaders/elm.js +0 -25
  164. data/lib/install/loaders/erb.js +0 -11
  165. data/lib/install/loaders/svelte.js +0 -9
  166. data/lib/install/loaders/vue.js +0 -6
  167. data/lib/install/react.rb +0 -18
  168. data/lib/install/stimulus.rb +0 -12
  169. data/lib/install/svelte.rb +0 -29
  170. data/lib/install/typescript.rb +0 -39
  171. data/lib/install/vue.rb +0 -49
  172. data/lib/tasks/installers.rake +0 -42
  173. data/package/config_types/__tests__/config_list.js +0 -118
  174. data/package/config_types/__tests__/config_object.js +0 -43
  175. data/package/config_types/config_list.js +0 -75
  176. data/package/config_types/config_object.js +0 -55
  177. data/package/config_types/index.js +0 -7
  178. data/package/rules/module.css.js +0 -3
  179. data/package/rules/module.sass.js +0 -8
  180. data/package/rules/node_modules.js +0 -22
  181. data/package/utils/__tests__/deep_assign.js +0 -32
  182. data/package/utils/__tests__/deep_merge.js +0 -10
  183. data/package/utils/__tests__/get_style_rule.js +0 -65
  184. data/package/utils/__tests__/objectify.js +0 -9
  185. data/package/utils/deep_assign.js +0 -22
  186. data/package/utils/deep_merge.js +0 -22
  187. data/package/utils/objectify.js +0 -3
  188. /data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.css +0 -0
  189. /data/test/test_app/app/{javascript/packs → packs/entrypoints}/multi_entry.js +0 -0
data/docs/engines.md DELETED
@@ -1,213 +0,0 @@
1
- # Using in Rails engines
2
-
3
- If the application UI consists of multiple frontend application, you'd probably like to isolate their building too (e.g. if you use different frameworks/versions). Hence we needed our webpack(-er) to be isolated too: separate `package.json`, dev server, compilation process.
4
-
5
- You can do this by adding another Webpacker instance to your application.
6
-
7
- This guide describes how to do that using [Rails engines](https://guides.rubyonrails.org/engines.html).
8
-
9
-
10
- ## Step 1: create Rails engine.
11
-
12
- First, you create a Rails engine (say, `MyEngine`). See the official [Rails guide](https://guides.rubyonrails.org/engines.html).
13
-
14
- ## Step 2: install Webpacker within the engine.
15
-
16
- There is no built-in tasks to install Webpacker within the engine, thus you have to add all the require files manually (you can copy them from the main app):
17
- - Add `config/webpacker.yml` and `config/webpack/*.js` files
18
- - Add `bin/webpack` and `bin/webpack-dev-server` files
19
- - Add `package.json` with required deps.
20
-
21
-
22
- ## Step 3: configure Webpacker instance.
23
-
24
- - File `lib/my_engine.rb`
25
-
26
- ```ruby
27
- module MyEngine
28
- ROOT_PATH = Pathname.new(File.join(__dir__, ".."))
29
-
30
- class << self
31
- def webpacker
32
- @webpacker ||= ::Webpacker::Instance.new(
33
- root_path: ROOT_PATH,
34
- config_path: ROOT_PATH.join("config/webpacker.yml")
35
- )
36
- end
37
- end
38
- end
39
- ```
40
-
41
- ## Step 4: Configure dev server proxy.
42
-
43
- - File `lib/my_engine/engine.rb`
44
-
45
- ```ruby
46
- module MyEngine
47
- class Engine < ::Rails::Engine
48
- initializer "webpacker.proxy" do |app|
49
- insert_middleware = begin
50
- MyEngine.webpacker.config.dev_server.present?
51
- rescue
52
- nil
53
- end
54
- next unless insert_middleware
55
-
56
- app.middleware.insert_before(
57
- 0, Webpacker::DevServerProxy, # "Webpacker::DevServerProxy" if Rails version < 5
58
- ssl_verify_none: true,
59
- webpacker: MyEngine.webpacker
60
- )
61
- end
62
- end
63
- end
64
- ```
65
-
66
- If you have multiple webpackers, you would probably want to run multiple dev servers at a time, and hence be able to configure their setting through env vars (e.g. within a `docker-compose.yml` file):
67
-
68
- ```yml
69
- # webpacker.yml
70
- # ...
71
- development:
72
- # ...
73
- dev_server:
74
- env_prefix: "MY_ENGINE_WEBPACKER_DEV_SERVER"
75
- # ...
76
- ```
77
-
78
- ## Step 5: configure helper.
79
-
80
- - File `app/helpers/my_engine/application_helper.rb`
81
-
82
- ```ruby
83
- require "webpacker/helper"
84
-
85
- module MyEngine
86
- module ApplicationHelper
87
- include ::Webpacker::Helper
88
-
89
- def current_webpacker_instance
90
- MyEngine.webpacker
91
- end
92
- end
93
- end
94
- ```
95
-
96
- Now you can use `stylesheet_pack_tag` and `javascript_pack_tag` from within your engine.
97
-
98
- ## Step 6: rake tasks.
99
-
100
- Add Rake task to compile assets in production (`rake my_engine:webpacker:compile`)
101
-
102
- - File `my_engine_rootlib/tasks/my_engine_tasks.rake`
103
-
104
- ```ruby
105
- def ensure_log_goes_to_stdout
106
- old_logger = Webpacker.logger
107
- Webpacker.logger = ActiveSupport::Logger.new(STDOUT)
108
- yield
109
- ensure
110
- Webpacker.logger = old_logger
111
- end
112
-
113
-
114
- namespace :my_engine do
115
- namespace :webpacker do
116
- desc "Install deps with yarn"
117
- task :yarn_install do
118
- Dir.chdir(File.join(__dir__, "../..")) do
119
- system "yarn install --no-progress --production"
120
- end
121
- end
122
-
123
- desc "Compile JavaScript packs using webpack for production with digests"
124
- task compile: [:yarn_install, :environment] do
125
- Webpacker.with_node_env("production") do
126
- ensure_log_goes_to_stdout do
127
- if MyEngine.webpacker.commands.compile
128
- # Successful compilation!
129
- else
130
- # Failed compilation
131
- exit!
132
- end
133
- end
134
- end
135
- end
136
- end
137
- end
138
-
139
- def yarn_install_available?
140
- rails_major = Rails::VERSION::MAJOR
141
- rails_minor = Rails::VERSION::MINOR
142
-
143
- rails_major > 5 || (rails_major == 5 && rails_minor >= 1)
144
- end
145
-
146
- def enhance_assets_precompile
147
- # yarn:install was added in Rails 5.1
148
- deps = yarn_install_available? ? [] : ["my_engine:webpacker:yarn_install"]
149
- Rake::Task["assets:precompile"].enhance(deps) do
150
- Rake::Task["my_engine:webpacker:compile"].invoke
151
- end
152
- end
153
-
154
- # Compile packs after we've compiled all other assets during precompilation
155
- skip_webpacker_precompile = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
156
-
157
- unless skip_webpacker_precompile
158
- if Rake::Task.task_defined?("assets:precompile")
159
- enhance_assets_precompile
160
- else
161
- Rake::Task.define_task("assets:precompile" => "my_engine:webpacker:compile")
162
- end
163
- end
164
- ```
165
-
166
- ## Step 7: serving compiled packs.
167
-
168
- There are two approaches on serving compiled assets.
169
-
170
- ### Put engine's assets to the root app's public/ folder
171
-
172
- You can serve engine's assets using the main app's static files server which serves files from `public/` folder.
173
-
174
- For that you must configure your engine's webpacker to put compiled assets to the app's `public/` folder:
175
-
176
- ```yml
177
- # my_engine/config/webpacker.yml
178
- default: &default
179
- # ...
180
- # public_root_path could be used to override the path to `public/` folder
181
- # (relative to the engine root)
182
- public_root_path: ../public
183
- # use a different sub-folder name
184
- public_output_path: my-engine-packs
185
- ```
186
-
187
- ### Use a separate middleware
188
-
189
- To serve static assets from the engine's `public/` folder you must add a middleware and point it to your engine's webpacker output path:
190
-
191
- ```ruby
192
- # application.rb
193
-
194
- config.middleware.use(
195
- Rack::Static,
196
- urls: ["/my-engine-packs"], root: "my_engine/public"
197
- )
198
- ```
199
- or if you prefer to keep your engine-related configuration within the engine itself
200
-
201
- ```ruby
202
- # my-engine-root/lib/my-engine/engine.rb
203
- module MyEngine
204
- class Engine < ::Rails:Engine
205
- config.app_middleware.use(
206
- Rack::Static,
207
- urls: ["/my-engine-packs"], root: "my_engine/public"
208
- )
209
- end
210
- end
211
- ```
212
-
213
- **NOTE:** in the example above we assume that your `public_output_path` is set to `my-engine-packs` in your engine's `webpacker.yml`.
data/docs/env.md DELETED
@@ -1,63 +0,0 @@
1
- # Environment variables
2
-
3
-
4
- Environment variables are supported out of the box in Webpacker. For example if
5
- you run the webpack dev server like so:
6
- ```
7
- FOO=hello BAR=world ./bin/webpack-dev-server
8
- ```
9
-
10
- You can then reference these variables in your JavaScript app code with
11
- `process.env`:
12
-
13
- ```js
14
- console.log(process.env.FOO) // Compiles to console.log("hello")
15
- ```
16
-
17
- You may want to store configuration in environment variables via `.env` files,
18
- similar to the [dotenv Ruby gem](https://github.com/bkeepers/dotenv).
19
-
20
- In development, if you use [Foreman](http://ddollar.github.io/foreman) or [Invoker](http://invoker.codemancers.com)
21
- to launch the webpack server, both of these tools have basic support for a
22
- `.env` file (Invoker also supports `.env.local`), so no further configuration
23
- is needed.
24
-
25
- However, if you run the webpack server without Foreman/Invoker, or if you
26
- want more control over what `.env` files to load, you can use the
27
- [dotenv npm package](https://github.com/motdotla/dotenv). Here is what you could
28
- do to support a "Ruby-like" dotenv:
29
-
30
- ```
31
- yarn add dotenv
32
- ```
33
-
34
- ```javascript
35
- // config/webpack/environment.js
36
-
37
- ...
38
- const { environment } = require('@rails/webpacker')
39
- const webpack = require('webpack')
40
- const dotenv = require('dotenv')
41
-
42
- const dotenvFiles = [
43
- `.env.${process.env.NODE_ENV}.local`,
44
- '.env.local',
45
- `.env.${process.env.NODE_ENV}`,
46
- '.env'
47
- ]
48
- dotenvFiles.forEach((dotenvFile) => {
49
- dotenv.config({ path: dotenvFile, silent: true })
50
- })
51
-
52
- module.exports = environment
53
- ```
54
-
55
- **Warning:** using Foreman/Invoker and npm dotenv at the same time can result in
56
- confusing behavior, in that Foreman/Invoker variables take precedence over
57
- npm dotenv variables.
58
-
59
- If you'd like to pass custom variables to the on demand compiler, use `Webpacker::Compiler.env` attribute.
60
-
61
- ```rb
62
- Webpacker::Compiler.env['FRONTEND_API_KEY'] = 'your_secret_key'
63
- ```
data/docs/es6.md DELETED
@@ -1,72 +0,0 @@
1
- # ES6
2
-
3
- ## Babel
4
-
5
- Webpacker ships with [babel](https://babeljs.io/) - a JavaScript compiler so
6
- you can use next generation JavaScript, today. The Webpacker installer sets up a
7
- standard `babel.config.js` file in your app root, which will work great in most cases
8
- because of [@babel/preset-env](https://github.com/babel/babel/tree/master/packages/babel-preset-env).
9
-
10
- Following ES6/7 features are supported out of the box:
11
-
12
- * Async/await.
13
- * Object Rest/Spread Properties.
14
- * Exponentiation Operator.
15
- * Dynamic import() - useful for route level code-splitting
16
- * Class Fields and Static Properties.
17
-
18
- We have also included [core-js](https://github.com/zloirock/core-js) to polyfill features in the
19
- older browsers.
20
-
21
- Don't forget to add these lines into your main entry point:
22
-
23
- ```js
24
- import "core-js/stable";
25
- import "regenerator-runtime/runtime";
26
- ```
27
-
28
- ## Dynamic/Lazy Chunk Loading
29
-
30
- For this section, you need Webpack and Webpacker 4. Then enable `SplitChunks` as it is explained in [docs/webpack](webpack.md).
31
-
32
- [Dynamic code splitting](https://webpack.js.org/guides/code-splitting#dynamic-imports) enables you to conditionally request/run only the JS that you need. For example, if your site has a `searchBarComponent` on every page, you can reduce the page overhead by deferring the request for the `searchBarComponent` code until after the page has loaded, until the user has scrolled it into view, or until the user has clicked on an element.
33
-
34
- ```js
35
- function loadSearchBarComponent() {
36
- return import(/* webpackChunkName: "searchBarComponent" */ './pathTo/searchBarComponent')
37
- }
38
- ```
39
-
40
- The comment you see above (`/* webpackChunkName */`) is not arbitrary, it is one of webpacks [magic comments](https://webpack.js.org/api/module-methods/#magic-comments). They can be used to fine-tune `import()` with settings such as `defer` or `prefetch`.
41
-
42
- **Warning**: You should not attempt to dynamically load anything from your `packs/` folder. Instead, try to make your `pack` scripts a hub from which you dynamically load `non-pack` scripts.
43
-
44
- - [Docs for using magic comments](https://webpack.js.org/api/module-methods/#magic-comments)
45
- - [Docs for configuring `splitChunks` in webpacker](https://github.com/rails/webpacker/blob/master/docs/webpack.md#add-splitchunks-webpack-v4).
46
- - [Docs for using dynamic `import()`](https://webpack.js.org/guides/code-splitting#dynamic-imports).
47
-
48
- ## Module import vs require()
49
-
50
- While you are free to use `require()` and `module.exports`, we encourage you
51
- to use `import` and `export` instead since it reads and looks much better.
52
-
53
- ```js
54
- import Button from 'react-bootstrap/lib/Button'
55
-
56
- // or
57
- import { Button } from 'react-bootstrap'
58
-
59
- class Foo {
60
- // code...
61
- }
62
-
63
- export default Foo
64
- import Foo from './foo'
65
- ```
66
-
67
- You can also use named export and import
68
-
69
- ```js
70
- export const foo = () => console.log('hello world')
71
- import { foo } from './foo'
72
- ```
@@ -1,66 +0,0 @@
1
- # Folder Structure
2
-
3
-
4
- ## Packs a.k.a webpack entries
5
-
6
- "Packs" is a special directory made only for webpack entry files so don't put anything
7
- here that you don't want to link in your views.
8
-
9
-
10
- ## Source
11
-
12
- You can put your app source under `app/javascript` folder or whatever you have configured
13
- in `config/webpacker.yml`.
14
-
15
-
16
- ## Example
17
-
18
- Let's say you're building a calendar app. Your JS app structure could look like this:
19
-
20
- ```js
21
- // app/javascript/packs/calendar.js
22
-
23
- import 'calendar'
24
- ```
25
-
26
- ```
27
- app/javascript/calendar/index.js // gets loaded by import 'calendar'
28
- app/javascript/calendar/components/grid.jsx
29
- app/javascript/calendar/styles/grid.sass
30
- app/javascript/calendar/models/month.js
31
- ```
32
-
33
- ```erb
34
- <%# app/views/layouts/application.html.erb %>
35
-
36
- <%= javascript_pack_tag 'calendar' %>
37
- <%= stylesheet_pack_tag 'calendar' %>
38
- ```
39
-
40
- But it could also look a million other ways.
41
-
42
-
43
- ## Namespacing
44
-
45
- You can also namespace your packs using directories similar to a Rails app.
46
-
47
- ```
48
- app/javascript/packs/admin/orders.js
49
- app/javascript/packs/shop/orders.js
50
- ```
51
-
52
- and reference them in your views like this:
53
-
54
- ```erb
55
- <%# app/views/admin/orders/index.html.erb %>
56
-
57
- <%= javascript_pack_tag 'admin/orders' %>
58
- ```
59
-
60
- and
61
-
62
- ```erb
63
- <%# app/views/shop/orders/index.html.erb %>
64
-
65
- <%= javascript_pack_tag 'shop/orders' %>
66
- ```
data/docs/integrations.md DELETED
@@ -1,220 +0,0 @@
1
- # Integrations
2
-
3
- Webpacker ships with basic out-of-the-box integration for React, Angular, Vue and Elm.
4
- You can see a list of available commands/tasks by running `bundle exec rails webpacker`:
5
-
6
- ## React
7
-
8
- To use Webpacker with [React](https://facebook.github.io/react/), create a
9
- new Rails 5.1+ app using `--webpack=react` option:
10
-
11
- ```bash
12
- # Rails 5.1+
13
- rails new myapp --webpack=react
14
- ```
15
-
16
- (or run `bundle exec rails webpacker:install:react` in an existing Rails app already
17
- setup with Webpacker).
18
-
19
- The installer will add all relevant dependencies using Yarn, changes
20
- to the configuration files, and an example React component to your
21
- project in `app/javascript/packs` so that you can experiment with React right away.
22
-
23
-
24
- ## Angular with TypeScript
25
-
26
- To use Webpacker with [Angular](https://angular.io/), create a
27
- new Rails 5.1+ app using `--webpack=angular` option:
28
-
29
- ```bash
30
- # Rails 5.1+
31
- rails new myapp --webpack=angular
32
- ```
33
-
34
- (or run `bundle exec rails webpacker:install:angular` on a Rails app already
35
- setup with Webpacker).
36
-
37
- The installer will add the TypeScript and Angular core libraries using Yarn alongside
38
- a few changes to the configuration files. An example component written in
39
- TypeScript will also be added to your project in `app/javascript` so that
40
- you can experiment with Angular right away.
41
-
42
- By default, Angular uses a JIT compiler for development environment. This
43
- compiler is not compatible with restrictive CSP (Content Security
44
- Policy) environments like Rails 5.2+. You can use Angular AOT compiler
45
- in development with the [@ngtools/webpack](https://www.npmjs.com/package/@ngtools/webpack#usage) plugin.
46
-
47
- Alternatively if you're using Rails 5.2+ you can enable `unsafe-eval` rule for your
48
- development environment. This can be done in the `config/initializers/content_security_policy.rb`
49
- with the following code:
50
-
51
- ```ruby
52
- Rails.application.config.content_security_policy do |policy|
53
- if Rails.env.development?
54
- policy.script_src :self, :https, :unsafe_eval
55
- else
56
- policy.script_src :self, :https
57
- end
58
- end
59
- ```
60
-
61
-
62
- ## Vue
63
-
64
- To use Webpacker with [Vue](https://vuejs.org/), create a
65
- new Rails 5.1+ app using `--webpack=vue` option:
66
-
67
- ```bash
68
- # Rails 5.1+
69
- rails new myapp --webpack=vue
70
- ```
71
- (or run `bundle exec rails webpacker:install:vue` on a Rails app already setup with Webpacker).
72
-
73
- The installer will add Vue and its required libraries using Yarn alongside
74
- automatically applying changes needed to the configuration files. An example component will
75
- be added to your project in `app/javascript` so that you can experiment with Vue right away.
76
-
77
- If you're using Rails 5.2+ you'll need to enable `unsafe-eval` rule for your development environment.
78
- This can be done in the `config/initializers/content_security_policy.rb` with the following
79
- configuration:
80
-
81
- ```ruby
82
- Rails.application.config.content_security_policy do |policy|
83
- if Rails.env.development?
84
- policy.script_src :self, :https, :unsafe_eval
85
- else
86
- policy.script_src :self, :https
87
- end
88
- end
89
- ```
90
- You can read more about this in the [Vue docs](https://vuejs.org/v2/guide/installation.html#CSP-environments).
91
-
92
- ### Lazy loading integration
93
-
94
- See [docs/es6](es6.md) to know more about Webpack and Webpacker configuration.
95
-
96
- For instance, you can lazy load Vue JS components:
97
-
98
- Before:
99
- ```js
100
- import Vue from 'vue'
101
- import { VCard } from 'vuetify/lib'
102
-
103
- Vue.component('VCard', VCard)
104
- ```
105
-
106
- After:
107
- ```js
108
- import Vue from 'vue'
109
-
110
- // With destructuring assignment
111
- Vue.component('VCard', import('vuetify/lib').then(({ VCard }) => VCard)
112
-
113
- // Or without destructuring assignment
114
- Vue.component('OtherComponent', () => import('./OtherComponent'))
115
- ```
116
-
117
- You can use it in a Single File Component as well:
118
-
119
- ```html
120
- <template>
121
- ...
122
- </template>
123
-
124
- <script>
125
- export default {
126
- components: {
127
- OtherComponent: () => import('./OtherComponent')
128
- }
129
- }
130
- </script>
131
- ```
132
-
133
- By wrapping the import function into an arrow function, Vue will execute it only when it gets requested, loading the module in that moment.
134
-
135
- ##### Automatic registration
136
-
137
- ```js
138
- /**
139
- * The following block of code may be used to automatically register your
140
- * Vue components. It will recursively scan this directory for the Vue
141
- * components and automatically register them with their "basename".
142
- *
143
- * Eg. ./components/OtherComponent.vue -> <other-component></other-component>
144
- * Eg. ./UI/ButtonComponent.vue -> <button-component></button-component>
145
- */
146
-
147
- const files = require.context('./', true, /\.vue$/i)
148
- files.keys().map(key => {
149
- const component = key.split('/').pop().split('.')[0]
150
-
151
- // With Lazy Loading
152
- Vue.component(component, () => import(`${key}`))
153
-
154
- // Or without Lazy Loading
155
- Vue.component(component, files(key).default)
156
- })
157
- ```
158
-
159
- ## Elm
160
-
161
- To use Webpacker with [Elm](http://elm-lang.org), create a
162
- new Rails 5.1+ app using `--webpack=elm` option:
163
-
164
- ```
165
- # Rails 5.1+
166
- rails new myapp --webpack=elm
167
- ```
168
-
169
- (or run `bundle exec rails webpacker:install:elm` on a Rails app already setup with Webpacker).
170
-
171
- The Elm library and its core packages will be added via Yarn and Elm.
172
- An example `Main.elm` app will also be added to your project in `app/javascript`
173
- so that you can experiment with Elm right away.
174
-
175
- ## Svelte
176
-
177
- To use Webpacker with [Svelte](https://svelte.dev), create a
178
- new Rails 5.1+ app using `--webpack=svelte` option:
179
-
180
- ```
181
- # Rails 5.1+
182
- rails new myapp --webpack=svelte
183
- ```
184
-
185
- (or run `bundle exec rails webpacker:install:svelte` on a Rails app already setup with Webpacker).
186
-
187
- Please play with the [Svelte Tutorial](https://svelte.dev/tutorial/basics) or learn more about its API at https://svelte.dev/docs
188
-
189
- ## Stimulus
190
-
191
- To use Webpacker with [Stimulus](http://stimulusjs.org), create a
192
- new Rails 5.1+ app using `--webpack=stimulus` option:
193
-
194
- ```
195
- # Rails 5.1+
196
- rails new myapp --webpack=stimulus
197
- ```
198
-
199
- (or run `bundle exec rails webpacker:install:stimulus` on a Rails app already setup with Webpacker).
200
-
201
- Please read [The Stimulus Handbook](https://stimulusjs.org/handbook/introduction) or learn more about its source code at https://github.com/stimulusjs/stimulus
202
-
203
- ## CoffeeScript
204
-
205
- To add [CoffeeScript](http://coffeescript.org/) support,
206
- run `bundle exec rails webpacker:install:coffee` on a Rails app already
207
- setup with Webpacker.
208
-
209
- An example `hello_coffee.coffee` file will also be added to your project
210
- in `app/javascript/packs` so that you can experiment with CoffeeScript right away.
211
-
212
- ## Erb
213
-
214
- To add [Erb](https://apidock.com/ruby/ERB) support in your JS templates,
215
- run `bundle exec rails webpacker:install:erb` on a Rails app already
216
- setup with Webpacker.
217
-
218
- An example `hello_erb.js.erb` file will also be added to your project
219
- in `app/javascript/packs` so that you can experiment with Erb-flavoured
220
- javascript right away.
data/docs/misc.md DELETED
@@ -1,23 +0,0 @@
1
- # How-Tos
2
-
3
-
4
- ## Ignoring swap files
5
-
6
- If you are using vim or emacs and want to ignore certain files you can add `ignore-loader`:
7
-
8
- ```
9
- yarn add ignore-loader
10
- ```
11
-
12
- and add `ignore-loader` to `config/webpack/environment.js`
13
-
14
- ```js
15
- // ignores vue~ swap files
16
- const { environment } = require('@rails/webpacker')
17
- environment.loaders.append('ignore', {
18
- test: /.vue~$/,
19
- loader: 'ignore-loader'
20
- })
21
- ```
22
-
23
- And now all files with `.vue~` will be ignored by the webpack compiler.