webpacker-jets 3.2.100

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +7 -0
  2. data/.eslintignore +4 -0
  3. data/.eslintrc.js +14 -0
  4. data/.gitignore +6 -0
  5. data/.rubocop.yml +124 -0
  6. data/.travis.yml +32 -0
  7. data/CHANGELOG.md +523 -0
  8. data/Gemfile +13 -0
  9. data/Gemfile.lock +154 -0
  10. data/MIT-LICENSE +20 -0
  11. data/README.md +445 -0
  12. data/Rakefile +12 -0
  13. data/docs/assets.md +106 -0
  14. data/docs/cloud9.md +310 -0
  15. data/docs/css.md +116 -0
  16. data/docs/deployment.md +74 -0
  17. data/docs/docker.md +49 -0
  18. data/docs/env.md +65 -0
  19. data/docs/es6.md +53 -0
  20. data/docs/folder-structure.md +66 -0
  21. data/docs/misc.md +23 -0
  22. data/docs/props.md +223 -0
  23. data/docs/testing.md +128 -0
  24. data/docs/troubleshooting.md +119 -0
  25. data/docs/typescript.md +116 -0
  26. data/docs/webpack-dev-server.md +92 -0
  27. data/docs/webpack.md +297 -0
  28. data/docs/yarn.md +12 -0
  29. data/exe/webpack +8 -0
  30. data/exe/webpack-dev-server +8 -0
  31. data/gemfiles/Gemfile-rails-edge +13 -0
  32. data/gemfiles/Gemfile-rails.4.2.x +10 -0
  33. data/gemfiles/Gemfile-rails.5.0.x +10 -0
  34. data/gemfiles/Gemfile-rails.5.1.x +10 -0
  35. data/lib/install/angular.rb +27 -0
  36. data/lib/install/coffee.rb +22 -0
  37. data/lib/install/config/.babelrc +18 -0
  38. data/lib/install/config/.postcssrc.yml +3 -0
  39. data/lib/install/config/webpack/development.js +3 -0
  40. data/lib/install/config/webpack/environment.js +3 -0
  41. data/lib/install/config/webpack/production.js +3 -0
  42. data/lib/install/config/webpack/staging.js +3 -0
  43. data/lib/install/config/webpack/test.js +3 -0
  44. data/lib/install/config/webpacker.yml +79 -0
  45. data/lib/install/elm.rb +38 -0
  46. data/lib/install/erb.rb +22 -0
  47. data/lib/install/examples/angular/hello_angular.js +7 -0
  48. data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
  49. data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
  50. data/lib/install/examples/angular/hello_angular/index.ts +8 -0
  51. data/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
  52. data/lib/install/examples/angular/tsconfig.json +19 -0
  53. data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
  54. data/lib/install/examples/elm/Main.elm +54 -0
  55. data/lib/install/examples/elm/hello_elm.js +12 -0
  56. data/lib/install/examples/erb/hello_erb.js.erb +6 -0
  57. data/lib/install/examples/react/.babelrc +6 -0
  58. data/lib/install/examples/react/hello_react.jsx +26 -0
  59. data/lib/install/examples/vue/app.vue +22 -0
  60. data/lib/install/examples/vue/hello_vue.js +70 -0
  61. data/lib/install/javascript/packs/application.js +10 -0
  62. data/lib/install/loaders/coffee.js +6 -0
  63. data/lib/install/loaders/elm.js +23 -0
  64. data/lib/install/loaders/erb.js +11 -0
  65. data/lib/install/loaders/typescript.js +6 -0
  66. data/lib/install/loaders/vue.js +13 -0
  67. data/lib/install/react.rb +28 -0
  68. data/lib/install/template.rb +37 -0
  69. data/lib/install/vue.rb +26 -0
  70. data/lib/tasks/installers.rake +24 -0
  71. data/lib/tasks/webpacker.rake +22 -0
  72. data/lib/tasks/webpacker/check_binstubs.rake +12 -0
  73. data/lib/tasks/webpacker/check_node.rake +24 -0
  74. data/lib/tasks/webpacker/check_yarn.rake +24 -0
  75. data/lib/tasks/webpacker/clobber.rake +16 -0
  76. data/lib/tasks/webpacker/compile.rake +41 -0
  77. data/lib/tasks/webpacker/install.rake +13 -0
  78. data/lib/tasks/webpacker/verify_install.rake +16 -0
  79. data/lib/tasks/webpacker/yarn_install.rake +6 -0
  80. data/lib/webpacker.rb +32 -0
  81. data/lib/webpacker/commands.rb +23 -0
  82. data/lib/webpacker/compiler.rb +88 -0
  83. data/lib/webpacker/configuration.rb +87 -0
  84. data/lib/webpacker/dev_server.rb +61 -0
  85. data/lib/webpacker/dev_server_proxy.rb +26 -0
  86. data/lib/webpacker/dev_server_runner.rb +51 -0
  87. data/lib/webpacker/helper.rb +66 -0
  88. data/lib/webpacker/instance.rb +44 -0
  89. data/lib/webpacker/manifest.rb +75 -0
  90. data/lib/webpacker/railtie.rb +82 -0
  91. data/lib/webpacker/rake_tasks.rb +6 -0
  92. data/lib/webpacker/runner.rb +22 -0
  93. data/lib/webpacker/version.rb +9 -0
  94. data/lib/webpacker/webpack_runner.rb +15 -0
  95. data/package.json +67 -0
  96. data/package/__tests__/environment.js +74 -0
  97. data/package/config.js +34 -0
  98. data/package/config_types/__tests__/config_list.js +123 -0
  99. data/package/config_types/__tests__/config_object.js +43 -0
  100. data/package/config_types/config_list.js +85 -0
  101. data/package/config_types/config_object.js +55 -0
  102. data/package/config_types/index.js +7 -0
  103. data/package/environment.js +116 -0
  104. data/package/environments/development.js +46 -0
  105. data/package/environments/production.js +37 -0
  106. data/package/environments/test.js +3 -0
  107. data/package/index.js +20 -0
  108. data/package/rules/babel.js +13 -0
  109. data/package/rules/css.js +39 -0
  110. data/package/rules/file.js +13 -0
  111. data/package/rules/index.js +11 -0
  112. data/package/rules/sass.js +15 -0
  113. data/package/utils/__tests__/deep_assign.js +11 -0
  114. data/package/utils/__tests__/deep_merge.js +10 -0
  115. data/package/utils/__tests__/objectify.js +9 -0
  116. data/package/utils/deep_assign.js +22 -0
  117. data/package/utils/deep_merge.js +23 -0
  118. data/package/utils/helpers.js +32 -0
  119. data/package/utils/objectify.js +4 -0
  120. data/test/command_test.rb +27 -0
  121. data/test/compiler_test.rb +35 -0
  122. data/test/configuration_test.rb +69 -0
  123. data/test/dev_server_test.rb +24 -0
  124. data/test/helper_test.rb +52 -0
  125. data/test/manifest_test.rb +28 -0
  126. data/test/rake_tasks_test.rb +29 -0
  127. data/test/test_app/Rakefile +3 -0
  128. data/test/test_app/app/javascript/packs/application.js +10 -0
  129. data/test/test_app/config/application.rb +11 -0
  130. data/test/test_app/config/environment.rb +4 -0
  131. data/test/test_app/config/webpacker.yml +65 -0
  132. data/test/test_app/public/packs/manifest.json +6 -0
  133. data/test/test_helper.rb +29 -0
  134. data/webpacker-jets.gemspec +29 -0
  135. data/yarn.lock +5768 -0
  136. metadata +250 -0
