webpacker 4.0.0.rc.7 → 4.0.0.rc.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e149e93bb4665ea4065b508fa03374660c831a66c7ed1b25796c1a76cf8e8625
4
- data.tar.gz: 5aa0549de2a179d32a026622b2df83a4bc1fb99ecef421d89fa2207635fe7f2c
3
+ metadata.gz: aaad344f0471e623fde0e00f3444f63f08b2347fa50171309dd20d429dc3e680
4
+ data.tar.gz: 21a1b84e25560f25565ee2670ae0654c74fb8a7ef48ecf953ffb245ceff77b08
5
5
  SHA512:
6
- metadata.gz: 3ff2f4807b9ec0266de861bc5a58d2a2f9c5bbcfe5380ae3b0fdb11cddbb265c52cebe155cc5e41be467edd39e3f9bf4c8414bafc94255b4990e2528210dd033
7
- data.tar.gz: 7b6499cb15ba9f5b98ed4ac65f472817f8d0be7abf3ef5ed12b589f13261fb0395503b125c0fb30f1090b599e92de4590e874fa9dd13983a13b107a1023f471f
6
+ metadata.gz: 34e2f71eea35056a09af3b285e43747bf273722f5cbabc4b5643bed6d4a53cba0ed9fa25f7397a864325a1147748b1365ddab433b04a16b2289a7ac9b050c50d
7
+ data.tar.gz: 0ecb39cbc1e5c98d2095c7b4066ef097e4b60f057f065d3f1add3f76a36074d2f40449ecc695dc44c8f9ee71c7b9c2181e27636a4ca35a557d7dec05cb0f1962
data/CHANGELOG.md CHANGED
@@ -1,5 +1,49 @@
1
1
  **Please note that Webpacker 3.1.0 and 3.1.1 have some serious bugs so please consider using either 3.0.2 or 3.2.0**
2
2
 
3
+ ## [4.0.0.rc.8] - 2019-03-03
4
+
5
+ ### Fixed
6
+
7
+ - Re-enable source maps in production to make debugging in production
8
+ easier. Enabling source maps doesn't have drawbacks for most of the
9
+ applications since maps are compressed by default and aren't loaded
10
+ by browsers unless Dev Tools are opened.
11
+
12
+ Source maps can be disabled in any environment configuration, e.g:
13
+
14
+ ```js
15
+ // config/webpack/production.js
16
+
17
+ const environment = require('./environment')
18
+ environment.config.merge({ devtool: 'none' })
19
+
20
+ module.exports = environment.toWebpackConfig()
21
+ ```
22
+
23
+ - Reintroduced `context` to the file loader. Reverting the simpler paths change
24
+
25
+ - Updated file loader to have filename based on the path. This change
26
+ keeps the old behaviour intact i.e. let people use namespaces for media
27
+ inside `app/javascript` and also include media outside of `app/javascript`
28
+ with simpler paths, for example from `node_modules` or `app/assets`
29
+
30
+ ```bash
31
+ # Files inside app/javascript (i.e. packs source path)
32
+ # media/[full_path_relative_to_app_javascript]/name_of_the_asset_with_digest
33
+ media/images/google-97e897b3851e415bec4fd30c265eb3ce.jpg
34
+ media/images/rails-45b116b1f66cc5e6f9724e8f9a2db73d.png
35
+ media/images/some_namespace/google-97e897b3851e415bec4fd30c265eb3ce.jpg
36
+
37
+ # Files outside app/javascript (i.e. packs source path)
38
+ # media/[containing_folder_name]/name_of_the_asset_with_digest
39
+ media/some_assets/rails_assets-f0f7bbb5.png
40
+ media/webfonts/fa-brands-400-4b115e11.woff2
41
+ ```
42
+
43
+ This change is done so we don't end up paths like `media/_/assets/images/rails_assets-f0f7bbb5ef00110a0dcef7c2cb7d34a6.png` or `media/_/_/node_modules/foo-f0f7bbb5ef00110a0dcef7c2cb7d34a6.png` for media outside of
44
+ `app/javascript`
45
+
46
+
3
47
  ## [4.0.0.rc.7] - 2019-01-25
4
48
 
5
49
  ### Fixed
@@ -21,6 +65,19 @@
21
65
  "media/avatar.png": "/packs/media/avatar-057862c747f0fdbeae506bdd0516cad1.png"
