webpacker 4.0.2 → 4.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/docs/deployment.md CHANGED
@@ -83,3 +83,19 @@ Make sure you have `public/packs` and `node_modules` in `:linked_dirs`
83
83
  append :linked_dirs, "log", "tmp/pids", "tmp/cache", "tmp/sockets", "public/packs", ".bundle", "node_modules"
84
84
  ```
85
85
 
86
+ If you have `node_modules` added to `:linked_dirs` you'll need to run yarn install before `deploy:assets:precompile`, so you can add this code snippet at the bottom deploy.rb
87
+
88
+ ```ruby
89
+ before "deploy:assets:precompile", "deploy:yarn_install"
90
+ namespace :deploy do
91
+ desc "Run rake yarn install"
92
+ task :yarn_install do
93
+ on roles(:web) do
94
+ within release_path do
95
+ execute("cd #{release_path} && yarn install --silent --no-progress --no-audit --no-optional")
96
+ end
97
+ end
98
+ end
99
+ end
100
+ ```
101
+
data/docs/engines.md CHANGED
@@ -21,6 +21,8 @@ There is no built-in tasks to install Webpacker within the engine, thus you have
21
21
 
22
22
  ## Step 3: configure Webpacker instance.
23
23
 
24
+ - File `lib/my_engine.rb`
25
+
24
26
  ```ruby
25
27
  module MyEngine
26
28
  ROOT_PATH = Pathname.new(File.join(__dir__, ".."))
@@ -38,6 +40,8 @@ end
38
40
 
39
41
  ## Step 4: Configure dev server proxy.
40
42
 
43
+ - File `lib/my_engine/engine.rb`
44
+
41
45
  ```ruby
42
46
  module MyEngine
43
47
  class Engine < ::Rails::Engine
@@ -73,6 +77,8 @@ development:
73
77
 
74
78
  ## Step 5: configure helper.
75
79
 
80
+ - File `app/helpers/my_engine/application_helper.rb`
81
+
76
82
  ```ruby
77
83
  require "webpacker/helper"
78
84
 
@@ -93,6 +99,8 @@ Now you can use `stylesheet_pack_tag` and `javascript_pack_tag` from within your
93
99
 
94
100
  Add Rake task to compile assets in production (`rake my_engine:webpacker:compile`)
95
101
 
102
+ - File `lib/tasks/my_engine_tasks.rake`
103
+
96
104
  ```ruby
97
105
  namespace :my_engine do
98
106
  namespace :webpacker do
data/docs/es6.md CHANGED
@@ -16,13 +16,14 @@ Following ES6/7 features are supported out of the box:
16
16
  * Dynamic import() - useful for route level code-splitting
17
17
  * Class Fields and Static Properties.
18
18
 
19
- We have also included [babel polyfill](https://babeljs.io/docs/usage/polyfill/)
20
- that includes a custom regenerator runtime and core-js.
19
+ We have also included [core-js](https://github.com/zloirock/core-js) to polyfill features in the
20
+ older browsers.
21
21
 
22
- Don't forget to import `@babel/polyfill` in your main entry point like so:
22
+ Don't forget to add these lines into your main entry point:
23
23
 
24
24
  ```js