data/docs/webpack.md ADDED
@@ -0,0 +1,297 @@
1
+ # webpack
2
+
3
+
4
+ ## Configuration
5
+
6
+ Webpacker gives you a default set of configuration files for test, development and
7
+ production environments in `config/webpack/*.js`. You can configure each individual
8
+ environment in their respective files or configure them all in the base
9
+ `config/webpack/environment.js` file.
10
+
11
+ By default, you don't need to make any changes to `config/webpack/*.js`
12
+ files since it's all standard production-ready configuration. However,
13
+ if you do need to customize or add a new loader, this is where you would go.
14
+
15
+ Here is how you can modify webpack configuration:
16
+
17
+ ```js
18
+ // config/webpack/custom.js
19
+ module.exports = {
20
+ resolve: {
21
+ alias: {
22
+ jquery: 'jquery/src/jquery',
23
+ vue: 'vue/dist/vue.js',
24
+ React: 'react',
25
+ ReactDOM: 'react-dom',
26
+ vue_resource: 'vue-resource/dist/vue-resource',
27
+ }
28
+ }
29
+ }
30
+
31
+ // config/webpack/environment.js
32
+ const environment = require('./environment')
33
+ const customConfig = require('./custom')
34
+
35
+ // Set nested object prop using path notation
36
+ environment.config.set('resolve.extensions', ['.foo', '.bar'])
37
+ environment.config.set('output.filename', '[name].js')
38
+
39
+ // Merge custom config
40
+ environment.config.merge(customConfig)
41
+
42
+ // Delete a property
43
+ environment.config.delete('output.chunkFilename')
44
+
45
+ module.exports = environment
46
+ ```
47
+
48
+ If you need access to configs within Webpacker's configuration,
49
+ you can import them like so:
50
+
51
+ ```js
52
+ const { config } = require('@rails/webpacker')
53
+
54
+ console.log(config.output_path)
55
+ console.log(config.source_path)
56
+ ```
57
+
58
+ ## Loaders
59
+
60
+ You can add additional loaders beyond the base set that Webpacker provides by
61
+ adding it to your environment. We'll use `json-loader` as an example:
62
+
63
+ ```
64
+ yarn add json-loader
65
+ ```
66
+
67
+ ```js
68
+ // config/webpack/environment.js
69
+ const { environment } = require('@rails/webpacker')
70
+
71
+ environment.loaders.append('json', {
72
+ test: /\.json$/,
73
+ use: 'json-loader'
74
+ })
75
+
76
+ // Insert json loader at the top of list
77
+ environment.loaders.prepend('json', jsonLoader)
78
+
79
+ // Insert json loader after/before a given loader
80
+ environment.loaders.insert('json', jsonLoader, { after: 'style'} )
81
+ environment.loaders.insert('json', jsonLoader, { before: 'babel'} )
82
+
83
+ module.exports = environment
84
+ ```
85
+
86
+ Finally add `.json` to the list of extensions in `config/webpacker.yml`. Now if you `import()` any `.json` files inside your JavaScript
87
+ they will be processed using `json-loader`. Voila!
88
+
89
+ You can also modify the loaders that Webpacker pre-configures for you. We'll update
90
+ the `babel` loader as an example:
91
+
92
+ ```js
93
+ // config/webpack/environment.js
94
+ const { environment } = require('@rails/webpacker')
95
+
96
+ const babelLoader = environment.loaders.get('babel')
97
+ babelLoader.options.cacheDirectory = false
98
+
99
+ module.exports = environment
100
+ ```
101
+
102
+ ### Coffeescript 2
103
+
104
+ Out of the box webpacker supports coffeescript 1,
105
+ but here is how you can use Coffeescript 2:
106
+
107
+ ```
108
+ yarn add coffeescript@2.0.1
109
+ ```
110
+
111
+ ```js
112
+ // config/webpack/environment.js
113
+ const { environment } = require('@rails/webpacker')
114
+
115
+ const babelLoader = environment.loaders.get('babel')
116
+
117
+ // Replace existing coffee loader with CS2 version
118
+ environment.loaders.insert('coffee', {
119
+ test: /\.coffee(\.erb)?$/,
120
+ use: babelLoader.use.concat(['coffee-loader'])
121
+ })
122
+
123
+ module.exports = environment
124
+ ```
125
+
126
+ ### React SVG loader
127
+
128
+ To use react svg loader, you should append svg loader before file loader:
129
+
130
+ ```js
131
+ const { environment } = require('@rails/webpacker')
132
+
133
+ const babelLoader = environment.loaders.get('babel')
134
+
135
+ environment.loaders.insert('svg', {
136
+ test: /\.svg$/,
137
+ use: babelLoader.use.concat([
138
+ {
139
+ loader: 'react-svg-loader',
140
+ options: {
141
+ jsx: true // true outputs JSX tags
142
+ }
143
+ }
144
+ ])
145
+ }, { before: 'file' })
146
+ ```
147
+
148
+
149
+ ### Url Loader
150
+
151
+ ```js
152
+ // config/webpack/loaders/url.js
153
+
154
+ const { assetHost } = require('@rails/webpacker')
155
+
156
+ module.exports = {
157
+ test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
158
+ use: [{
159
+ loader: 'url-loader',
160
+ options: {
161
+ limit: 10000,
162
+ name: '[name]-[hash].[ext]',
163
+ publicPath: assetHost.publicPathWithHost
164
+ }
165
+ }]
166
+ }
167
+
168
+ // config/webpack/environment.js
169
+
170
+ const { environment } = require('@rails/webpacker')
171
+
172
+ environment.loaders.prepend('url', url)
173
+ ```
174
+
175
+ ### Overriding Loader Options in webpack 3+ (for CSS Modules etc.)
176
+
177
+ In webpack 3+, if you'd like to specify additional or different options for a loader, edit `config/webpack/environment.js` and provide an options object to override. This is similar to the technique shown above, but the following example shows specifically how to apply CSS Modules, which is what you may be looking for:
178
+
179
+ ```javascript
180
+ const { environment } = require('@rails/webpacker')
181
+ const merge = require('webpack-merge')
182
+
183
+ const myCssLoaderOptions = {
184
+ modules: true,
185
+ sourceMap: true,
186
+ localIdentName: '[name]__[local]___[hash:base64:5]'
187
+ }
188
+
189
+ const CSSLoader = environment.loaders.get('sass').use.find(el => el.loader === 'css-loader')
190
+
191
+ CSSLoader.options = merge(CSSLoader.options, myCssLoaderOptions)
192
+
193
+ module.exports = environment
194
+ ```
195
+
196
+ See [issue #756](https://github.com/rails/webpacker/issues/756#issuecomment-327148547) for additional discussion of this.
197
+
198
+ For this to work, don't forget to use the `stylesheet_pack_tag`, for example:
199
+
200
+ ```
201
+ <%= stylesheet_pack_tag 'YOUR_PACK_NAME_HERE' %>
202
+ ```
203
+
204
+ ## Plugins
205
+
206
+ The process for adding or modifying webpack plugins is the same as the process
207
+ for loaders above:
208
+
209
+ ```js
210
+ // config/webpack/environment.js
211
+ const { environment } = require('@rails/webpacker')
212
+ const webpack = require('webpack')
213
+
214
+ // Get a pre-configured plugin
215
+ const manifestPlugin = environment.plugins.get('Manifest')
216
+ manifestPlugin.opts.writeToFileEmit = false
217
+
218
+ // Add an additional plugin of your choosing : ProvidePlugin
219
+ environment.plugins.prepend(
220
+ 'Provide',
221
+ new webpack.ProvidePlugin({
222
+ $: 'jquery',
223
+ jQuery: 'jquery',
224
+ jquery: 'jquery',
225
+ 'window.Tether': 'tether',
226
+ Popper: ['popper.js', 'default'],
227
+ ActionCable: 'actioncable',
228
+ Vue: 'vue',
229
+ VueResource: 'vue-resource',
230
+ })
231
+ )
232
+
233
+ // Insert before a given plugin
234
+ environment.plugins.insert('CommonChunkVendor',
235
+ new webpack.optimize.CommonsChunkPlugin({
236
+ name: 'vendor', // Vendor code
237
+ minChunks: (module) => module.context && module.context.indexOf('node_modules') !== -1
238
+ })
239
+ , { before: 'manifest' })
240
+
241
+ module.exports = environment
242
+ ```
243
+
244
+ ## Resolved modules
245
+
246
+ To add new paths to `resolve.modules`, the API is same as loaders and plugins:
247
+
248
+ ```js
249
+ const { environment } = require('@rails/webpacker')
250
+
251
+ // Resolved modules list API - prepend, append, insert
252
+ environment.resolvedModules.append('vendor', 'vendor')
253
+ ```
254
+
255
+ ### Add common chunks
256
+
257
+ The CommonsChunkPlugin is an opt-in feature that creates a separate file (known as a chunk), consisting of common modules shared between multiple entry points. By separating common modules from bundles, the resulting chunked file can be loaded once initially, and stored in the cache for later use. This results in page speed optimizations as the browser can quickly serve the shared code from the cache, rather than being forced to load a larger bundle whenever a new page is visited.
258
+
259
+ Add the plugins in `config/webpack/environment.js`:
260
+
261
+ ```js
262
+ const webpack = require('webpack')
263
+
264
+ environment.plugins.append(
265
+ 'CommonsChunkVendor',
266
+ new webpack.optimize.CommonsChunkPlugin({
267
+ name: 'vendor',
268
+ minChunks: (module) => {
269
+ // this assumes your vendor imports exist in the node_modules directory
270
+ return module.context && module.context.indexOf('node_modules') !== -1
271
+ }
272
+ })
273
+ )
274
+
275
+ environment.plugins.append(
276
+ 'CommonsChunkManifest',
277
+ new webpack.optimize.CommonsChunkPlugin({
278
+ name: 'manifest',
279
+ minChunks: Infinity
280
+ })
281
+ )
282
+ ```
283
+
284
+ Now, add these files to your `layouts/application.html.erb`:
285
+
286
+ ```erb
287
+ <%# Head %>
288
+
289
+ <%= javascript_pack_tag "manifest" %>
290
+ <%= javascript_pack_tag "vendor" %>
291
+
292
+ <%# If importing any styles from node_modules in your JS app %>
293
+
294
+ <%= stylesheet_pack_tag "vendor" %>
295
+ ```
296
+
297
+ More detailed guides available here: [webpack guides](https://webpack.js.org/guides/)
data/docs/yarn.md ADDED
@@ -0,0 +1,12 @@
1
+ # Yarn
2
+
3
+ Webpacker by default uses `yarn` as package manager for node modules
4
+
5
+
6
+ ## Add a new npm module
7
+
8
+ To add any new JS module you can use `yarn`:
9
+
10
+ ```bash
11
+ yarn add bootstrap material-ui
12
+ ```
data/exe/webpack ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV["JETS_ENV"] ||= ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4
+ ENV["NODE_ENV"] ||= ENV["JETS_ENV"]
5
+
6
+ require "webpacker"
7
+ require "webpacker/webpack_runner"
8
+ Webpacker::WebpackRunner.run(ARGV)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV["JETS_ENV"] ||= ENV["RAILS_ENV"] ||= ENV["RACK_ENV"] || "development"
4
+ ENV["NODE_ENV"] ||= ENV["JETS_ENV"]
5
+
6
+ require "webpacker"
7
+ require "webpacker/dev_server_runner"
8
+ Webpacker::DevServerRunner.run(ARGV)
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) { |repo| "https://github.com/#{repo}.git" }
4
+
5
+ gem "webpacker", path: ".."
6
+
7
+ gem "rails", github: "rails/rails"
8
+ gem "arel", github: "rails/arel"
9
+ gem "rake", ">= 11.1"
10
+ gem "rubocop", ">= 0.49", require: false
11
+ gem "rack-proxy", require: false
12
+ gem "minitest", "~> 5.0"
13
+ gem "byebug"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "webpacker", path: ".."
4
+
5
+ gem "rails", "~> 4.2"
6
+ gem "rake", ">= 11.1"
7
+ gem "rubocop", ">= 0.49", require: false
8
+ gem "rack-proxy", require: false
9
+ gem "minitest", "~> 5.0"
10
+ gem "byebug"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "webpacker", path: ".."
4
+
5
+ gem "rails", "~> 5.0"
6
+ gem "rake", ">= 11.1"
7
+ gem "rubocop", ">= 0.49", require: false
8
+ gem "rack-proxy", require: false
9
+ gem "minitest", "~> 5.0"
10
+ gem "byebug"
@@ -0,0 +1,10 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "webpacker", path: ".."
4
+
5
+ gem "rails", "~> 5.1"
6
+ gem "rake", ">= 11.1"
7
+ gem "rubocop", ">= 0.49", require: false
8
+ gem "rack-proxy", require: false
9
+ gem "minitest", "~> 5.0"
10
+ gem "byebug"
@@ -0,0 +1,27 @@
1
+ require "webpacker/configuration"
2
+
3
+ say "Copying angular loader to config/webpack/loaders"
4
+ copy_file "#{__dir__}/loaders/typescript.js", Jets.root.join("config/webpack/loaders/typescript.js").to_s
5
+
6
+ say "Adding typescript loader to config/webpack/environment.js"
7
+ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
8
+ "const typescript = require('./loaders/typescript')\n",
9
+ after: "require('@rails/webpacker')\n"
10
+
11
+ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
12
+ "environment.loaders.append('typescript', typescript)\n",
13
+ before: "module.exports"
14
+
15
+ say "Copying angular example entry file to #{Webpacker.config.source_entry_path}"
16
+ copy_file "#{__dir__}/examples/angular/hello_angular.js", "#{Webpacker.config.source_entry_path}/hello_angular.js"
17
+
18
+ say "Copying hello_angular app to #{Webpacker.config.source_path}"
19
+ directory "#{__dir__}/examples/angular/hello_angular", "#{Webpacker.config.source_path}/hello_angular"
20
+
21
+ say "Copying tsconfig.json to the Rails root directory for typescript"
22
+ copy_file "#{__dir__}/examples/angular/tsconfig.json", "tsconfig.json"
23
+
24
+ say "Installing all angular dependencies"
25
+ run "yarn add typescript ts-loader core-js zone.js rxjs @angular/core @angular/common @angular/compiler @angular/platform-browser @angular/platform-browser-dynamic"
26
+
27
+ say "Webpacker now supports angular and typescript 🎉", :green
@@ -0,0 +1,22 @@
1
+ require "webpacker/configuration"
2
+
3
+ say "Copying coffee loader to config/webpack/loaders"
4
+ copy_file "#{__dir__}/loaders/coffee.js", Jets.root.join("config/webpack/loaders/coffee.js").to_s
5
+
6
+ say "Adding coffee loader to config/webpack/environment.js"
7
+ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
8
+ "const coffee = require('./loaders/coffee')\n",
9
+ after: "require('@rails/webpacker')\n"
10
+
11
+ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
12
+ "environment.loaders.append('coffee', coffee)\n",
13
+ before: "module.exports"
14
+
15
+ say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
16
+ copy_file "#{__dir__}/examples/coffee/hello_coffee.coffee",
17
+ "#{Webpacker.config.source_entry_path}/hello_coffee.coffee"
18
+
19
+ say "Installing all Coffeescript dependencies"
20
+ run "yarn add coffeescript@1.12.7 coffee-loader"
21
+
22
+ say "Webpacker now supports Coffeeescript 🎉", :green
@@ -0,0 +1,18 @@
1
+ {
2
+ "presets": [
3
+ ["env", {
4
+ "modules": false,
5
+ "targets": {
6
+ "browsers": "> 1%",
7
+ "uglify": true
8
+ },
9
+ "useBuiltIns": true
10
+ }]
11
+ ],
12
+
13
+ "plugins": [
14
+ "syntax-dynamic-import",
15
+ "transform-object-rest-spread",
16
+ ["transform-class-properties", { "spec": true }]
17
+ ]
18
+ }