webpacker 2.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -0
  3. data/.rubocop.yml +21 -21
  4. data/CHANGELOG.md +107 -4
  5. data/Gemfile +3 -1
  6. data/Gemfile.lock +15 -8
  7. data/README.md +137 -937
  8. data/docs/assets.md +106 -0
  9. data/docs/css.md +82 -0
  10. data/docs/deployment.md +39 -0
  11. data/docs/env.md +62 -0
  12. data/docs/es6.md +53 -0
  13. data/docs/folder-structure.md +66 -0
  14. data/docs/misc.md +23 -0
  15. data/docs/props.md +105 -0
  16. data/docs/testing.md +45 -0
  17. data/docs/troubleshooting.md +65 -0
  18. data/docs/typescript.md +115 -0
  19. data/docs/webpack-dev-server.md +32 -0
  20. data/docs/webpack.md +108 -0
  21. data/docs/yarn.md +12 -0
  22. data/lib/install/angular.rb +4 -7
  23. data/lib/install/bin/webpack-dev-server.tt +35 -11
  24. data/lib/install/bin/webpack.tt +3 -4
  25. data/lib/install/config/.babelrc +1 -0
  26. data/lib/install/config/.postcssrc.yml +1 -2
  27. data/lib/install/config/webpack/development.js +2 -31
  28. data/lib/install/config/webpack/environment.js +3 -0
  29. data/lib/install/config/webpack/production.js +2 -34
  30. data/lib/install/config/webpack/test.js +2 -5
  31. data/lib/install/config/webpacker.yml +20 -2
  32. data/lib/install/elm.rb +6 -11
  33. data/lib/install/examples/vue/hello_vue.js +31 -2
  34. data/lib/install/react.rb +2 -5
  35. data/lib/install/template.rb +3 -8
  36. data/lib/install/vue.rb +4 -7
  37. data/lib/tasks/webpacker.rake +1 -1
  38. data/lib/tasks/webpacker/{check_webpack_binstubs.rake → check_binstubs.rake} +3 -2
  39. data/lib/tasks/webpacker/check_node.rake +8 -6
  40. data/lib/tasks/webpacker/check_yarn.rake +2 -2
  41. data/lib/tasks/webpacker/clobber.rake +2 -3
  42. data/lib/tasks/webpacker/compile.rake +16 -18
  43. data/lib/tasks/webpacker/verify_install.rake +5 -5
  44. data/lib/tasks/webpacker/yarn_install.rake +1 -1
  45. data/lib/webpacker.rb +15 -11
  46. data/lib/webpacker/commands.rb +22 -0
  47. data/lib/webpacker/compiler.rb +66 -10
  48. data/lib/webpacker/configuration.rb +54 -38
  49. data/lib/webpacker/dev_server.rb +47 -0
  50. data/lib/webpacker/dev_server_proxy.rb +24 -0
  51. data/lib/webpacker/helper.rb +23 -5
  52. data/lib/webpacker/instance.rb +44 -0
  53. data/lib/webpacker/manifest.rb +58 -34
  54. data/lib/webpacker/railtie.rb +22 -3
  55. data/lib/webpacker/version.rb +2 -1
  56. data/package.json +37 -7
  57. data/package/asset_host.js +21 -0
  58. data/package/config.js +8 -0
  59. data/package/environment.js +95 -0
  60. data/package/environments/development.js +47 -0
  61. data/package/environments/production.js +34 -0
  62. data/package/environments/test.js +3 -0
  63. data/package/index.js +16 -0
  64. data/package/loaders/babel.js +11 -0
  65. data/{lib/install/config/loaders/core → package/loaders}/coffee.js +0 -0
  66. data/{lib/install/config/loaders/installers → package/loaders}/elm.js +4 -5
  67. data/{lib/install/config/loaders/core → package/loaders}/erb.js +0 -0
  68. data/package/loaders/file.js +15 -0
  69. data/package/loaders/style.js +31 -0
  70. data/{lib/install/config/loaders/installers/angular.js → package/loaders/typescript.js} +1 -1
  71. data/package/loaders/vue.js +12 -0
  72. data/test/compiler_test.rb +20 -0
  73. data/test/configuration_test.rb +43 -19
  74. data/test/dev_server_test.rb +24 -0
  75. data/test/helper_test.rb +21 -5
  76. data/test/manifest_test.rb +25 -19
  77. data/test/test_app/public/packs/manifest.json +3 -1
  78. data/test/webpacker_test_helper.rb +40 -0
  79. data/webpacker.gemspec +1 -1
  80. data/yarn.lock +4701 -578
  81. metadata +52 -29
  82. data/lib/install/config/loaders/core/assets.js +0 -12
  83. data/lib/install/config/loaders/core/babel.js +0 -5
  84. data/lib/install/config/loaders/core/sass.js +0 -15
  85. data/lib/install/config/loaders/installers/react.js +0 -5
  86. data/lib/install/config/loaders/installers/vue.js +0 -13
  87. data/lib/install/config/webpack/configuration.js +0 -35
  88. data/lib/install/config/webpack/shared.js +0 -58
  89. data/lib/webpacker/env.rb +0 -23
  90. data/lib/webpacker/file_loader.rb +0 -24
  91. data/test/env_test.rb +0 -14
  92. data/test/webpacker_test.rb +0 -15