25
- import "@babel/polyfill"
25
+ import "core-js/stable";
26
+ import "regenerator-runtime/runtime";
26
27
  ```
27
28
 
28
29
 
@@ -1,5 +1,14 @@
1
1
  # Troubleshooting
2
2
 
3
+ ## Debugging your webpack config
4
+
5
+ 1. Read the error message carefully. The error message will tell you the precise key value
6
+ that is not matching what Webpack expects.
7
+ 2. Put a `debugger` statement in your Webpack configuration and run `bin/webpack --debug`.
8
+ If you have a node debugger installed, you'll see the Chrome debugger for your webpack
9
+ config. For example, install the Chrome extension [NiM](https://chrome.google.com/webstore/detail/nodejs-v8-inspector-manag/gnhhdgbaldcilmgcpfddgdbkhjohddkj) and
10
+ set the option for the dev tools to open automatically. For more details on debugging,
11
+ see the official [Webpack docs on debugging](https://webpack.js.org/contribute/debugging/#devtools)
3
12
 
4
13
  ## ENOENT: no such file or directory - node-sass
5
14
 
data/docs/v4-upgrade.md CHANGED
@@ -5,7 +5,7 @@ To update a Webpacker v3.5 app to v4, follow these steps:
5
5
 
6
6
  1. Update the `webpacker` gem and the `@rails/webpacker` package to v4. This will upgrade Webpack itself from 3.x to 4.x, make sure you're aware of [any deprecations which might effect you](https://webpack.js.org/migrate/4/). Also make sure any other packages you depend on support Webpack 4 and don't require any changes, e.g. if you explicitly include `webpack` you need to upgrade it to 4.x, and if you use `webpack-dev-server` you need to upgrade it to 3.x.
7
7
 
8
- 2. Browser support definitions have been moved to [`.browserslistrc`](../lib/install/config/.browserslistrc) to `/`.
8
+ 2. Browser support definitions have been moved from [`.browserslistrc`](../lib/install/config/.browserslistrc) to `/`.
9
9
 
10
10
  3. Merge any differences between [`config/webpacker.yml`](../lib/install/config/webpacker.yml) and your `config/webpacker.yml`.
11
11
 
@@ -104,7 +104,7 @@ If you want to keep the old behavior source maps can be disabled in any environm
104
104
  // config/webpack/production.js
105
105
 
106
106
  const environment = require('./environment')
107
- environment.config.merge({ devtool: 'none' })
107
+ environment.config.merge({ devtool: false })
108
108
 
109
109
  module.exports = environment.toWebpackConfig()
110
110
  ```
@@ -125,6 +125,16 @@ The compiled packs in the public directory are now stored under namespaces:
125
125
  "runtime~hello_react" => "/packs/js/runtime~hello_react-da2baf7fd07b0e8b6d17.js"
126
126
  ```
127
127
 
128
+ ## Upgrading projects with custom Webpack setups that use only the view helpers
129
+ The default value for `extract_css` is **false** in `config/webpack.yml`. Custom webpack builds that extract the CSS such as often used with [React on Rails](https://github.com/shakacode/react_on_rails) should set this value to true or else no CSS link tags are generated.
130
+
131
+ ```yml
132
+ default: &default
133
+ # other stuff
134
+ extract_css: true
135
+ # by default, extract and emit a css file. The default is false
136
+ ```
137
+
128
138
  ## Example Upgrades
129
139
 
130
140
  This is what an upgrade to Webpacker 4 looked like for existing Rails apps (please contribute yours!):
data/docs/webpack.md CHANGED
@@ -146,7 +146,7 @@ environment.loaders.insert('svg', {
146
146
  }
147
147
  }
148
148
  ])
149
- }, { after: 'file' })
149
+ }, { before: 'file' })
150
150
 
151
151
  const fileLoader = environment.loaders.get('file')
152
152
  fileLoader.exclude = /\.(svg)$/i
@@ -221,7 +221,7 @@ const webpack = require('webpack')
221
221
 
222
222
  // Get a pre-configured plugin
223
223
  const manifestPlugin = environment.plugins.get('Manifest')
224
- manifestPlugin.opts.writeToFileEmit = false
224
+ manifestPlugin.options.writeToFileEmit = false
225
225
 
226
226
  // Add an additional plugin of your choosing : ProvidePlugin
227
227
  environment.plugins.prepend(
@@ -261,7 +261,7 @@ environment.resolvedModules.append('vendor', 'vendor')
261
261
  ```
262
262
 
263
263
  ### Add SplitChunks (Webpack V4)
264
- Originally, chunks (and modules imported inside them) were connected by a parent-child relationship in the internal webpack graph. The CommonsChunkPlugin was used to avoid duplicated dependencies across them, but further optimizations were not possible
264
+ Originally, chunks (and modules imported inside them) were connected by a parent-child relationship in the internal webpack graph. The CommonsChunkPlugin was used to avoid duplicated dependencies across them, but further optimizations were not possible.
265
265
 
266
266
  Since webpack v4, the CommonsChunkPlugin was removed in favor of optimization.splitChunks.
267
267
 
