webpacker 5.0.1 → 6.0.0.pre.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +8 -8
- data/.github/workflows/jest.yml +38 -0
- data/.github/workflows/js-lint.yml +39 -0
- data/.github/workflows/rubocop.yml +39 -0
- data/.github/workflows/ruby.yml +70 -0
- data/.gitignore +2 -0
- data/.node-version +1 -1
- data/.rubocop.yml +11 -16
- data/CHANGELOG.md +33 -1
- data/CONTRIBUTING.md +1 -1
- data/Gemfile.lock +91 -85
- data/README.md +27 -44
- data/docs/assets.md +21 -5
- data/docs/css.md +80 -30
- data/docs/deployment.md +18 -0
- data/docs/docker.md +2 -2
- data/docs/engines.md +1 -1
- data/docs/env.md +4 -1
- data/docs/es6.md +1 -1
- data/docs/integrations.md +2 -2
- data/docs/props.md +2 -38
- data/docs/react.md +183 -0
- data/docs/target.md +22 -0
- data/docs/testing.md +13 -3
- data/docs/troubleshooting.md +3 -1
- data/docs/typescript.md +92 -27
- data/docs/webpack-dev-server.md +17 -15
- data/docs/webpack.md +58 -107
- data/lib/install/config/webpack/base.js +3 -0
- data/lib/install/config/webpack/development.js +2 -2
- data/lib/install/config/webpack/production.js +2 -2
- data/lib/install/config/webpack/test.js +2 -2
- data/lib/install/config/webpacker.yml +9 -42
- data/lib/install/examples/{vue → vue3}/app.vue +10 -5
- data/lib/install/examples/vue3/hello_vue.js +15 -0
- data/lib/install/javascript/packs/application.css +9 -0
- data/lib/install/template.rb +33 -19
- data/lib/tasks/webpacker.rake +2 -11
- data/lib/tasks/webpacker/binstubs.rake +6 -4
- data/lib/tasks/webpacker/check_binstubs.rake +4 -4
- data/lib/tasks/webpacker/check_node.rake +1 -1
- data/lib/tasks/webpacker/check_yarn.rake +2 -3
- data/lib/tasks/webpacker/compile.rake +4 -2
- data/lib/tasks/webpacker/info.rake +12 -10
- data/lib/tasks/webpacker/install.rake +6 -4
- data/lib/tasks/webpacker/verify_install.rake +2 -1
- data/lib/tasks/webpacker/yarn_install.rake +9 -1
- data/lib/webpacker/commands.rb +1 -1
- data/lib/webpacker/compiler.rb +14 -9
- data/lib/webpacker/configuration.rb +7 -27
- data/lib/webpacker/dev_server_proxy.rb +3 -1
- data/lib/webpacker/dev_server_runner.rb +23 -4
- data/lib/webpacker/helper.rb +55 -46
- data/lib/webpacker/manifest.rb +1 -1
- data/lib/webpacker/railtie.rb +0 -43
- data/lib/webpacker/runner.rb +1 -0
- data/lib/webpacker/version.rb +1 -1
- data/lib/webpacker/webpack_runner.rb +7 -2
- data/package.json +27 -43
- data/package/__tests__/config.js +6 -27
- data/package/__tests__/dev_server.js +2 -0
- data/package/__tests__/development.js +18 -7
- data/package/__tests__/env.js +12 -4
- data/package/__tests__/production.js +6 -6
- data/package/__tests__/staging.js +7 -6
- data/package/__tests__/test.js +4 -5
- data/package/babel/preset-react.js +62 -0
- data/package/babel/preset.js +44 -0
- data/package/config.js +4 -9
- data/package/configPath.js +3 -0
- data/package/dev_server.js +1 -1
- data/package/env.js +9 -4
- data/package/environments/__tests__/base.js +21 -36
- data/package/environments/base.js +67 -128
- data/package/environments/development.js +46 -39
- data/package/environments/production.js +69 -67
- data/package/environments/test.js +2 -2
- data/package/index.js +6 -6
- data/package/rules/babel.js +20 -11
- data/package/rules/coffee.js +6 -0
- data/package/rules/erb.js +13 -0
- data/package/rules/file.js +19 -18
- data/package/rules/index.js +24 -18
- data/package/rules/less.js +18 -0
- data/package/rules/sass.js +6 -7
- data/package/rules/svg.js +23 -0
- data/package/utils/get_style_rule.js +22 -28
- data/package/utils/helpers.js +3 -35
- data/test/compiler_test.rb +4 -11
- data/test/configuration_test.rb +2 -32
- data/test/dev_server_runner_test.rb +25 -6
- data/test/engine_rake_tasks_test.rb +39 -0
- data/test/helper_test.rb +18 -9
- data/test/mounted_app/Rakefile +4 -0
- data/test/mounted_app/test/dummy/Rakefile +3 -0
- data/test/mounted_app/test/dummy/bin/rails +3 -0
- data/test/mounted_app/test/dummy/bin/rake +3 -0
- data/test/mounted_app/test/dummy/config.ru +5 -0
- data/test/mounted_app/test/dummy/config/application.rb +10 -0
- data/test/mounted_app/test/dummy/config/environment.rb +3 -0
- data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
- data/test/mounted_app/test/dummy/package.json +7 -0
- data/test/rake_tasks_test.rb +1 -10
- data/test/test_app/config/application.rb +0 -1
- data/test/test_app/config/webpacker.yml +3 -21
- data/test/test_app/config/webpacker_public_root.yml +0 -1
- data/test/test_app/public/packs/manifest.json +18 -13
- data/test/test_app/some.config.js +0 -0
- data/test/webpack_runner_test.rb +10 -4
- data/webpacker.gemspec +1 -1
- data/yarn.lock +2657 -6224
- metadata +53 -71
- data/.travis.yml +0 -43
- data/lib/install/angular.rb +0 -23
- data/lib/install/coffee.rb +0 -25
- data/lib/install/config/.browserslistrc +0 -1
- data/lib/install/config/babel.config.js +0 -72
- data/lib/install/config/postcss.config.js +0 -12
- data/lib/install/config/webpack/environment.js +0 -3
- data/lib/install/elm.rb +0 -39
- data/lib/install/erb.rb +0 -25
- data/lib/install/examples/angular/hello_angular.js +0 -7
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
- data/lib/install/examples/angular/hello_angular/index.ts +0 -8
- data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
- data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
- data/lib/install/examples/elm/Main.elm +0 -55
- data/lib/install/examples/elm/hello_elm.js +0 -16
- data/lib/install/examples/erb/hello_erb.js.erb +0 -6
- data/lib/install/examples/react/babel.config.js +0 -87
- data/lib/install/examples/react/hello_react.jsx +0 -26
- data/lib/install/examples/react/tsconfig.json +0 -20
- data/lib/install/examples/stimulus/application.js +0 -1
- data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
- data/lib/install/examples/stimulus/controllers/index.js +0 -9
- data/lib/install/examples/svelte/app.svelte +0 -11
- data/lib/install/examples/svelte/hello_svelte.js +0 -20
- data/lib/install/examples/typescript/hello_typescript.ts +0 -4
- data/lib/install/examples/typescript/tsconfig.json +0 -23
- data/lib/install/examples/vue/hello_vue.js +0 -72
- data/lib/install/loaders/coffee.js +0 -6
- data/lib/install/loaders/elm.js +0 -25
- data/lib/install/loaders/erb.js +0 -11
- data/lib/install/loaders/svelte.js +0 -9
- data/lib/install/loaders/typescript.js +0 -11
- data/lib/install/loaders/vue.js +0 -6
- data/lib/install/react.rb +0 -18
- data/lib/install/stimulus.rb +0 -12
- data/lib/install/svelte.rb +0 -29
- data/lib/install/typescript.rb +0 -46
- data/lib/install/vue.rb +0 -49
- data/lib/tasks/installers.rake +0 -42
- data/package/config_types/__tests__/config_list.js +0 -118
- data/package/config_types/__tests__/config_object.js +0 -43
- data/package/config_types/config_list.js +0 -75
- data/package/config_types/config_object.js +0 -55
- data/package/config_types/index.js +0 -7
- data/package/rules/module.css.js +0 -3
- data/package/rules/module.sass.js +0 -8
- data/package/rules/node_modules.js +0 -24
- data/package/utils/__tests__/deep_assign.js +0 -32
- data/package/utils/__tests__/deep_merge.js +0 -10
- data/package/utils/__tests__/get_style_rule.js +0 -65
- data/package/utils/__tests__/objectify.js +0 -9
- data/package/utils/deep_assign.js +0 -22
- data/package/utils/deep_merge.js +0 -22
- data/package/utils/objectify.js +0 -3
@@ -0,0 +1,15 @@
|
|
1
|
+
/* eslint no-console: 0 */
|
2
|
+
// Run this example by adding <%= javascript_pack_tag 'hello_vue' %> (and
|
3
|
+
// <%= stylesheet_pack_tag 'hello_vue' %> if you have styles in your component)
|
4
|
+
// to the head of your layout file,
|
5
|
+
// like app/views/layouts/application.html.erb.
|
6
|
+
// Create a div container with the id 'vue-app' <div id='vue-app'></div>
|
7
|
+
// It renders <p>Hello Vue</p> into it.
|
8
|
+
|
9
|
+
import { createApp } from "vue";
|
10
|
+
import App from "../app.vue";
|
11
|
+
|
12
|
+
document.addEventListener("DOMContentLoaded", () => {
|
13
|
+
const app = createApp(App);
|
14
|
+
app.mount("#vue-app");
|
15
|
+
});
|
@@ -0,0 +1,9 @@
|
|
1
|
+
/*
|
2
|
+
Any CSS added to this file or imported from this file, e.g. `@import '../stylesheets/my-css.css'`,
|
3
|
+
will be included in the "application" pack. Any CSS imported from application.js or as part of the
|
4
|
+
application.js dependency graph, e.g. `import '../stylesheets/my-css.css'` will also be included
|
5
|
+
in the "application" pack.
|
6
|
+
|
7
|
+
To reference this file, add <%= stylesheet_pack_tag 'application' %> to the appropriate
|
8
|
+
layout file, like app/views/layouts/application.html.erb
|
9
|
+
*/
|
data/lib/install/template.rb
CHANGED
@@ -4,15 +4,6 @@ copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
|
|
4
4
|
say "Copying webpack core config"
|
5
5
|
directory "#{__dir__}/config/webpack", "config/webpack"
|
6
6
|
|
7
|
-
say "Copying postcss.config.js to app root directory"
|
8
|
-
copy_file "#{__dir__}/config/postcss.config.js", "postcss.config.js"
|
9
|
-
|
10
|
-
say "Copying babel.config.js to app root directory"
|
11
|
-
copy_file "#{__dir__}/config/babel.config.js", "babel.config.js"
|
12
|
-
|
13
|
-
say "Copying .browserslistrc to app root directory"
|
14
|
-
copy_file "#{__dir__}/config/.browserslistrc", ".browserslistrc"
|
15
|
-
|
16
7
|
if Dir.exists?(Webpacker.config.source_path)
|
17
8
|
say "The JavaScript app source directory already exists"
|
18
9
|
else
|
@@ -22,8 +13,9 @@ end
|
|
22
13
|
|
23
14
|
apply "#{__dir__}/binstubs.rb"
|
24
15
|
|
25
|
-
|
26
|
-
|
16
|
+
git_ignore_path = Rails.root.join(".gitignore")
|
17
|
+
if File.exists?(git_ignore_path)
|
18
|
+
append_to_file git_ignore_path do
|
27
19
|
"\n" +
|
28
20
|
"/public/packs\n" +
|
29
21
|
"/public/packs-test\n" +
|
@@ -34,16 +26,38 @@ if File.exists?(".gitignore")
|
|
34
26
|
end
|
35
27
|
end
|
36
28
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
29
|
+
Dir.chdir(Rails.root) do
|
30
|
+
if Webpacker::VERSION =~ /^[0-9]+\.[0-9]+\.[0-9]+$/
|
31
|
+
say "Installing all JavaScript dependencies [#{Webpacker::VERSION}]"
|
32
|
+
run "yarn add @rails/webpacker@#{Webpacker::VERSION}"
|
33
|
+
else
|
34
|
+
say "Installing all JavaScript dependencies [from prerelease rails/webpacker]"
|
35
|
+
run "yarn add @rails/webpacker@next"
|
36
|
+
end
|
37
|
+
|
38
|
+
package_json = File.read("#{__dir__}/../../package.json")
|
39
|
+
webpack_version = package_json.match(/"webpack": "(.*)"/)[1]
|
40
|
+
webpack_cli_version = package_json.match(/"webpack-cli": "(.*)"/)[1]
|
41
|
+
|
42
|
+
# needed for experimental Yarn 2 support and should not harm Yarn 1
|
43
|
+
say "Installing webpack and webpack-cli as direct dependencies"
|
44
|
+
run "yarn add webpack@#{webpack_version} webpack-cli@#{webpack_cli_version}"
|
45
|
+
|
46
|
+
say "Installing dev server for live reloading"
|
47
|
+
run "yarn add --dev webpack-dev-server @webpack-cli/serve"
|
43
48
|
end
|
44
49
|
|
45
|
-
|
46
|
-
|
50
|
+
insert_into_file Rails.root.join("package.json").to_s, before: /\n}\n*$/ do
|
51
|
+
<<~JSON.chomp
|
52
|
+
,
|
53
|
+
"babel": {
|
54
|
+
"presets": ["./node_modules/@rails/webpacker/package/babel/preset.js"]
|
55
|
+
},
|
56
|
+
"browserslist": [
|
57
|
+
"defaults"
|
58
|
+
]
|
59
|
+
JSON
|
60
|
+
end
|
47
61
|
|
48
62
|
if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
|
49
63
|
say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
|
data/lib/tasks/webpacker.rake
CHANGED
@@ -6,19 +6,10 @@ tasks = {
|
|
6
6
|
"webpacker:clobber" => "Removes the webpack compiled output directory",
|
7
7
|
"webpacker:check_node" => "Verifies if Node.js is installed",
|
8
8
|
"webpacker:check_yarn" => "Verifies if Yarn is installed",
|
9
|
-
"webpacker:check_binstubs" => "Verifies that webpack
|
9
|
+
"webpacker:check_binstubs" => "Verifies that bin/webpack is present",
|
10
10
|
"webpacker:binstubs" => "Installs Webpacker binstubs in this application",
|
11
11
|
"webpacker:verify_install" => "Verifies if Webpacker is installed",
|
12
|
-
"webpacker:yarn_install" => "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn"
|
13
|
-
"webpacker:install:react" => "Installs and setup example React component",
|
14
|
-
"webpacker:install:vue" => "Installs and setup example Vue component",
|
15
|
-
"webpacker:install:angular" => "Installs and setup example Angular component",
|
16
|
-
"webpacker:install:elm" => "Installs and setup example Elm component",
|
17
|
-
"webpacker:install:svelte" => "Installs and setup example Svelte component",
|
18
|
-
"webpacker:install:stimulus" => "Installs and setup example Stimulus component",
|
19
|
-
"webpacker:install:erb" => "Installs Erb loader with an example",
|
20
|
-
"webpacker:install:coffee" => "Installs CoffeeScript loader with an example",
|
21
|
-
"webpacker:install:typescript" => "Installs Typescript loader with an example"
|
12
|
+
"webpacker:yarn_install" => "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn"
|
22
13
|
}.freeze
|
23
14
|
|
24
15
|
desc "Lists all available tasks in Webpacker"
|
@@ -1,13 +1,15 @@
|
|
1
1
|
binstubs_template_path = File.expand_path("../../install/binstubs.rb", __dir__).freeze
|
2
|
-
bin_path = ENV["BUNDLE_BIN"] || "
|
2
|
+
bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
|
3
3
|
|
4
4
|
namespace :webpacker do
|
5
5
|
desc "Installs Webpacker binstubs in this application"
|
6
|
-
task binstubs: [:check_node, :check_yarn] do
|
6
|
+
task binstubs: [:check_node, :check_yarn] do |task|
|
7
|
+
prefix = task.name.split(/#|webpacker:binstubs/).first
|
8
|
+
|
7
9
|
if Rails::VERSION::MAJOR >= 5
|
8
|
-
exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION=#{binstubs_template_path}"
|
10
|
+
exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION=#{binstubs_template_path}"
|
9
11
|
else
|
10
|
-
exec "#{RbConfig.ruby} #{bin_path}/rake rails:template LOCATION=#{binstubs_template_path}"
|
12
|
+
exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION=#{binstubs_template_path}"
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -1,10 +1,10 @@
|
|
1
1
|
namespace :webpacker do
|
2
|
-
desc "Verifies that webpack
|
2
|
+
desc "Verifies that bin/webpack is present"
|
3
3
|
task :check_binstubs do
|
4
|
-
unless File.exist?("bin/webpack")
|
5
|
-
$stderr.puts "webpack
|
4
|
+
unless File.exist?(Rails.root.join("bin/webpack"))
|
5
|
+
$stderr.puts "webpack binstub not found.\n"\
|
6
6
|
"Have you run rails webpacker:install ?\n"\
|
7
|
-
"Make sure the bin directory
|
7
|
+
"Make sure the bin directory and bin/webpack are not included in .gitignore\n"\
|
8
8
|
"Exiting!"
|
9
9
|
exit!
|
10
10
|
end
|
@@ -3,7 +3,7 @@ namespace :webpacker do
|
|
3
3
|
desc "Verifies if Node.js is installed"
|
4
4
|
task :check_node do
|
5
5
|
begin
|
6
|
-
node_version = `node -v || nodejs -v
|
6
|
+
node_version = `node -v || nodejs -v`.strip
|
7
7
|
raise Errno::ENOENT if node_version.blank?
|
8
8
|
|
9
9
|
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
|
@@ -3,19 +3,18 @@ namespace :webpacker do
|
|
3
3
|
desc "Verifies if Yarn is installed"
|
4
4
|
task :check_yarn do
|
5
5
|
begin
|
6
|
-
yarn_version = `yarn --version
|
6
|
+
yarn_version = `yarn --version`.strip
|
7
7
|
raise Errno::ENOENT if yarn_version.blank?
|
8
8
|
|
9
9
|
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
|
10
10
|
yarn_range = JSON.parse(pkg_path.read)["engines"]["yarn"]
|
11
11
|
is_valid = SemanticRange.satisfies?(yarn_version, yarn_range) rescue false
|
12
|
-
is_unsupported = SemanticRange.satisfies?(yarn_version, ">=
|
12
|
+
is_unsupported = SemanticRange.satisfies?(yarn_version, ">=3.0.0") rescue false
|
13
13
|
|
14
14
|
unless is_valid
|
15
15
|
$stderr.puts "Webpacker requires Yarn \"#{yarn_range}\" and you are using #{yarn_version}"
|
16
16
|
if is_unsupported
|
17
17
|
$stderr.puts "This version of Webpacker does not support Yarn #{yarn_version}. Please downgrade to a supported version of Yarn https://yarnpkg.com/lang/en/docs/install/"
|
18
|
-
$stderr.puts "For information on using Webpacker with Yarn 2.0, see https://github.com/rails/webpacker/issues/2112"
|
19
18
|
else
|
20
19
|
$stderr.puts "Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/"
|
21
20
|
end
|
@@ -10,8 +10,10 @@ end
|
|
10
10
|
def enhance_assets_precompile
|
11
11
|
# yarn:install was added in Rails 5.1
|
12
12
|
deps = yarn_install_available? ? [] : ["webpacker:yarn_install"]
|
13
|
-
Rake::Task["assets:precompile"].enhance(deps) do
|
14
|
-
|
13
|
+
Rake::Task["assets:precompile"].enhance(deps) do |task|
|
14
|
+
prefix = task.name.split(/#|assets:precompile/).first
|
15
|
+
|
16
|
+
Rake::Task["#{prefix}webpacker:compile"].invoke
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
@@ -3,17 +3,19 @@ require "webpacker/version"
|
|
3
3
|
namespace :webpacker do
|
4
4
|
desc "Provide information on Webpacker's environment"
|
5
5
|
task :info do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
Dir.chdir(Rails.root) do
|
7
|
+
$stdout.puts "Ruby: #{`ruby --version`}"
|
8
|
+
$stdout.puts "Rails: #{Rails.version}"
|
9
|
+
$stdout.puts "Webpacker: #{Webpacker::VERSION}"
|
10
|
+
$stdout.puts "Node: #{`node --version`}"
|
11
|
+
$stdout.puts "Yarn: #{`yarn --version`}"
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
$stdout.puts "\n"
|
14
|
+
$stdout.puts "@rails/webpacker: \n#{`npm list @rails/webpacker version`}"
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
|
16
|
+
$stdout.puts "Is bin/webpack present?: #{File.exist? 'bin/webpack'}"
|
17
|
+
$stdout.puts "Is bin/webpack-dev-server present?: #{File.exist? 'bin/webpack-dev-server'}"
|
18
|
+
$stdout.puts "Is bin/yarn present?: #{File.exist? 'bin/yarn'}"
|
19
|
+
end
|
18
20
|
end
|
19
21
|
end
|
@@ -1,13 +1,15 @@
|
|
1
1
|
install_template_path = File.expand_path("../../install/template.rb", __dir__).freeze
|
2
|
-
bin_path = ENV["BUNDLE_BIN"] || "
|
2
|
+
bin_path = ENV["BUNDLE_BIN"] || Rails.root.join("bin")
|
3
3
|
|
4
4
|
namespace :webpacker do
|
5
5
|
desc "Install Webpacker in this application"
|
6
|
-
task install: [:check_node, :check_yarn] do
|
6
|
+
task install: [:check_node, :check_yarn] do |task|
|
7
|
+
prefix = task.name.split(/#|webpacker:install/).first
|
8
|
+
|
7
9
|
if Rails::VERSION::MAJOR >= 5
|
8
|
-
exec "#{RbConfig.ruby} #{bin_path}/rails app:template LOCATION=#{install_template_path}"
|
10
|
+
exec "#{RbConfig.ruby} #{bin_path}/rails #{prefix}app:template LOCATION=#{install_template_path}"
|
9
11
|
else
|
10
|
-
exec "#{RbConfig.ruby} #{bin_path}/rake rails:template LOCATION=#{install_template_path}"
|
12
|
+
exec "#{RbConfig.ruby} #{bin_path}/rake #{prefix}rails:template LOCATION=#{install_template_path}"
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
@@ -4,7 +4,8 @@ namespace :webpacker do
|
|
4
4
|
desc "Verifies if Webpacker is installed"
|
5
5
|
task verify_install: [:check_node, :check_yarn, :check_binstubs] do
|
6
6
|
unless Webpacker.config.config_path.exist?
|
7
|
-
|
7
|
+
path = Webpacker.config.config_path.relative_path_from(Pathname.new(pwd)).to_s
|
8
|
+
$stderr.puts "Configuration #{path} file not found. \n"\
|
8
9
|
"Make sure webpacker:install is run successfully before " \
|
9
10
|
"running dependent tasks"
|
10
11
|
exit!
|
@@ -5,6 +5,14 @@ namespace :webpacker do
|
|
5
5
|
node_env = ENV.fetch("NODE_ENV") do
|
6
6
|
valid_node_envs.include?(Rails.env) ? Rails.env : "production"
|
7
7
|
end
|
8
|
-
|
8
|
+
Dir.chdir(Rails.root) do
|
9
|
+
yarn_flags =
|
10
|
+
if `yarn --version`.start_with?("1")
|
11
|
+
"--no-progress --frozen-lockfile"
|
12
|
+
else
|
13
|
+
"--immutable"
|
14
|
+
end
|
15
|
+
system({ "NODE_ENV" => node_env }, "yarn install #{yarn_flags}")
|
16
|
+
end
|
9
17
|
end
|
10
18
|
end
|
data/lib/webpacker/commands.rb
CHANGED
@@ -23,7 +23,7 @@ class Webpacker::Commands
|
|
23
23
|
.each_with_index
|
24
24
|
.drop_while do |(mtime, _), index|
|
25
25
|
max_age = [0, Time.now - Time.at(mtime)].max
|
26
|
-
max_age < age
|
26
|
+
max_age < age || index < count
|
27
27
|
end
|
28
28
|
.each do |(_, files), index|
|
29
29
|
files.each do |file|
|
data/lib/webpacker/compiler.rb
CHANGED
@@ -4,6 +4,8 @@ require "digest/sha1"
|
|
4
4
|
class Webpacker::Compiler
|
5
5
|
# Additional paths that test compiler needs to watch
|
6
6
|
# Webpacker::Compiler.watched_paths << 'bower_components'
|
7
|
+
#
|
8
|
+
# Deprecated. Use additional_paths in the YAML configuration instead.
|
7
9
|
cattr_accessor(:watched_paths) { [] }
|
8
10
|
|
9
11
|
# Additional environment variables that the compiler is being run with
|
@@ -20,9 +22,8 @@ class Webpacker::Compiler
|
|
20
22
|
if stale?
|
21
23
|
run_webpack.tap do |success|
|
22
24
|
# We used to only record the digest on success
|
23
|
-
# However, the output file is still written on error,
|
24
|
-
#
|
25
|
-
# take place when it should.
|
25
|
+
# However, the output file is still written on error, meaning that the digest should still be updated.
|
26
|
+
# If it's not, you can end up in a situation where a recompile doesn't take place when it should.
|
26
27
|
# See https://github.com/rails/webpacker/issues/2113
|
27
28
|
record_compilation_digest
|
28
29
|
end
|
@@ -51,9 +52,12 @@ class Webpacker::Compiler
|
|
51
52
|
end
|
52
53
|
|
53
54
|
def watched_files_digest
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
warn "Webpacker::Compiler.watched_paths has been deprecated. Set additional_paths in webpacker.yml instead." unless watched_paths.empty?
|
56
|
+
Dir.chdir File.expand_path(config.root_path) do
|
57
|
+
files = Dir[*default_watched_paths, *watched_paths].reject { |f| File.directory?(f) }
|
58
|
+
file_ids = files.sort.map { |f| "#{File.basename(f)}/#{Digest::SHA1.file(f).hexdigest}" }
|
59
|
+
Digest::SHA1.hexdigest(file_ids.join("/"))
|
60
|
+
end
|
57
61
|
end
|
58
62
|
|
59
63
|
def record_compilation_digest
|
@@ -87,8 +91,8 @@ class Webpacker::Compiler
|
|
87
91
|
|
88
92
|
def default_watched_paths
|
89
93
|
[
|
90
|
-
*config.
|
91
|
-
config.
|
94
|
+
*config.additional_paths,
|
95
|
+
"#{config.source_path}/**/*",
|
92
96
|
"yarn.lock", "package.json",
|
93
97
|
"config/webpack/**/*"
|
94
98
|
].freeze
|
@@ -102,6 +106,7 @@ class Webpacker::Compiler
|
|
102
106
|
return env unless defined?(ActionController::Base)
|
103
107
|
|
104
108
|
env.merge("WEBPACKER_ASSET_HOST" => ENV.fetch("WEBPACKER_ASSET_HOST", ActionController::Base.helpers.compute_asset_host),
|
105
|
-
"WEBPACKER_RELATIVE_URL_ROOT" => ENV.fetch("WEBPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root)
|
109
|
+
"WEBPACKER_RELATIVE_URL_ROOT" => ENV.fetch("WEBPACKER_RELATIVE_URL_ROOT", ActionController::Base.relative_url_root),
|
110
|
+
"WEBPACKER_CONFIG" => webpacker.config_path.to_s)
|
106
111
|
end
|
107
112
|
end
|
@@ -23,16 +23,8 @@ class Webpacker::Configuration
|
|
23
23
|
root_path.join(fetch(:source_path))
|
24
24
|
end
|
25
25
|
|
26
|
-
def
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
def resolved_paths
|
31
|
-
fetch(:resolved_paths)
|
32
|
-
end
|
33
|
-
|
34
|
-
def resolved_paths_globbed
|
35
|
-
resolved_paths.map { |p| globbed_path_with_extensions(p) }
|
26
|
+
def additional_paths
|
27
|
+
fetch(:additional_paths)
|
36
28
|
end
|
37
29
|
|
38
30
|
def source_entry_path
|
@@ -59,26 +51,18 @@ class Webpacker::Configuration
|
|
59
51
|
root_path.join(fetch(:cache_path))
|
60
52
|
end
|
61
53
|
|
62
|
-
def extensions
|
63
|
-
fetch(:extensions)
|
64
|
-
end
|
65
|
-
|
66
54
|
def check_yarn_integrity=(value)
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
55
|
+
warn <<~EOS
|
56
|
+
Webpacker::Configuration#check_yarn_integrity=(value) is obsolete. The integrity
|
57
|
+
check has been removed from Webpacker (https://github.com/rails/webpacker/pull/2518)
|
58
|
+
so changing this setting will have no effect.
|
59
|
+
EOS
|
72
60
|
end
|
73
61
|
|
74
62
|
def webpack_compile_output?
|
75
63
|
fetch(:webpack_compile_output)
|
76
64
|
end
|
77
65
|
|
78
|
-
def extract_css?
|
79
|
-
fetch(:extract_css)
|
80
|
-
end
|
81
|
-
|
82
66
|
private
|
83
67
|
def fetch(key)
|
84
68
|
data.fetch(key, defaults[key])
|
@@ -106,8 +90,4 @@ class Webpacker::Configuration
|
|
106
90
|
@defaults ||= \
|
107
91
|
HashWithIndifferentAccess.new(YAML.load_file(File.expand_path("../../install/config/webpacker.yml", __FILE__))[env])
|
108
92
|
end
|
109
|
-
|
110
|
-
def globbed_path_with_extensions(path)
|
111
|
-
"#{path}/**/*{#{extensions.join(',')}}"
|
112
|
-
end
|
113
93
|
end
|
@@ -11,7 +11,9 @@ class Webpacker::DevServerProxy < Rack::Proxy
|
|
11
11
|
|
12
12
|
def perform_request(env)
|
13
13
|
if env["PATH_INFO"].start_with?("/#{public_output_uri_path}") && dev_server.running?
|
14
|
-
env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] =
|
14
|
+
env["HTTP_HOST"] = env["HTTP_X_FORWARDED_HOST"] = dev_server.host
|
15
|
+
env["HTTP_X_FORWARDED_SERVER"] = dev_server.host_with_port
|
16
|
+
env["HTTP_PORT"] = env["HTTP_X_FORWARDED_PORT"] = dev_server.port.to_s
|
15
17
|
env["HTTP_X_FORWARDED_PROTO"] = env["HTTP_X_FORWARDED_SCHEME"] = dev_server.protocol
|
16
18
|
unless dev_server.https?
|
17
19
|
env["HTTPS"] = env["HTTP_X_FORWARDED_SSL"] = "off"
|
@@ -8,11 +8,13 @@ module Webpacker
|
|
8
8
|
class DevServerRunner < Webpacker::Runner
|
9
9
|
def run
|
10
10
|
load_config
|
11
|
+
detect_unsupported_switches!
|
11
12
|
detect_port!
|
12
13
|
execute_cmd
|
13
14
|
end
|
14
15
|
|
15
16
|
private
|
17
|
+
|
16
18
|
def load_config
|
17
19
|
app_root = Pathname.new(@app_path)
|
18
20
|
|
@@ -27,6 +29,7 @@ module Webpacker
|
|
27
29
|
@hostname = dev_server.host
|
28
30
|
@port = dev_server.port
|
29
31
|
@pretty = dev_server.pretty?
|
32
|
+
@https = dev_server.https?
|
30
33
|
|
31
34
|
rescue Errno::ENOENT, NoMethodError
|
32
35
|
$stdout.puts "webpack dev_server configuration not found in #{@config.config_path}[#{ENV["RAILS_ENV"]}]."
|
@@ -34,6 +37,21 @@ module Webpacker
|
|
34
37
|
exit!
|
35
38
|
end
|
36
39
|
|
40
|
+
UNSUPPORTED_SWITCHES = %w[--host --port]
|
41
|
+
private_constant :UNSUPPORTED_SWITCHES
|
42
|
+
def detect_unsupported_switches!
|
43
|
+
unsupported_switches = UNSUPPORTED_SWITCHES & @argv
|
44
|
+
if unsupported_switches.any?
|
45
|
+
$stdout.puts "The following CLI switches are not supported by Webpacker: #{unsupported_switches.join(' ')}. Please edit your command and try again."
|
46
|
+
exit!
|
47
|
+
end
|
48
|
+
|
49
|
+
if @argv.include?("--https") && !@https
|
50
|
+
$stdout.puts "Please set https: true in webpacker.yml to use the --https command line flag."
|
51
|
+
exit!
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
37
55
|
def detect_port!
|
38
56
|
server = TCPServer.new(@hostname, @port)
|
39
57
|
server.close
|
@@ -45,20 +63,21 @@ module Webpacker
|
|
45
63
|
|
46
64
|
def execute_cmd
|
47
65
|
env = Webpacker::Compiler.env
|
66
|
+
env["WEBPACKER_CONFIG"] = @webpacker_config
|
48
67
|
|
49
68
|
cmd = if node_modules_bin_exist?
|
50
|
-
["#{@node_modules_bin_path}/webpack
|
69
|
+
["#{@node_modules_bin_path}/webpack", "serve"]
|
51
70
|
else
|
52
|
-
["yarn", "webpack
|
71
|
+
["yarn", "webpack", "serve"]
|
53
72
|
end
|
54
73
|
|
55
|
-
if
|
74
|
+
if @argv.include?("--debug-webpacker")
|
56
75
|
cmd = [ "node", "--inspect-brk"] + cmd
|
57
|
-
ARGV.delete("--debug")
|
58
76
|
end
|
59
77
|
|
60
78
|
cmd += ["--config", @webpack_config]
|
61
79
|
cmd += ["--progress", "--color"] if @pretty
|
80
|
+
cmd += @argv
|
62
81
|
|
63
82
|
Dir.chdir(@app_path) do
|
64
83
|
Kernel.exec env, *cmd
|