@@ -2,7 +2,6 @@
2
2
  $stdout.sync = true
3
3
 
4
4
  require "shellwords"
5
- require "yaml"
6
5
 
7
6
  ENV["RAILS_ENV"] ||= "development"
8
7
  RAILS_ENV = ENV["RAILS_ENV"]
@@ -20,9 +19,9 @@ unless File.exist?(WEBPACK_CONFIG)
20
19
  exit!
21
20
  end
22
21
 
23
- newenv = { "NODE_PATH" => NODE_MODULES_PATH.shellescape }
24
- cmdline = ["yarn", "run", "webpack", "--", "--config", WEBPACK_CONFIG] + ARGV
22
+ env = { "NODE_PATH" => NODE_MODULES_PATH.shellescape }
23
+ cmd = [ "#{NODE_MODULES_PATH}/.bin/webpack", "--config", WEBPACK_CONFIG ] + ARGV
25
24
 
26
25
  Dir.chdir(APP_PATH) do
27
- exec newenv, *cmdline
26
+ exec env, *cmd
28
27
  end
@@ -12,6 +12,7 @@
12
12
 
13
13
  "plugins": [
14
14
  "syntax-dynamic-import",
15
+ "transform-object-rest-spread",
15
16
  ["transform-class-properties", { "spec": true }]
16
17
  ]
17
18
  }
@@ -1,4 +1,3 @@
1
1
  plugins:
2
2
  postcss-smart-import: {}
3
- precss: {}
4
- autoprefixer: {}
3
+ postcss-cssnext: {}
@@ -1,32 +1,3 @@
1
- // Note: You must restart bin/webpack-dev-server for changes to take effect
1
+ const environment = require('./environment')
2
2
 
3
- const merge = require('webpack-merge')
4
- const sharedConfig = require('./shared.js')
5
- const { settings, output } = require('./configuration.js')
6
-
7
- module.exports = merge(sharedConfig, {
8
- devtool: 'cheap-eval-source-map',
9
-
10
- stats: {
11
- errorDetails: true
12
- },
13
-
14
- output: {
15
- pathinfo: true
16
- },
17
-
18
- devServer: {
19
- clientLogLevel: 'none',
20
- https: settings.dev_server.https,
21
- host: settings.dev_server.host,
22
- port: settings.dev_server.port,
23
- contentBase: output.path,
24
- publicPath: output.publicPath,
25
- compress: true,
26
- headers: { 'Access-Control-Allow-Origin': '*' },
27
- historyApiFallback: true,
28
- watchOptions: {
29
- ignored: /node_modules/
30
- }
31
- }
32
- })
3
+ module.exports = environment.toWebpackConfig()
@@ -0,0 +1,3 @@
1
+ const { environment } = require('@rails/webpacker')
2
+
3
+ module.exports = environment
@@ -1,35 +1,3 @@
1
- // Note: You must restart bin/webpack-dev-server for changes to take effect
1
+ const environment = require('./environment')
2
2
 
3
- /* eslint global-require: 0 */
4
-
5
- const webpack = require('webpack')
6
- const merge = require('webpack-merge')
7
- const CompressionPlugin = require('compression-webpack-plugin')
8
- const sharedConfig = require('./shared.js')
9
-
10
- module.exports = merge(sharedConfig, {
11
- output: { filename: '[name]-[chunkhash].js' },
12
- devtool: 'source-map',
13
- stats: 'normal',
14
-
15
- plugins: [
16
- new webpack.optimize.UglifyJsPlugin({
17
- minimize: true,
18
- sourceMap: true,
19
-
20
- compress: {
21
- warnings: false
22
- },
23
-
24
- output: {
25
- comments: false
26
- }
27
- }),
28
-
29
- new CompressionPlugin({
30
- asset: '[path].gz[query]',
31
- algorithm: 'gzip',
32
- test: /\.(js|css|html|json|ico|svg|eot|otf|ttf)$/
33
- })
34
- ]
35
- })
3
+ module.exports = environment.toWebpackConfig()
@@ -1,6 +1,3 @@
1
- // Note: You must restart bin/webpack-dev-server for changes to take effect
1
+ const environment = require('./environment')
2
2
 