@@ -269,7 +269,6 @@ For the full configuration options of SplitChunks, see the [Webpack documentatio
269
269
 
270
270
  ```js
271
271
  // config/webpack/environment.js
272
- const WebpackAssetsManifest = require('webpack-assets-manifest');
273
272
 
274
273
  // Enable the default config
275
274
  environment.splitChunks()
@@ -2,12 +2,11 @@ source "https://rubygems.org"
2
2
 
3
3
  git_source(:github) { |repo| "https://github.com/#{repo}.git" }
4
4
 
5
- gem "webpacker", path: ".."
5
+ gemspec path: "../"
6
6
 
7
7
  gem "rails", github: "rails/rails"
8
8
  gem "arel", github: "rails/arel"
9
9
  gem "rake", ">= 11.1"
10
- gem "rubocop", git: "https://github.com/rubocop-hq/rubocop.git", require: false
11
10
  gem "rack-proxy", require: false
12
11
  gem "minitest", "~> 5.0"
13
12
  gem "byebug"
@@ -1,10 +1,9 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "webpacker", path: ".."
3
+ gemspec path: "../"
4
4
 
5
5
  gem "rails", "~> 4.2.0"
6
6
  gem "rake", ">= 11.1"
7
- gem "rubocop", git: "https://github.com/rubocop-hq/rubocop.git", require: false
8
7
  gem "rack-proxy", require: false
9
8
  gem "minitest", "~> 5.0"
10
9
  gem "byebug"
@@ -1,10 +1,9 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "webpacker", path: ".."
3
+ gemspec path: "../"
4
4
 
5
5
  gem "rails", "~> 5.0.0"
6
6
  gem "rake", ">= 11.1"
7
- gem "rubocop", git: "https://github.com/rubocop-hq/rubocop.git", require: false
8
7
  gem "rack-proxy", require: false
9
8
  gem "minitest", "~> 5.0"
10
9
  gem "byebug"
@@ -1,10 +1,9 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "webpacker", path: ".."
3
+ gemspec path: "../"
4
4
 
5
5
  gem "rails", "~> 5.1.0"
6
6
  gem "rake", ">= 11.1"
7
- gem "rubocop", git: "https://github.com/rubocop-hq/rubocop.git", require: false
8
7
  gem "rack-proxy", require: false
9
8
  gem "minitest", "~> 5.0"
10
9
  gem "byebug"
@@ -1,10 +1,9 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem "webpacker", path: ".."
3
+ gemspec path: "../"
4
4
 
5
5
  gem "rails", "~> 5.2.0"
6
6
  gem "rake", ">= 11.1"
7
- gem "rubocop", git: "https://github.com/rubocop-hq/rubocop.git", require: false
8
7
  gem "rack-proxy", require: false
9
8
  gem "minitest", "~> 5.0"
10
9
  gem "byebug"
@@ -30,6 +30,7 @@ module.exports = function(api) {
30
30
  {
31
31
  forceAllTransforms: true,
32
32
  useBuiltIns: 'entry',
33
+ corejs: 3,
33
34
  modules: false,
34
35
  exclude: ['transform-typeof-symbol']
35
36
  }
@@ -56,7 +57,8 @@ module.exports = function(api) {
56
57
  require('@babel/plugin-transform-runtime').default,
57
58
  {
58
59
  helpers: false,
59
- regenerator: true
60
+ regenerator: true,
61
+ corejs: 3
60
62
  }
61
63
  ],
62
64
  [
@@ -52,7 +52,7 @@ development:
52
52
  <<: *default
53
53
  compile: true
54
54
 
55
- # Verifies that versions and hashed value of the package contents in the project's package.json
55
+ # Verifies that correct packages and versions are installed by inspecting package.json, yarn.lock, and node_modules
56
56
  check_yarn_integrity: true
57
57
 
58
58
  # Reference: https://webpack.js.org/configuration/dev-server/
data/lib/install/elm.rb CHANGED
@@ -24,13 +24,13 @@ say "Installing all Elm dependencies"
24
24
  run "yarn add elm elm-webpack-loader"
25
25
  run "yarn add --dev elm-hot-webpack-loader"
26
26
  run "yarn run elm init"
27
- run "yarn run elm make"
27
+ run "yarn run elm make #{Webpacker.config.source_path}/Main.elm"
28
28
 
29
29
  say "Updating webpack paths to include .elm file extension"
30
30
  insert_into_file Webpacker.config.config_path, "- .elm\n".indent(4), after: /\s+extensions:\n/
31
31
 
32
32
  say "Updating Elm source location"
33
- gsub_file "elm.json", /\"\src\"\n/,
33
+ gsub_file "elm.json", /\"src\"\n/,
34
34
  %("#{Webpacker.config.source_path.relative_path_from(Rails.root)}"\n)
35
35
 
36
36
  say "Updating .gitignore to include elm-stuff folder"
@@ -30,6 +30,7 @@ module.exports = function(api) {
30
30
  {
31
31
  forceAllTransforms: true,
32
32
  useBuiltIns: 'entry',
33
+ corejs: 3,
33
34
  modules: false,
34
35
  exclude: ['transform-typeof-symbol']
35
36
  }
@@ -9,11 +9,10 @@ import Vue from 'vue'
9
9
  import App from '../app.vue'
10
10
 
11
11
  document.addEventListener('DOMContentLoaded', () => {
12
- const el = document.body.appendChild(document.createElement('hello'))
13
12
  const app = new Vue({
14
- el,
15
13
  render: h => h(App)
16
- })
14
+ }).$mount()
15
+ document.body.appendChild(app.$el)
17
16
 
18
17
  console.log(app)
19
18
  })
@@ -40,9 +40,12 @@ namespace :webpacker do
40
40
  end
41
41
 
42
42
  # Compile packs after we've compiled all other assets during precompilation
43
- if Rake::Task.task_defined?("assets:precompile")
44
- skip_webpacker_precompile = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
45
- enhance_assets_precompile unless skip_webpacker_precompile
46
- else
47
- Rake::Task.define_task("assets:precompile" => ["webpacker:yarn_install", "webpacker:compile"])
43
+ skip_webpacker_precompile = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
44
+
45
+ unless skip_webpacker_precompile
46
+ if Rake::Task.task_defined?("assets:precompile")
47
+ enhance_assets_precompile
48
+ else
49
+ Rake::Task.define_task("assets:precompile" => ["webpacker:yarn_install", "webpacker:compile"])
50
+ end
48
51
  end
@@ -58,17 +58,21 @@ class Webpacker::Compiler
58
58
  def run_webpack
59
59
  logger.info "Compiling…"
60
60
 
61
- stdout, sterr , status = Open3.capture3(
61
+ stdout, stderr, status = Open3.capture3(
62
62
  webpack_env,
63
63
  "#{RbConfig.ruby} ./bin/webpack",
64
64
  chdir: File.expand_path(config.root_path)
65
65
  )
66
66
 
67
- if sterr == "" && status.success?
67
+ if status.success?
68
68
  logger.info "Compiled all packs in #{config.public_output_path}"
69
- logger.info stdout if config.webpack_compile_output?
69
+ logger.error "#{stderr}" unless stderr.empty?
70
70
  else
71
- logger.error "Compilation failed:\n#{sterr}\n#{stdout}"
71
+ logger.error "Compilation failed:\n#{stderr}"
72
+ end
73
+
74
+ if config.webpack_compile_output?
75
+ logger.info stdout
72
76
  end
73
77
 
74
78
  status.success?
@@ -51,6 +51,12 @@ module Webpacker
51
51
  else
52
52
  ["yarn", "webpack-dev-server"]
53
53
  end
54
+
55
+ if ARGV.include?("--debug")
56
+ cmd = [ "node", "--inspect-brk"] + cmd
57
+ ARGV.delete("--debug")
58
+ end
59
+
54
60
  cmd += ["--config", @webpack_config]
55
61
  cmd += ["--progress", "--color"] if @pretty
56
62
 
@@ -1,6 +1,6 @@
1
1
  module Webpacker::Helper
2
2
  # Returns current Webpacker instance.
3
- # Could be overriden to use multiple Webpacker
3
+ # Could be overridden to use multiple Webpacker
4
4
  # configurations within the same app (e.g. with engines)
5
5
  def current_webpacker_instance
6
6
  Webpacker.instance
@@ -1,4 +1,4 @@
1
1
  module Webpacker
2
2
  # Change the version in package.json too, please!
3
- VERSION = "4.0.2".freeze
3
+ VERSION = "4.0.3".freeze
4
4
  end
@@ -11,6 +11,12 @@ module Webpacker
11
11
  else
12
12
  ["yarn", "webpack"]
13
13
  end
14
+
15
+ if ARGV.include?("--debug")
16
+ cmd = [ "node", "--inspect-brk"] + cmd
17
+ ARGV.delete("--debug")
18
+ end
19
+
14
20
  cmd += ["--config", @webpack_config] + @argv
15
21
 
16
22
  Dir.chdir(@app_path) do
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rails/webpacker",
3
- "version": "4.0.2",
3
+ "version": "4.0.3",
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,53 @@
12
12
  "yarn": ">=1.0.0"
13
13
  },
14
14
  "dependencies": {
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",
15
+ "@babel/core": "^7.4.5",
16
+ "@babel/plugin-proposal-class-properties": "^7.4.4",
17
+ "@babel/plugin-proposal-object-rest-spread": "^7.4.4",
18
18
  "@babel/plugin-syntax-dynamic-import": "^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
- "@babel/polyfill": "^7.2.5",
23
- "@babel/preset-env": "^7.3.4",
24
- "@babel/runtime": "^7.3.4",
25
- "babel-loader": "^8.0.5",
19
+ "@babel/plugin-transform-destructuring": "^7.4.4",
20
+ "@babel/plugin-transform-regenerator": "^7.4.5",
21
+ "@babel/plugin-transform-runtime": "^7.4.4",
22
+ "@babel/preset-env": "^7.4.5",
23
+ "@babel/runtime": "^7.4.5",
24
+ "@babel/runtime-corejs3": "^7.4.5",
25
+ "babel-loader": "^8.0.6",
26
26
  "babel-plugin-dynamic-import-node": "^2.2.0",
27
27
  "babel-plugin-macros": "^2.5.0",
28
28
  "case-sensitive-paths-webpack-plugin": "^2.2.0",
29
29
  "compression-webpack-plugin": "^2.0.0",
30
- "css-loader": "^2.1.0",
30
+ "core-js": "^3.1.3",
31
+ "css-loader": "^2.1.1",
31
32
  "file-loader": "^3.0.1",
32
33
  "flatted": "^2.0.0",
33
- "glob": "^7.1.3",
34
- "js-yaml": "^3.12.2",
35
- "mini-css-extract-plugin": "^0.5.0",
36
- "node-sass": "^4.11.0",
34
+ "glob": "^7.1.4",
35
+ "js-yaml": "^3.13.1",
36
+ "mini-css-extract-plugin": "^0.7.0",
37
+ "node-sass": "^4.12.0",
37
38
  "optimize-css-assets-webpack-plugin": "^5.0.1",
38
39
  "path-complete-extname": "^1.0.0",
39
- "pnp-webpack-plugin": "^1.3.1",
40
+ "pnp-webpack-plugin": "^1.4.3",
40
41
  "postcss-flexbugs-fixes": "^4.1.0",
41
42
  "postcss-import": "^12.0.1",
42
43
  "postcss-loader": "^3.0.0",
43
44
  "postcss-preset-env": "^6.6.0",
44
45
  "postcss-safe-parser": "^4.0.1",
46
+ "regenerator-runtime": "^0.13.2",
45
47
  "sass-loader": "^7.1.0",
46
48
  "style-loader": "^0.23.1",
47
- "terser-webpack-plugin": "^1.2.3",
48
- "webpack": "^4.29.6",
49
+ "terser-webpack-plugin": "^1.3.0",
50
+ "webpack": "^4.32.2",
49
51
  "webpack-assets-manifest": "^3.1.1",
50
- "webpack-cli": "^3.2.3",
52
+ "webpack-cli": "^3.3.2",
51
53
  "webpack-sources": "^1.3.0"
52
54
  },
53
55
  "devDependencies": {
54
- "eslint": "^5.15.0",
56
+ "eslint": "^5.16.0",
55
57
  "eslint-config-airbnb": "^17.1.0",
56
- "eslint-plugin-import": "^2.16.0",
58
+ "eslint-plugin-import": "^2.17.3",
57
59
  "eslint-plugin-jsx-a11y": "^6.2.1",
58
- "eslint-plugin-react": "^7.12.4",
59
- "jest": "^24.1.0"
60
+ "eslint-plugin-react": "^7.13.0",
61
+ "jest": "^24.8.0"
60
62
  },
61
63
  "jest": {
62
64
  "testRegex": "(/__tests__/.*|(\\.|/))\\.jsx?$",