webpacker 3.1.1 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +77 -0
  3. data/Gemfile.lock +17 -18
  4. data/README.md +21 -0
  5. data/docs/css.md +8 -3
  6. data/docs/troubleshooting.md +18 -0
  7. data/docs/webpack.md +30 -3
  8. data/lib/install/angular.rb +12 -0
  9. data/lib/install/coffee.rb +22 -0
  10. data/lib/install/config/.postcssrc.yml +1 -1
  11. data/lib/install/elm.rb +12 -0
  12. data/lib/install/erb.rb +22 -0
  13. data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
  14. data/lib/install/examples/erb/hello_erb.js.erb +6 -0
  15. data/{package/rules → lib/install/loaders}/coffee.js +0 -0
  16. data/{package/rules → lib/install/loaders}/elm.js +0 -0
  17. data/{package/rules → lib/install/loaders}/erb.js +0 -0
  18. data/{package/rules → lib/install/loaders}/typescript.js +0 -0
  19. data/{package/rules → lib/install/loaders}/vue.js +1 -1
  20. data/lib/install/vue.rb +12 -0
  21. data/lib/tasks/installers.rake +3 -1
  22. data/lib/tasks/webpacker.rake +3 -1
  23. data/lib/tasks/webpacker/check_node.rake +2 -6
  24. data/lib/webpacker/compiler.rb +6 -1
  25. data/lib/webpacker/configuration.rb +8 -0
  26. data/lib/webpacker/helper.rb +14 -2
  27. data/lib/webpacker/version.rb +1 -1
  28. data/package.json +4 -10
  29. data/package/__tests__/environment.js +74 -0
  30. data/package/config.js +3 -0
  31. data/package/config_types/config_list.js +2 -0
  32. data/package/environment.js +6 -9
  33. data/package/environments/development.js +3 -4
  34. data/package/index.js +1 -2
  35. data/package/rules/file.js +1 -3
  36. data/package/rules/index.js +0 -12
  37. data/test/compiler_test.rb +11 -0
  38. data/test/configuration_test.rb +8 -0
  39. data/test/helper_test.rb +8 -0
  40. data/test/test_app/app/javascript/packs/application.js +10 -0
  41. data/test/test_app/config/webpacker.yml +65 -0
  42. data/test/test_helper.rb +1 -1
  43. data/yarn.lock +100 -188
  44. metadata +16 -9
  45. data/package/asset_host.js +0 -20
  46. data/package/rules/url.js +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 720fa717b75c3fe4a1729f826d54a80b502937fd
4
- data.tar.gz: 99d55971228f24ebe7cec9a9deda91d30d9d1c56
3
+ metadata.gz: b2f0cc346a219b0ec7cbf6e7a8742a5d2357e688
4
+ data.tar.gz: 22cfe110c400664e867746d12872f16c0aab2ea6
5
5
  SHA512:
6
- metadata.gz: 88e6dafb821268be55f60904f1c1fbf82b2bb445790232130a9921cef5d155f2d5598c650c3792711b989897de68bcddc86e429f4b6718cbb2f28db5578d3211
7
- data.tar.gz: 2ad1085b3937f9a27f1e352689a17fe2372e03baa97ecc4615aaafa3f93e919cf15ac620962b152a41c91efb45430d5fb5d07e51624bfcdeee41d269217f86dc
6
+ metadata.gz: be0bae989d22432883152e3623edd818cfbaf8845b539424cf9acc94c69e9a7aec0eda791f650cab2509e76ddf871c44db8bbe5dabda795ee44db3fd6ccf1197
7
+ data.tar.gz: 86f02ab54817cae201d65463d9b17d7966c427bec9f2763041a29691b4410e2c33fa7fb2dd2cd8375f111408ccc01b57e85820955fa7e6c9c72272a632dcd86f
data/CHANGELOG.md CHANGED
@@ -1,3 +1,80 @@
1
+ **Please note that Webpacker 3.1.0 and 3.1.1 has some serious bugs so please consider using either 3.0.2 or 3.2.0**
2
+
3
+ ## [3.2.0] - 2017-12-16
4
+
5
+ ### To upgrade:
6
+
7
+ ```bash
8
+ bundle update webpacker
9
+ yarn upgrade @rails/webpacker
10
+ ```
11
+
12
+ ### Breaking changes
13
+
14
+ If you are using react, vue, angular, elm, erb or coffeescript inside your
15
+ `packs/` please re-run the integration installers as described in the README.
16
+
17
+ ```bash
18
+ bundle exec rails webpacker:install:react
19
+ bundle exec rails webpacker:install:vue
20
+ bundle exec rails webpacker:install:angular
21
+ bundle exec rails webpacker:install:elm
22
+ bundle exec rails webpacker:install:erb
23
+ bundle exec rails webpacker:install::coffee
24
+ ```
25
+
26
+ Or simply copy required loaders used in your app from
27
+ https://github.com/rails/webpacker/tree/master/lib/install/loaders
28
+ into your `config/webpack/loaders/`
29
+ directory and add it to webpack build from `config/webpack/environment.js`
30
+
31
+ ```js
32
+ const erb = require('./loaders/erb')
33
+ const elm = require('./loaders/elm')
34
+ const typescript = require('./loaders/typescript')
35
+ const vue = require('./loaders/vue')
36
+ const coffee = require('./loaders/coffee')
37
+
38
+ environment.loaders.append('coffee', coffee)
39
+ environment.loaders.append('vue', vue)
40
+ environment.loaders.append('typescript', typescript)
41
+ environment.loaders.append('elm', elm)
42
+ environment.loaders.append('erb', erb)
43
+ ```
44
+
45
+ ### Added (npm module)
46
+
47
+ - Upgrade gems and webpack dependencies
48
+
49
+ - `postcss-import` in place of `postcss-smart-import`
50
+
51
+
52
+ ### Removed (npm module)
53
+
54
+ - `postcss-smart-import`, `coffee-loader`, `url-loader`, `rails-erb-loader` as dependencies
55
+
56
+ - `publicPath` from file loader [#1107](https://github.com/rails/webpacker/pull/1107)
57
+
58
+
59
+ ### Fixed (npm module)
60
+
61
+ - Return native array type for `ConfigList` [#1098](https://github.com/rails/webpacker/pull/1098)
62
+
63
+
64
+ ### Added (Gem)
65
+
66
+ - New `asset_pack_url` helper [#1102](https://github.com/rails/webpacker/pull/1102)
67
+
68
+ - New installers for coffee and erb
69
+
70
+ ```bash
71
+ bundle exec rails webpacker:install:erb
72
+ bundle exec rails webpacker:install::coffee
73
+ ```
74
+
75
+ - Resolved paths from webpacker.yml to compiler watched list
76
+
77
+
1
78
  ## [3.1.1] - 2017-12-11
2
79
 
3
80
  ### Fixed
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- webpacker (3.1.1)
4
+ webpacker (3.2.0)
5
5
  activesupport (>= 4.2)
6
6
  rack-proxy (>= 0.6.1)
7
7
  railties (>= 4.2)
@@ -51,33 +51,32 @@ GEM
51
51
  builder (3.2.3)
52
52
  byebug (9.1.0)
53
53
  concurrent-ruby (1.0.5)
54
- crass (1.0.2)
55
- erubi (1.6.1)
56
- globalid (0.4.0)
54
+ crass (1.0.3)
55
+ erubi (1.7.0)
56
+ globalid (0.4.1)
57
57
  activesupport (>= 4.2.0)
58
- i18n (0.8.6)
58
+ i18n (0.9.1)
59
+ concurrent-ruby (~> 1.0)
59
60
  loofah (2.1.1)
60
61
  crass (~> 1.0.2)
61
62
  nokogiri (>= 1.5.9)
62
- mail (2.6.6)
63
- mime-types (>= 1.16, < 4)
63
+ mail (2.7.0)
64
+ mini_mime (>= 0.1.1)
64
65
  method_source (0.9.0)
65
- mime-types (3.1)
66
- mime-types-data (~> 3.2015)
67
- mime-types-data (3.2016.0521)
66
+ mini_mime (1.0.0)
68
67
  mini_portile2 (2.3.0)
69
68
  minitest (5.10.3)
70
69
  nio4r (2.1.0)
71
70
  nokogiri (1.8.1)
72
71
  mini_portile2 (~> 2.3.0)
73
72
  parallel (1.12.0)
74
- parser (2.4.0.0)
75
- ast (~> 2.2)
73
+ parser (2.4.0.2)
74
+ ast (~> 2.3)
76
75
  powerpack (0.1.1)
77
76
  rack (2.0.3)
78
- rack-proxy (0.6.2)
77
+ rack-proxy (0.6.3)
79
78
  rack
80
- rack-test (0.7.0)
79
+ rack-test (0.8.2)
81
80
  rack (>= 1.0, < 3)
82
81
  rails (5.1.4)
83
82
  actioncable (= 5.1.4)
@@ -104,8 +103,8 @@ GEM
104
103
  thor (>= 0.18.1, < 2.0)
105
104
  rainbow (2.2.2)
106
105
  rake
107
- rake (12.1.0)
108
- rubocop (0.50.0)
106
+ rake (12.3.0)
107
+ rubocop (0.51.0)
109
108
  parallel (~> 1.10)
110
109
  parser (>= 2.3.3.1, < 3.0)
111
110
  powerpack (~> 0.1)
@@ -122,12 +121,12 @@ GEM
122
121
  sprockets (>= 3.0.0)
123
122
  thor (0.20.0)
124
123
  thread_safe (0.3.6)
125
- tzinfo (1.2.3)
124
+ tzinfo (1.2.4)
126
125
  thread_safe (~> 0.1)
127
126
  unicode-display_width (1.3.0)
128
127
  websocket-driver (0.6.5)
129
128
  websocket-extensions (>= 0.1.0)
130
- websocket-extensions (0.1.2)
129
+ websocket-extensions (0.1.3)
131
130
 
132
131
  PLATFORMS
133
132
  ruby
data/README.md CHANGED
@@ -30,6 +30,8 @@ in which case you may not even need the asset pipeline. This is mostly relevant
30
30
  - [Angular with TypeScript](#angular-with-typescript)
31
31
  - [Vue](#vue)
32
32
  - [Elm](#elm)
33
+ - [Coffeescript](#coffeescript)
34
+ - [Erb](#erb)
33
35
  - [Paths](#paths)
34
36
  - [Resolved](#resolved)
35
37
  - [Watched](#watched)
@@ -323,6 +325,25 @@ The Elm library and core packages will be added via Yarn and Elm itself.
323
325
  An example `Main.elm` app will also be added to your project in `app/javascript`
324
326
  so that you can experiment with Elm right away.
325
327
 
328
+ ### Coffeescript
329
+
330
+ To add [Coffeescript](http://coffeescript.org/) support,
331
+ run `bundle exec rails webpacker:install:coffee` on a Rails app already
332
+ setup with Webpacker.
333
+
334
+ An example `hello_coffee.coffee` file will also be added to your project
335
+ in `app/javascript/packs` so that you can experiment with Coffeescript right away.
336
+
337
+ ### Erb
338
+
339
+ To add [Erb](https://apidock.com/ruby/ERB) support in your JS templates,
340
+ run `bundle exec rails webpacker:install:erb` on a Rails app already
341
+ setup with Webpacker.
342
+
343
+ An example `hello_erb.js.erb` file will also be added to your project
344
+ in `app/javascript/packs` so that you can experiment with Erb flavoured
345
+ javascript right away.
346
+
326
347
 
327
348
  ## Paths
328
349
 
data/docs/css.md CHANGED
@@ -77,7 +77,7 @@ file in your app root with standard plugins.
77
77
 
78
78
  ```yml
79
79
  plugins:
80
- postcss-smart-import: {}
80
+ postcss-import: {}
81
81
  postcss-cssnext: {}
82
82
  ```
83
83
 
@@ -106,6 +106,11 @@ yarn add resolve-url-loader
106
106
  // webpack/environment.js
107
107
  const { environment } = require('@rails/webpacker')
108
108
 
109
- const sassLoader = environment.loaders.get('sass')
110
- sassLoader.use.push({ loader: 'resolve-url-loader' })
109
+ // resolve-url-loader must be used before sass-loader
110
+ environment.loaders.get('sass').use.splice(-1, 0, {
111
+ loader: 'resolve-url-loader',
112
+ options: {
113
+ attempts: 1
114
+ }
115
+ });
111
116
  ```
@@ -99,3 +99,21 @@ Rails.application.config.assets.js_compressor = :uglifier
99
99
  #Rails.application.config.assets.js_compressor = :uglifier
100
100
 
101
101
  ```
102
+
103
+ ### Angular: WARNING in ./node_modules/@angular/core/esm5/core.js, Critical dependency: the request of a dependency is an expression
104
+
105
+ To silent these warnings, please update `config/webpack/environment.js`
106
+
107
+ ```js
108
+ // environment.js
109
+ const webpack = require('webpack')
110
+ const { resolve } = require('path')
111
+ const { environment, config } = require('@rails/webpacker')
112
+
113
+ environment.plugins.set('ContextReplacement',
114
+ new webpack.ContextReplacementPlugin(
115
+ /angular(\\|\/)core(\\|\/)(@angular|esm5)/,
116
+ resolve(config.source_path)
117
+ )
118
+ )
119
+ ```
data/docs/webpack.md CHANGED
@@ -49,9 +49,9 @@ If you need access to configs within Webpacker's configuration,
49
49
  you can import them like so:
50
50
 
51
51
  ```js
52
- const { config, asset_host } = require('@rails/webpacker')
52
+ const { config } = require('@rails/webpacker')
53
53
 
54
- console.log(asset_host.publicPathWithHost)
54
+ console.log(config.output_path)
55
55
  console.log(config.source_path)
56
56
  ```
57
57
 
@@ -145,6 +145,33 @@ environment.loaders.insert('svg', {
145
145
  }, { before: 'file' })
146
146
  ```
147
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
+
148
175
  ### Overriding Loader Options in webpack 3+ (for CSS Modules etc.)
149
176
 
150
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:
@@ -159,7 +186,7 @@ const myCssLoaderOptions = {
159
186
  localIdentName: '[name]__[local]___[hash:base64:5]'
160
187
  }
161
188
 
162
- const CSSLoader = environment.loaders.get('style').use.find(el => el.loader === 'css-loader')
189
+ const CSSLoader = environment.loaders.get('sass').use.find(el => el.loader === 'css-loader')
163
190
 
164
191
  CSSLoader.options = merge(CSSLoader.options, myCssLoaderOptions)
165
192
 
@@ -1,5 +1,17 @@
1
1
  require "webpacker/configuration"
2
2
 
3
+ say "Copying angular loader to config/webpack/loaders"
4
+ copy_file "#{__dir__}/loaders/typescript.js", Rails.root.join("config/webpack/loaders/typescript.js").to_s
5
+
6
+ say "Adding typescript loader to config/webpack/environment.js"
7
+ insert_into_file Rails.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 Rails.root.join("config/webpack/environment.js").to_s,
12
+ "environment.loaders.append('typescript', typescript)\n",
13
+ before: "module.exports"
14
+
3
15
  say "Copying angular example entry file to #{Webpacker.config.source_entry_path}"
4
16
  copy_file "#{__dir__}/examples/angular/hello_angular.js", "#{Webpacker.config.source_entry_path}/hello_angular.js"
5
17
 
@@ -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", Rails.root.join("config/webpack/loaders/coffee.js").to_s
5
+
6
+ say "Adding coffee loader to config/webpack/environment.js"
7
+ insert_into_file Rails.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 Rails.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
@@ -1,3 +1,3 @@
1
1
  plugins:
2
- postcss-smart-import: {}
2
+ postcss-import: {}
3
3
  postcss-cssnext: {}
data/lib/install/elm.rb CHANGED
@@ -1,5 +1,17 @@
1
1
  require "webpacker/configuration"
2
2
 
3
+ say "Copying elm loader to config/webpack/loaders"
4
+ copy_file "#{__dir__}/loaders/elm.js", Rails.root.join("config/webpack/loaders/elm.js").to_s
5
+
6
+ say "Adding elm loader to config/webpack/environment.js"
7
+ insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
8
+ "const elm = require('./loaders/elm')\n",
9
+ after: "require('@rails/webpacker')\n"
10
+
11
+ insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
12
+ "environment.loaders.append('elm', elm)\n",
13
+ before: "module.exports"
14
+
3
15
  say "Copying Elm example entry file to #{Webpacker.config.source_entry_path}"
4
16
  copy_file "#{__dir__}/examples/elm/hello_elm.js",
5
17
  "#{Webpacker.config.source_entry_path}/hello_elm.js"
@@ -0,0 +1,22 @@
1
+ require "webpacker/configuration"
2
+
3
+ say "Copying vue loader to config/webpack/loaders"
4
+ copy_file "#{__dir__}/loaders/erb.js", Rails.root.join("config/webpack/loaders/erb.js").to_s
5
+
6
+ say "Adding erb loader to config/webpack/environment.js"
7
+ insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
8
+ "const erb = require('./loaders/erb')\n",
9
+ after: "require('@rails/webpacker')\n"
10
+
11
+ insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
12
+ "environment.loaders.append('erb', erb)\n",
13
+ before: "module.exports"
14
+
15
+ say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
16
+ copy_file "#{__dir__}/examples/erb/hello_erb.js.erb",
17
+ "#{Webpacker.config.source_entry_path}/hello_erb.js.erb"
18
+
19
+ say "Installing all Erb dependencies"
20
+ run "yarn add rails-erb-loader"
21
+
22
+ say "Webpacker now supports Erb in JS 🎉", :green
@@ -0,0 +1,4 @@
1
+ # Run this example by adding <%%= javascript_pack_tag 'hello_coffee' %> to the head of your layout file,
2
+ # like app/views/layouts/application.html.erb.
3
+
4
+ console.log 'Hello world from coffeescript'
@@ -0,0 +1,6 @@
1
+ // Run this example by adding <%%= javascript_pack_tag 'hello_erb' %> to the head of your layout file,
2
+ // like app/views/layouts/application.html.erb.
3
+
4
+ <% name = 'Erb' %>
5
+
6
+ console.log('Hello world from <%= name %>')
File without changes
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- const { dev_server: devServer } = require('../config')
1
+ const { dev_server: devServer } = require('@rails/webpacker').config
2
2
 
3
3
  const isProduction = process.env.NODE_ENV === 'production'
4
4
  const inDevServer = process.argv.find(v => v.includes('webpack-dev-server'))
data/lib/install/vue.rb CHANGED
@@ -1,5 +1,17 @@
1
1
  require "webpacker/configuration"
2
2
 
3
+ say "Copying vue loader to config/webpack/loaders"
4
+ copy_file "#{__dir__}/loaders/vue.js", Rails.root.join("config/webpack/loaders/vue.js").to_s
5
+
6
+ say "Adding vue loader to config/webpack/environment.js"
7
+ insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
8
+ "const vue = require('./loaders/vue')\n",
9
+ after: "require('@rails/webpacker')\n"
10
+
11
+ insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
12
+ "environment.loaders.append('vue', vue)\n",
13
+ before: "module.exports"
14
+
3
15
  say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
4
16
  copy_file "#{__dir__}/examples/vue/hello_vue.js",
5
17
  "#{Webpacker.config.source_entry_path}/hello_vue.js"