3
- const merge = require('webpack-merge')
4
- const sharedConfig = require('./shared.js')
5
-
6
- module.exports = merge(sharedConfig, {})
3
+ module.exports = environment.toWebpackConfig()
@@ -4,6 +4,14 @@ default: &default
4
4
  source_path: app/javascript
5
5
  source_entry_path: packs
6
6
  public_output_path: packs
7
+ cache_path: tmp/cache/webpacker
8
+
9
+ # Additional paths webpack should lookup modules
10
+ # ['app/assets', 'engine/foo/app/assets']
11
+ resolved_paths: []
12
+
13
+ # Reload manifest.json on all requests so we reload latest compiled packs
14
+ cache_manifest: false
7
15
 
8
16
  extensions:
9
17
  - .coffee
@@ -23,16 +31,26 @@ default: &default
23
31
 
24
32
  development:
25
33
  <<: *default
34
+ compile: true
26
35
 
27
36
  dev_server:
28
- host: 0.0.0.0
29
- port: 8080
37
+ host: localhost
38
+ port: 3035
39
+ hmr: false
30
40
  https: false
31
41
 
32
42
  test:
33
43
  <<: *default
44
+ compile: true
34
45
 
46
+ # Compile test packs to a separate directory
35
47
  public_output_path: packs-test
36
48
 
37
49
  production:
38
50
  <<: *default
51
+
52
+ # Production demands on precompilation of packs prior to booting for performance.
53
+ compile: false
54
+
55
+ # Cache manifest.json for performance
56
+ cache_manifest: true
data/lib/install/elm.rb CHANGED
@@ -1,15 +1,11 @@
1
1
  require "webpacker/configuration"
2
2
 
3
- puts "Copying elm loader to config/webpack/loaders"
4
- copy_file "#{__dir__}/config/loaders/installers/elm.js",
5
- "config/webpack/loaders/elm.js"
3
+ puts "Copying elm example entry file to #{Webpacker.config.source_entry_path}"
4
+ copy_file "#{__dir__}/examples/elm/Main.elm", "#{Webpacker.config.source_entry_path}/Main.elm"
6
5
 
7
- puts "Copying elm example entry file to #{Webpacker::Configuration.entry_path}"
8
- copy_file "#{__dir__}/examples/elm/Main.elm", "#{Webpacker::Configuration.entry_path}/Main.elm"
9
-
10
- puts "Copying elm app file to #{Webpacker::Configuration.entry_path}"
6
+ puts "Copying elm app file to #{Webpacker.config.source_entry_path}"
11
7
  copy_file "#{__dir__}/examples/elm/hello_elm.js",
12
- "#{Webpacker::Configuration.entry_path}/hello_elm.js"
8
+ "#{Webpacker.config.source_entry_path}/hello_elm.js"
13
9
 
14
10
  puts "Installing all elm dependencies"
15
11
  run "yarn add elm elm-webpack-loader"
@@ -17,11 +13,10 @@ run "yarn add --dev elm-hot-loader"
17
13
  run "yarn run elm package install -- --yes"
18
14
 
19
15
  puts "Updating Webpack paths to include Elm file extension"
20
- insert_into_file Webpacker::Configuration.file_path, " - .elm\n", after: /extensions:\n/
16
+ insert_into_file Webpacker.config.config_path, " - .elm\n", after: /extensions:\n/
21
17
 
22
18
  puts "Updating elm source location"
23
- source_path = File.join(Webpacker::Configuration.source, Webpacker::Configuration.fetch(:source_entry_path))
24
- gsub_file "elm-package.json", /\"\.\"\n/, %("#{source_path}"\n)
19
+ gsub_file "elm-package.json", /\"\.\"\n/, %("#{Webpacker.config.source_entry_path}"\n)
25
20
 
26
21
  puts "Updating .gitignore to include elm-stuff folder"
27
22
  insert_into_file ".gitignore", "/elm-stuff\n", before: "/node_modules\n"