22
66
  ```
23
67
 
68
+ To get old behaviour:
69
+
70
+ ```js
71
+ // config/webpack/environment.js
72
+
73
+ const { environment, config } = require('@rails/webpacker')
74
+ const { join } = require('path')
75
+
76
+ const fileLoader = environment.loaders.get('file')
77
+ fileLoader.use[0].options.name = '[path][name]-[hash].[ext]'
78
+ fileLoader.use[0].options.context = join(config.source_path) // optional if you don't want to expose full paths
79
+ ```
80
+
24
81
  ### Added
25
82
 
26
83
  - Namespaces for compiled packs in the public directory
@@ -119,7 +176,14 @@ helper otherwise you will get duplicated chunks on the page.
119
176
  extract_css: true
120
177
  ```
121
178
  - Separate rule to compile node modules
122
- (fixes cases where ES6 libraries were included in the app code) [#1823](https://github.com/rails/webpacker/pull/1823)
179
+ (fixes cases where ES6 libraries were included in the app code) [#1823](https://github.com/rails/webpacker/pull/1823).
180
+
181
+ In previous versions only application code was transpiled. Now everything in `node_modules` transpiled with Babel. In some cases it could break your build (known issue with `mapbox-gl` package being broken by Babel, https://github.com/mapbox/mapbox-gl-js/issues/3422).
182
+
183
+ [`nodeModules` loader](https://github.com/rails/webpacker/pull/1823/files#diff-456094c8451b5774db50028dfecf4aa8) ignores `config.babel.js` and uses hard-coded `'@babel/preset-env', { modules: false }` config.
184
+
185
+ To keep previous behavior, remove `nodeModules` loader specifying `environment.loaders.delete('nodeModules');` in your `config/webpack/environment.js` file.
186
+
123
187
  - File loader extensions API [#1823](https://github.com/rails/webpacker/pull/1823)
124
188
  ```yml
125
189
  # webpacker.yml
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  GIT
2
2
  remote: https://github.com/rubocop-hq/rubocop.git
3
- revision: 19d65afe162a5c095d81fd69982c1308fbbf9b46
3
+ revision: dc69686abf10d9f38ed3a39037fab76ae8874138
4
4
  specs:
5
- rubocop (0.63.0)
5
+ rubocop (0.65.0)
6
6
  jaro_winkler (~> 1.5.1)
7
7
  parallel (~> 1.10)
8
8
  parser (>= 2.5, != 2.5.1.1)
9
9
  powerpack (~> 0.1)
10
+ psych (>= 3.1.0)
10
11
  rainbow (>= 2.2.2, < 4.0)
11
12
  ruby-progressbar (~> 1.7)
12
13
  unicode-display_width (~> 1.4.0)
@@ -14,7 +15,7 @@ GIT
14
15
  PATH
15
16
  remote: .
16
17
  specs:
17
- webpacker (4.0.0.rc.7)
18
+ webpacker (4.0.0.rc.8)
18
19
  activesupport (>= 4.2)
19
20
  rack-proxy (>= 0.6.1)
20
21
  railties (>= 4.2)
@@ -66,13 +67,13 @@ GEM
66
67
  arel (9.0.0)
67
68
  ast (2.4.0)
68
69
  builder (3.2.3)
69
- byebug (10.0.2)
70
+ byebug (11.0.0)
70
71
  concurrent-ruby (1.1.4)
71
72
  crass (1.0.4)
72
73
  erubi (1.8.0)
73
74
  globalid (0.4.2)
74
75
  activesupport (>= 4.2.0)
75
- i18n (1.5.2)
76
+ i18n (1.5.3)
76
77
  concurrent-ruby (~> 1.0)
77
78
  jaro_winkler (1.5.2)
78
79
  loofah (2.2.3)
@@ -90,10 +91,11 @@ GEM
90
91
  nio4r (2.3.1)
91
92
  nokogiri (1.10.1)
92
93
  mini_portile2 (~> 2.4.0)
93
- parallel (1.13.0)
94
+ parallel (1.14.0)
94
95
  parser (2.6.0.0)
95
96
  ast (~> 2.4.0)
96
97
  powerpack (0.1.2)
98
+ psych (3.1.0)
97
99
  rack (2.0.6)
98
100
  rack-proxy (0.6.5)
99
101
  rack
data/docs/assets.md CHANGED
@@ -61,7 +61,7 @@ Specify the plugin in your `babel.config.js` with the custom root or alias. Here
61
61
  ```js
62
62
  {
63
63
  plugins: [
64
- [require("module-resolver").default, {
64
+ [require("babel-plugin-module-resolver").default, {
65
65
  "root": ["./app"],
66
66
  "alias": {
67
67
  "assets": "./assets"
data/docs/v4-upgrade.md CHANGED
@@ -87,6 +87,21 @@ nodeModulesLoader.exclude.push(/some-library/) // replace `some-library` with
87
87
  // the actual path to exclude
88
88
  ```
89
89
 
90
+ ### Source Maps are enabled by default
91
+
92
+ Source maps are now enabled in production to make debugging in production easier. Enabling source maps doesn't have drawbacks for most of the applications since maps are compressed by default and aren't loaded by browsers unless Dev Tools are opened.
93
+
94
+ If you want to keep the old behavior source maps can be disabled in any environment configuration, e.g:
95
+
96
+ ```js
97
+ // config/webpack/production.js
98
+
99
+ const environment = require('./environment')
100
+ environment.config.merge({ devtool: 'none' })
101
+
102
+ module.exports = environment.toWebpackConfig()
103
+ ```
104
+
90
105
  ### Example upgrades
91
106
 
92
107
  This is what an upgrade to Webpacker 4 looked like for existing Rails apps (please contribute yours!):
data/docs/webpack.md CHANGED
@@ -38,6 +38,7 @@ environment.config.set('output.filename', '[name].js')
38
38
 
39
39
  // Merge custom config
40
40
  environment.config.merge(customConfig)
41
+ environment.config.merge({ devtool: 'none' })
41
42
 
42
43
  // Delete a property
43
44
  environment.config.delete('output.chunkFilename')
@@ -68,10 +69,13 @@ yarn add json-loader
68
69
  // config/webpack/environment.js
69
70
  const { environment } = require('@rails/webpacker')
70
71
 
71
- environment.loaders.append('json', {
72
+ const jsonLoader = {
72
73
  test: /\.json$/,
73
74
  use: 'json-loader'
74
- })
75
+ }
76
+
77
+ // Insert json loader at the end of list
78
+ environment.loaders.append('json', jsonLoader)
75
79
 
76
80
  // Insert json loader at the top of list
77
81
  environment.loaders.prepend('json', jsonLoader)
@@ -1 +1 @@
1
- > 1%
1
+ defaults
@@ -7,4 +7,12 @@
7
7
  // To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
8
8
  // layout file, like app/views/layouts/application.html.erb
9
9
 
10
+
11
+ // Uncomment to copy all static images under ../images to the output folder and reference
12
+ // them with the image_pack_tag helper in views (e.g <%= image_pack_tag 'rails.png' %>)
13
+ // or the `imagePath` JavaScript helper below.
14
+ //
15
+ // const images = require.context('../images', true)
16
+ // const imagePath = (name) => images(name, true)
17
+
10
18
  console.log('Hello World from Webpacker')
@@ -23,14 +23,15 @@ end
23
23
  apply "#{__dir__}/binstubs.rb"
24
24
 
25
25
  if File.exists?(".gitignore")
26
- append_to_file ".gitignore", <<-EOS
27
- /public/packs
28
- /public/packs-test
29
- /node_modules
30
- /yarn-error.log
31
- yarn-debug.log*
32
- .yarn-integrity
33
- EOS
26
+ append_to_file ".gitignore" do
27
+ "\n" +
28
+ "/public/packs\n" +
29
+ "/public/packs-test\n" +
30
+ "/node_modules\n" +
31
+ "/yarn-error.log\n" +
32
+ "yarn-debug.log*\n" +
33
+ ".yarn-integrity\n"
34
+ end
34
35
  end
35
36
 
36
37
  if Webpacker::VERSION == /^[0-9]+\.[0-9]+\.[0-9]+$/
@@ -8,9 +8,16 @@ ensure
8
8
  Webpacker.logger = old_logger
9
9
  end
10
10
 
11
+ def yarn_install_available?
12
+ rails_major = Rails::VERSION::MAJOR
13
+ rails_minor = Rails::VERSION::MINOR
14
+
15
+ rails_major > 5 || (rails_major == 5 && rails_minor >= 1)
16
+ end
17
+
11
18
  def enhance_assets_precompile
12
- # For Rails < 5.1
13
- deps = Rake::Task.task_defined?("yarn:install") ? [] : ["webpacker:yarn_install"]
19
+ # yarn:install was added in Rails 5.1
20
+ deps = yarn_install_available? ? [] : ["webpacker:yarn_install"]
14
21
  Rake::Task["assets:precompile"].enhance(deps) do
15
22
  Rake::Task["webpacker:compile"].invoke
16
23
  end
@@ -90,7 +90,7 @@ class Webpacker::Compiler
90
90
  def webpack_env
91
91
  return env unless defined?(ActionController::Base)
92
92
 
93
- env.merge("WEBPACKER_ASSET_HOST" => ActionController::Base.helpers.compute_asset_host,
94
- "WEBPACKER_RELATIVE_URL_ROOT" => ActionController::Base.relative_url_root)
93
+ env.merge("WEBPACKER_ASSET_HOST" => ENV.fetch("WEBPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host),
94
+ "WEBPACKER_RELATIVE_URL_ROOT" => ENV.fetch("WEBPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root))
95
95
  end
96
96
  end
@@ -47,7 +47,7 @@ module Webpacker::Helper
47
47
  # <%= image_pack_tag 'application.png', size: '16x10', alt: 'Edit Entry' %>
48
48
  # <img alt='Edit Entry' src='/packs/application-k344a6d59eef8632c9d1.png' width='16' height='10' />
49
49
  def image_pack_tag(name, **options)
50
- image_tag(asset_path(current_webpacker_instance.manifest.lookup!(name)), **options)
50
+ image_tag(resolve_path_to_image(name), **options)
51
51
  end
52
52
 
53
53
  # Creates a script tag that references the named pack file, as compiled by webpack per the entries list
@@ -140,4 +140,11 @@ module Webpacker::Helper
140
140
  def sources_from_manifest_entrypoints(names, type:)
141
141
  names.map { |name| current_webpacker_instance.manifest.lookup_pack_with_chunks!(name, type: type) }.flatten.uniq
142
142
  end
143
+
144
+ def resolve_path_to_image(name)
145
+ path = name.starts_with?("media/images/") ? name : "media/images/#{name}"
146
+ asset_path(current_webpacker_instance.manifest.lookup!(path))
147
+ rescue
148
+ asset_path(current_webpacker_instance.manifest.lookup!(name))
149
+ end
143
150
  end
@@ -1,4 +1,4 @@
1
1
  module Webpacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "4.0.0.rc.7".freeze
3
+ VERSION = "4.0.0.rc.8".freeze
4
4
  end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rails/webpacker",
3
- "version": "4.0.0-rc.7",
3
+ "version": "4.0.0-rc.8",
4
4
  "description": "Use webpack to manage app-like JavaScript modules in Rails",
5
5
  "main": "package/index.js",
6
6
  "files": [
@@ -12,51 +12,51 @@
12
12
  "yarn": ">=1.0.0"
13
13
  },
14
14
  "dependencies": {
15
- "@babel/core": "^7.2.2",
16
- "@babel/plugin-proposal-class-properties": "^7.2.3",
17
- "@babel/plugin-proposal-object-rest-spread": "^7.2.0",
15
+ "@babel/core": "^7.3.4",
16
+ "@babel/plugin-proposal-class-properties": "^7.3.4",
17
+ "@babel/plugin-proposal-object-rest-spread": "^7.3.4",
18
18
  "@babel/plugin-syntax-dynamic-import": "^7.2.0",
19
- "@babel/plugin-transform-destructuring": "^7.2.0",
20
- "@babel/plugin-transform-regenerator": "^7.0.0",
21
- "@babel/plugin-transform-runtime": "^7.2.0",
19
+ "@babel/plugin-transform-destructuring": "^7.3.2",
20
+ "@babel/plugin-transform-regenerator": "^7.3.4",
21
+ "@babel/plugin-transform-runtime": "^7.3.4",
22
22
  "@babel/polyfill": "^7.2.5",
23
- "@babel/preset-env": "^7.2.3",
24
- "@babel/runtime": "^7.2.0",
23
+ "@babel/preset-env": "^7.3.4",
24
+ "@babel/runtime": "^7.3.4",
25
25
  "babel-loader": "^8.0.5",
26
26
  "babel-plugin-dynamic-import-node": "^2.2.0",
27
- "babel-plugin-macros": "^2.4.5",
28
- "case-sensitive-paths-webpack-plugin": "^2.1.2",
27
+ "babel-plugin-macros": "^2.5.0",
28
+ "case-sensitive-paths-webpack-plugin": "^2.2.0",
29
29
  "compression-webpack-plugin": "^2.0.0",
30
30
  "css-loader": "^2.1.0",
31
31
  "file-loader": "^3.0.1",
32
32
  "flatted": "^2.0.0",
33
33
  "glob": "^7.1.3",
34
- "js-yaml": "^3.12.1",
34
+ "js-yaml": "^3.12.2",
35
35
  "mini-css-extract-plugin": "^0.5.0",
36
36
  "node-sass": "^4.11.0",
37
37
  "optimize-css-assets-webpack-plugin": "^5.0.1",
38
38
  "path-complete-extname": "^1.0.0",
39
- "pnp-webpack-plugin": "^1.2.1",
39
+ "pnp-webpack-plugin": "^1.3.1",
40
40
  "postcss-flexbugs-fixes": "^4.1.0",
41
41
  "postcss-import": "^12.0.1",
42
42
  "postcss-loader": "^3.0.0",
43
- "postcss-preset-env": "^6.5.0",
43
+ "postcss-preset-env": "^6.6.0",
44
44
  "postcss-safe-parser": "^4.0.1",
45
45
  "sass-loader": "^7.1.0",
46
46
  "style-loader": "^0.23.1",
47
- "terser-webpack-plugin": "^1.2.1",
48
- "webpack": "^4.29.0",
47
+ "terser-webpack-plugin": "^1.2.3",
48
+ "webpack": "^4.29.6",
49
49
  "webpack-assets-manifest": "^3.1.1",
50
- "webpack-cli": "^3.2.1",
50
+ "webpack-cli": "^3.2.3",
51
51
  "webpack-sources": "^1.3.0"
52
52
  },
53
53
  "devDependencies": {
54
- "eslint": "^5.12.1",
54
+ "eslint": "^5.15.0",
55
55
  "eslint-config-airbnb": "^17.1.0",
56
- "eslint-plugin-import": "^2.14.0",
57
- "eslint-plugin-jsx-a11y": "^6.1.2",
56
+ "eslint-plugin-import": "^2.16.0",
57
+ "eslint-plugin-jsx-a11y": "^6.2.1",
58
58
  "eslint-plugin-react": "^7.12.4",
59
- "jest": "^23.6.0"
59
+ "jest": "^24.1.0"
60
60
  },
61
61
  "jest": {
62
62
  "testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",
@@ -63,4 +63,16 @@ describe('Config', () => {
63
63
  '.jpg'
64
64
  ])
65
65
  })
66
+
67
+ test('should return static assets extensions as listed in app config', () => {
68
+ expect(config.static_assets_extensions).toEqual([
69
+ '.jpg',
70
+ '.jpeg',
71
+ '.png',
72
+ '.gif',
73
+ '.tiff',
74
+ '.ico',
75
+ '.svg',
76
+ ])
77
+ })
66
78
  })
@@ -22,7 +22,7 @@ describe('DevServer', () => {
22
22
 
23
23
  test('with custom env prefix', () => {
24
24
  const config = require('../config')
25
- config.dev_server.env_prefix = 'TEST_WEBPACKER_DEV_SERVER_'
25
+ config.dev_server.env_prefix = 'TEST_WEBPACKER_DEV_SERVER'
26
26
 
27
27
  process.env.NODE_ENV = 'development'
28
28
  process.env.RAILS_ENV = 'development'
@@ -21,7 +21,7 @@ describe('Production environment', () => {
21
21
  expect(config.output.path).toEqual(resolve('public', 'packs'))
22
22
  expect(config.output.publicPath).toEqual('/packs/')
23
23
  expect(config).toMatchObject({
24
- devtool: 'nosources-source-map',
24
+ devtool: 'source-map',
25
25
  stats: 'normal'
26
26
  })
27
27
  })
@@ -21,7 +21,7 @@ describe('Custom environment', () => {
21
21
  expect(config.output.path).toEqual(resolve('public', 'packs-staging'))
22
22
  expect(config.output.publicPath).toEqual('/packs-staging/')
23
23
  expect(config).toMatchObject({
24
- devtool: 'nosources-source-map',
24
+ devtool: 'source-map',
25
25
  stats: 'normal'
26
26
  })
27
27
  })
data/package/config.js CHANGED
@@ -17,6 +17,9 @@ const defaults = getDefaultConfig()
17
17
  const app = safeLoad(readFileSync(configPath), 'utf8')[railsEnv]
18
18
 
19
19
  if (isArray(app.extensions) && app.extensions.length) delete defaults.extensions
20
+ if (isArray(app.static_assets_extensions) && app.static_assets_extensions.length) {
21
+ delete defaults.static_assets_extensions
22
+ }
20
23
 
21
24
  const config = deepMerge(defaults, app)
22
25
  config.outputPath = resolve(config.public_root_path, config.public_output_path)
@@ -37,5 +40,6 @@ const getPublicPath = () => {
37
40
  }
38
41
 
39
42
  config.publicPath = getPublicPath()
43
+ config.publicPathWithoutCDN = `/${config.public_output_path}/`
40
44
 
41
45
  module.exports = config