@@ -1,6 +1,7 @@
1
1
  /* eslint no-console: 0 */
2
- // Run this example by adding <%= javascript_pack_tag 'hello_vue' %> and
3
- // <%= stylesheet_pack_tag 'hello_vue' %> to the head of your layout file,
2
+ // Run this example by adding <%= javascript_pack_tag 'hello_vue' %> (and
3
+ // <%= stylesheet_pack_tag 'hello_vue' %> if you set extractStyles to true
4
+ // in config/webpack/loaders/vue.js) to the head of your layout file,
4
5
  // like app/views/layouts/application.html.erb.
5
6
  // All it does is render <div>Hello Vue</div> at the bottom of the page.
6
7
 
@@ -13,3 +14,31 @@ document.addEventListener('DOMContentLoaded', () => {
13
14
 
14
15
  console.log(app)
15
16
  })
17
+
18
+
19
+ // The above code uses Vue without the compiler, which means you cannot
20
+ // use Vue to target elements in your existing html templates. You would
21
+ // need to always use single file components.
22
+ // To be able to target elements in your existing html/erb templates,
23
+ // comment out the above code and uncomment the below
24
+ // Add <%= javascript_pack_tag 'hello_vue' %> to your layout
25
+ // Then add this markup to your html template:
26
+ //
27
+ // <div id='hello'>
28
+ // {{message}}
29
+ // <app></app>
30
+ // </div>
31
+
32
+
33
+ // import Vue from 'vue/dist/vue.esm'
34
+ // import App from './app.vue'
35
+ //
36
+ // document.addEventListener('DOMContentLoaded', () => {
37
+ // const app = new Vue({
38
+ // el: '#hello',
39
+ // data: {
40
+ // message: "Can you say hello?"
41
+ // },
42
+ // components: { App }
43
+ // })
44
+ // })
data/lib/install/react.rb CHANGED
@@ -19,11 +19,8 @@ else
19
19
  copy_file "#{__dir__}/examples/react/.babelrc", ".babelrc"
20
20
  end
21
21
 
22
- puts "Copying react loader to config/webpack/loaders"
23
- copy_file "#{__dir__}/config/loaders/installers/react.js", "config/webpack/loaders/react.js"
24
-
25
- puts "Copying react example entry file to #{Webpacker::Configuration.entry_path}"
26
- copy_file "#{__dir__}/examples/react/hello_react.jsx", "#{Webpacker::Configuration.entry_path}/hello_react.jsx"
22
+ puts "Copying react example entry file to #{Webpacker.config.source_entry_path}"
23
+ copy_file "#{__dir__}/examples/react/hello_react.jsx", "#{Webpacker.config.source_entry_path}/hello_react.jsx"
27
24
 
28
25
  puts "Installing all react dependencies"
29
26
  run "yarn add react react-dom babel-preset-react prop-types"
@@ -3,7 +3,6 @@ copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
3
3
 
4
4
  puts "Copying webpack core config and loaders"
5
5
  directory "#{__dir__}/config/webpack", "config/webpack"
6
- directory "#{__dir__}/config/loaders/core", "config/webpack/loaders"
7
6
 
8
7
  puts "Copying .postcssrc.yml to app root directory"
9
8
  copy_file "#{__dir__}/config/.postcssrc.yml", ".postcssrc.yml"
@@ -12,7 +11,7 @@ puts "Copying .babelrc to app root directory"
12
11
  copy_file "#{__dir__}/config/.babelrc", ".babelrc"
13
12
 
14
13
  puts "Creating javascript app source directory"
15
- directory "#{__dir__}/javascript", "#{Webpacker::Configuration.source}"
14
+ directory "#{__dir__}/javascript", Webpacker.config.source_path
16
15
 
17
16
  puts "Copying binstubs"
18
17
  directory "#{__dir__}/bin", "bin"
@@ -22,17 +21,13 @@ chmod "bin", 0755 & ~File.umask, verbose: false
22
21
  if File.exists?(".gitignore")
23
22
  append_to_file ".gitignore", <<-EOS
24
23
  /public/packs
24
+ /public/packs-test
25
25
  /node_modules
26
26
  EOS
27
27
  end
28
28
 
29
29
  puts "Installing all JavaScript dependencies"
30
- run "yarn add webpack webpack-merge js-yaml path-complete-extname " \
31
- "webpack-manifest-plugin babel-loader@7.x coffee-loader coffee-script " \
32
- "babel-core babel-preset-env babel-polyfill compression-webpack-plugin rails-erb-loader glob " \
33
- "extract-text-webpack-plugin node-sass file-loader sass-loader css-loader style-loader " \
34
- "postcss-loader autoprefixer postcss-smart-import precss resolve-url-loader " \
35
- "babel-plugin-syntax-dynamic-import babel-plugin-transform-class-properties"
30
+ run "yarn add @rails/webpacker"
36
31
 
37
32
  puts "Installing dev server for live reloading"
38
33
  run "yarn add --dev webpack-dev-server"
data/lib/install/vue.rb CHANGED
@@ -1,13 +1,10 @@
1
1
  require "webpacker/configuration"
2
2
 
3
- puts "Copying vue loader to config/webpack/loaders"
4
- copy_file "#{__dir__}/config/loaders/installers/vue.js", "config/webpack/loaders/vue.js"
3
+ puts "Copying the example entry file to #{Webpacker.config.source_entry_path}"
4
+ copy_file "#{__dir__}/examples/vue/hello_vue.js", "#{Webpacker.config.source_entry_path}/hello_vue.js"
5
5
 
6
- puts "Copying the example entry file to #{Webpacker::Configuration.entry_path}"
7
- copy_file "#{__dir__}/examples/vue/hello_vue.js", "#{Webpacker::Configuration.entry_path}/hello_vue.js"
8
-
9
- puts "Copying vue app file to #{Webpacker::Configuration.entry_path}"
10
- copy_file "#{__dir__}/examples/vue/app.vue", "#{Webpacker::Configuration.entry_path}/app.vue"
6
+ puts "Copying vue app file to #{Webpacker.config.source_entry_path}"
7
+ copy_file "#{__dir__}/examples/vue/app.vue", "#{Webpacker.config.source_entry_path}/app.vue"
11
8
 
12
9
  puts "Installing all vue dependencies"
13
10
  run "yarn add vue vue-loader vue-template-compiler"
@@ -3,7 +3,7 @@ tasks = {
3
3
  "webpacker:compile" => "Compiles webpack bundles based on environment",
4
4
  "webpacker:check_node" => "Verifies if Node.js is installed",
5
5
  "webpacker:check_yarn" => "Verifies if yarn is installed",
6
- "webpacker:check_webpack_binstubs" => "Verifies that bin/webpack & bin/webpack-dev-server are present",
6
+ "webpacker:check_binstubs" => "Verifies that bin/webpack & bin/webpack-dev-server are present",
7
7
  "webpacker:verify_install" => "Verifies if webpacker is installed",
8
8
  "webpacker:yarn_install" => "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn",
9
9
  "webpacker:install:react" => "Installs and setup example React component",
@@ -1,8 +1,9 @@
1
1
  namespace :webpacker do
2
2
  desc "Verifies that bin/webpack & bin/webpack-dev-server are present."
3
- task :check_webpack_binstubs do
3
+ task :check_binstubs do
4
4
  unless File.exist?("bin/webpack") && File.exist?("bin/webpack-dev-server")
5
- puts "Webpack binstubs not found.\n"\
5
+ $stderr.puts "Webpack binstubs not found.\n"\
6
+ "Have you run rails webpacker:install ?\n"\
6
7
  "Make sure the bin directory or binstubs are not included in .gitignore\n"\
7
8
  "Exiting!"
8
9
  exit!
@@ -3,17 +3,19 @@ namespace :webpacker do
3
3
  task :check_node do
4
4
  begin
5
5
  node_version = `node -v`
6
- required_node_version = "6.4"
6
+ node_version = `nodejs -v` if node_version.blank?
7
+ required_node_version = "6.0"
7
8
 
8
9
  raise Errno::ENOENT if node_version.blank?
10
+
9
11
  if Gem::Version.new(node_version.strip.tr("v", "")) < Gem::Version.new(required_node_version)
10
- puts "Webpacker requires Node.js >= v#{required_node_version} and you are using #{node_version}"
11
- puts "Please upgrade Node.js https://nodejs.org/en/download/"
12
- puts "Exiting!" && exit!
12
+ $stderr.puts "Webpacker requires Node.js >= v#{required_node_version} and you are using #{node_version}"
13
+ $stderr.puts "Please upgrade Node.js https://nodejs.org/en/download/"
14
+ $stderr.puts "Exiting!" && exit!
13
15
  end
14
16
  rescue Errno::ENOENT
15
- puts "Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/"
16
- puts "Exiting!" && exit!
17
+ $stderr.puts "Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/"
18
+ $stderr.puts "Exiting!" && exit!
17
19
  end
18
20
  end
19
21
  end
@@ -8,8 +8,8 @@ namespace :webpacker do
8
8
 
9
9
  raise Errno::ENOENT if yarn_version.blank? || Gem::Version.new(yarn_version) < Gem::Version.new(required_yarn_version)
10
10
  rescue Errno::ENOENT
11
- puts "Webpacker requires Yarn version >= #{required_yarn_version}. Please download and install the latest version from https://yarnpkg.com/lang/en/docs/install/"
12
- puts "Exiting!" && exit!
11
+ $stderr.puts "Webpacker requires Yarn version >= #{required_yarn_version}. Please download and install the latest version from https://yarnpkg.com/lang/en/docs/install/"
12
+ $stderr.puts "Exiting!" && exit!
13
13
  end
14
14
  end
15
15
  end
@@ -3,9 +3,8 @@ require "webpacker/configuration"
3
3
  namespace :webpacker do
4
4
  desc "Remove the webpack compiled output directory"
5
5
  task clobber: ["webpacker:verify_install", :environment] do
6
- output_path = Webpacker::Configuration.output_path
7
- FileUtils.rm_r(output_path) if File.exist?(output_path)
8
- puts "Removed webpack output path directory #{output_path}"
6
+ Webpacker.clobber
7
+ $stdout.puts "Removed webpack output path directory #{Webpacker.config.public_output_path}"
9
8
  end
10
9
  end
11
10
 
@@ -1,25 +1,23 @@
1
- require "open3"
2
- require "webpacker/env"
3
- require "webpacker/configuration"
1
+ $stdout.sync = true
2
+
3
+ def ensure_log_goes_to_stdout
4
+ old_logger = Webpacker.logger
5
+ Webpacker.logger = ActiveSupport::Logger.new(STDOUT)
6
+ yield
7
+ ensure
8
+ Webpacker.logger = old_logger
9
+ end
4
10
 
5
11
  namespace :webpacker do
6
12
  desc "Compile javascript packs using webpack for production with digests"
7
13
  task compile: ["webpacker:verify_install", :environment] do
8
- puts "[Webpacker] Compiling assets 🎉"
9
-
10
- asset_host = ActionController::Base.helpers.compute_asset_host
11
- env = { "NODE_ENV" => Webpacker.env, "ASSET_HOST" => asset_host }.freeze
12
-
13
- stdout_str, stderr_str, status = Open3.capture3(env, "./bin/webpack")
14
-
15
- if status.success?
16
- $stdout.puts "\e[32m[Webpacker] Compiled digests for all packs in #{Webpacker::Configuration.entry_path}:\e[0m"
17
- $stdout.puts "\e[32m#{JSON.parse(File.read(Webpacker::Configuration.manifest_path))}\e[0m"
18
- else
19
- $stdout.puts "[Webpacker] Compilation Failed"
20
- $stdout.puts "\e[31m#{stdout_str}\e[0m"
21
- $stderr.puts "\e[31m#{stderr_str}\e[0m"
22
- exit!
14
+ ensure_log_goes_to_stdout do
15
+ if Webpacker.compile
16
+ # Successful compilation!
17
+ else
18
+ # Failed compilation
19
+ exit!
20
+ end
23
21
  end
24
22
  end
25
23
  end
@@ -2,12 +2,12 @@ require "webpacker/configuration"
2
2
 
3
3
  namespace :webpacker do
4
4
  desc "Verifies if webpacker is installed"
5
- task verify_install: [:check_node, :check_yarn, :check_webpack_binstubs] do
6
- if File.exist?(Webpacker::Configuration.file_path)
7
- puts "Webpacker is installed 🎉 🍰"
8
- puts "Using #{Webpacker::Configuration.file_path} file for setting up webpack paths"
5
+ task verify_install: [:check_node, :check_yarn, :check_binstubs] do
6
+ if Webpacker.config.config_path.exist?
7
+ $stdout.puts "Webpacker is installed 🎉 🍰"
8
+ $stdout.puts "Using #{Webpacker.config.config_path} file for setting up webpack paths"
9
9
  else
10
- puts "Configuration config/webpacker.yml file not found. \n"\
10
+ $stderr.puts "Configuration config/webpacker.yml file not found. \n"\
11
11
  "Make sure webpacker:install is run successfully before " \
12
12
  "running dependent tasks"
13
13
  exit!