webpacker-jets 3.2.100
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.eslintignore +4 -0
- data/.eslintrc.js +14 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +124 -0
- data/.travis.yml +32 -0
- data/CHANGELOG.md +523 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +154 -0
- data/MIT-LICENSE +20 -0
- data/README.md +445 -0
- data/Rakefile +12 -0
- data/docs/assets.md +106 -0
- data/docs/cloud9.md +310 -0
- data/docs/css.md +116 -0
- data/docs/deployment.md +74 -0
- data/docs/docker.md +49 -0
- data/docs/env.md +65 -0
- data/docs/es6.md +53 -0
- data/docs/folder-structure.md +66 -0
- data/docs/misc.md +23 -0
- data/docs/props.md +223 -0
- data/docs/testing.md +128 -0
- data/docs/troubleshooting.md +119 -0
- data/docs/typescript.md +116 -0
- data/docs/webpack-dev-server.md +92 -0
- data/docs/webpack.md +297 -0
- data/docs/yarn.md +12 -0
- data/exe/webpack +8 -0
- data/exe/webpack-dev-server +8 -0
- data/gemfiles/Gemfile-rails-edge +13 -0
- data/gemfiles/Gemfile-rails.4.2.x +10 -0
- data/gemfiles/Gemfile-rails.5.0.x +10 -0
- data/gemfiles/Gemfile-rails.5.1.x +10 -0
- data/lib/install/angular.rb +27 -0
- data/lib/install/coffee.rb +22 -0
- data/lib/install/config/.babelrc +18 -0
- data/lib/install/config/.postcssrc.yml +3 -0
- data/lib/install/config/webpack/development.js +3 -0
- data/lib/install/config/webpack/environment.js +3 -0
- data/lib/install/config/webpack/production.js +3 -0
- data/lib/install/config/webpack/staging.js +3 -0
- data/lib/install/config/webpack/test.js +3 -0
- data/lib/install/config/webpacker.yml +79 -0
- data/lib/install/elm.rb +38 -0
- data/lib/install/erb.rb +22 -0
- data/lib/install/examples/angular/hello_angular.js +7 -0
- data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
- data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
- data/lib/install/examples/angular/hello_angular/index.ts +8 -0
- data/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
- data/lib/install/examples/angular/tsconfig.json +19 -0
- data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
- data/lib/install/examples/elm/Main.elm +54 -0
- data/lib/install/examples/elm/hello_elm.js +12 -0
- data/lib/install/examples/erb/hello_erb.js.erb +6 -0
- data/lib/install/examples/react/.babelrc +6 -0
- data/lib/install/examples/react/hello_react.jsx +26 -0
- data/lib/install/examples/vue/app.vue +22 -0
- data/lib/install/examples/vue/hello_vue.js +70 -0
- data/lib/install/javascript/packs/application.js +10 -0
- data/lib/install/loaders/coffee.js +6 -0
- data/lib/install/loaders/elm.js +23 -0
- data/lib/install/loaders/erb.js +11 -0
- data/lib/install/loaders/typescript.js +6 -0
- data/lib/install/loaders/vue.js +13 -0
- data/lib/install/react.rb +28 -0
- data/lib/install/template.rb +37 -0
- data/lib/install/vue.rb +26 -0
- data/lib/tasks/installers.rake +24 -0
- data/lib/tasks/webpacker.rake +22 -0
- data/lib/tasks/webpacker/check_binstubs.rake +12 -0
- data/lib/tasks/webpacker/check_node.rake +24 -0
- data/lib/tasks/webpacker/check_yarn.rake +24 -0
- data/lib/tasks/webpacker/clobber.rake +16 -0
- data/lib/tasks/webpacker/compile.rake +41 -0
- data/lib/tasks/webpacker/install.rake +13 -0
- data/lib/tasks/webpacker/verify_install.rake +16 -0
- data/lib/tasks/webpacker/yarn_install.rake +6 -0
- data/lib/webpacker.rb +32 -0
- data/lib/webpacker/commands.rb +23 -0
- data/lib/webpacker/compiler.rb +88 -0
- data/lib/webpacker/configuration.rb +87 -0
- data/lib/webpacker/dev_server.rb +61 -0
- data/lib/webpacker/dev_server_proxy.rb +26 -0
- data/lib/webpacker/dev_server_runner.rb +51 -0
- data/lib/webpacker/helper.rb +66 -0
- data/lib/webpacker/instance.rb +44 -0
- data/lib/webpacker/manifest.rb +75 -0
- data/lib/webpacker/railtie.rb +82 -0
- data/lib/webpacker/rake_tasks.rb +6 -0
- data/lib/webpacker/runner.rb +22 -0
- data/lib/webpacker/version.rb +9 -0
- data/lib/webpacker/webpack_runner.rb +15 -0
- data/package.json +67 -0
- data/package/__tests__/environment.js +74 -0
- data/package/config.js +34 -0
- data/package/config_types/__tests__/config_list.js +123 -0
- data/package/config_types/__tests__/config_object.js +43 -0
- data/package/config_types/config_list.js +85 -0
- data/package/config_types/config_object.js +55 -0
- data/package/config_types/index.js +7 -0
- data/package/environment.js +116 -0
- data/package/environments/development.js +46 -0
- data/package/environments/production.js +37 -0
- data/package/environments/test.js +3 -0
- data/package/index.js +20 -0
- data/package/rules/babel.js +13 -0
- data/package/rules/css.js +39 -0
- data/package/rules/file.js +13 -0
- data/package/rules/index.js +11 -0
- data/package/rules/sass.js +15 -0
- data/package/utils/__tests__/deep_assign.js +11 -0
- data/package/utils/__tests__/deep_merge.js +10 -0
- data/package/utils/__tests__/objectify.js +9 -0
- data/package/utils/deep_assign.js +22 -0
- data/package/utils/deep_merge.js +23 -0
- data/package/utils/helpers.js +32 -0
- data/package/utils/objectify.js +4 -0
- data/test/command_test.rb +27 -0
- data/test/compiler_test.rb +35 -0
- data/test/configuration_test.rb +69 -0
- data/test/dev_server_test.rb +24 -0
- data/test/helper_test.rb +52 -0
- data/test/manifest_test.rb +28 -0
- data/test/rake_tasks_test.rb +29 -0
- data/test/test_app/Rakefile +3 -0
- data/test/test_app/app/javascript/packs/application.js +10 -0
- data/test/test_app/config/application.rb +11 -0
- data/test/test_app/config/environment.rb +4 -0
- data/test/test_app/config/webpacker.yml +65 -0
- data/test/test_app/public/packs/manifest.json +6 -0
- data/test/test_helper.rb +29 -0
- data/webpacker-jets.gemspec +29 -0
- data/yarn.lock +5768 -0
- metadata +250 -0
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
// All it does is render <div>Hello Vue</div> at the bottom of the page.
|
|
7
|
+
|
|
8
|
+
import Vue from 'vue'
|
|
9
|
+
import App from '../app.vue'
|
|
10
|
+
|
|
11
|
+
document.addEventListener('DOMContentLoaded', () => {
|
|
12
|
+
document.body.appendChild(document.createElement('hello'))
|
|
13
|
+
const app = new Vue({
|
|
14
|
+
render: h => h(App)
|
|
15
|
+
}).$mount('hello')
|
|
16
|
+
|
|
17
|
+
console.log(app)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
// The above code uses Vue without the compiler, which means you cannot
|
|
22
|
+
// use Vue to target elements in your existing html templates. You would
|
|
23
|
+
// need to always use single file components.
|
|
24
|
+
// To be able to target elements in your existing html/erb templates,
|
|
25
|
+
// comment out the above code and uncomment the below
|
|
26
|
+
// Add <%= javascript_pack_tag 'hello_vue' %> to your layout
|
|
27
|
+
// Then add this markup to your html template:
|
|
28
|
+
//
|
|
29
|
+
// <div id='hello'>
|
|
30
|
+
// {{message}}
|
|
31
|
+
// <app></app>
|
|
32
|
+
// </div>
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
// import Vue from 'vue/dist/vue.esm'
|
|
36
|
+
// import App from '../app.vue'
|
|
37
|
+
//
|
|
38
|
+
// document.addEventListener('DOMContentLoaded', () => {
|
|
39
|
+
// const app = new Vue({
|
|
40
|
+
// el: '#hello',
|
|
41
|
+
// data: {
|
|
42
|
+
// message: "Can you say hello?"
|
|
43
|
+
// },
|
|
44
|
+
// components: { App }
|
|
45
|
+
// })
|
|
46
|
+
// })
|
|
47
|
+
//
|
|
48
|
+
//
|
|
49
|
+
//
|
|
50
|
+
// If the using turbolinks, install 'vue-turbolinks':
|
|
51
|
+
//
|
|
52
|
+
// yarn add 'vue-turbolinks'
|
|
53
|
+
//
|
|
54
|
+
// Then uncomment the code block below:
|
|
55
|
+
//
|
|
56
|
+
// import TurbolinksAdapter from 'vue-turbolinks';
|
|
57
|
+
// import Vue from 'vue/dist/vue.esm'
|
|
58
|
+
// import App from '../app.vue'
|
|
59
|
+
//
|
|
60
|
+
// Vue.use(TurbolinksAdapter)
|
|
61
|
+
//
|
|
62
|
+
// document.addEventListener('turbolinks:load', () => {
|
|
63
|
+
// const app = new Vue({
|
|
64
|
+
// el: '#hello',
|
|
65
|
+
// data: {
|
|
66
|
+
// message: "Can you say hello?"
|
|
67
|
+
// },
|
|
68
|
+
// components: { App }
|
|
69
|
+
// })
|
|
70
|
+
// })
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/* eslint no-console:0 */
|
|
2
|
+
// This file is automatically compiled by Webpack, along with any other files
|
|
3
|
+
// present in this directory. You're encouraged to place your actual application logic in
|
|
4
|
+
// a relevant structure within app/javascript and only use these pack files to reference
|
|
5
|
+
// that code so it'll be compiled.
|
|
6
|
+
//
|
|
7
|
+
// To reference this file, add <%= javascript_pack_tag 'application' %> to the appropriate
|
|
8
|
+
// layout file, like app/views/layouts/application.html.erb
|
|
9
|
+
|
|
10
|
+
console.log('Hello World from Webpacker')
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const { resolve } = require('path')
|
|
2
|
+
|
|
3
|
+
const isProduction = process.env.NODE_ENV === 'production'
|
|
4
|
+
const elmSource = resolve(process.cwd())
|
|
5
|
+
const elmMake = `${elmSource}/node_modules/.bin/elm-make`
|
|
6
|
+
|
|
7
|
+
const elmDefaultOptions = { cwd: elmSource, pathToMake: elmMake }
|
|
8
|
+
const developmentOptions = Object.assign({}, elmDefaultOptions, {
|
|
9
|
+
verbose: true,
|
|
10
|
+
warn: true,
|
|
11
|
+
debug: true
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
const elmWebpackLoader = {
|
|
15
|
+
loader: 'elm-webpack-loader',
|
|
16
|
+
options: isProduction ? elmDefaultOptions : developmentOptions
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = {
|
|
20
|
+
test: /\.elm(\.erb)?$/,
|
|
21
|
+
exclude: [/elm-stuff/, /node_modules/],
|
|
22
|
+
use: isProduction ? [elmWebpackLoader] : [{ loader: 'elm-hot-loader' }, elmWebpackLoader]
|
|
23
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const { dev_server: devServer } = require('@rails/webpacker').config
|
|
2
|
+
|
|
3
|
+
const isProduction = process.env.NODE_ENV === 'production'
|
|
4
|
+
const inDevServer = process.argv.find(v => v.includes('webpack-dev-server'))
|
|
5
|
+
const extractCSS = !(inDevServer && (devServer && devServer.hmr)) || isProduction
|
|
6
|
+
|
|
7
|
+
module.exports = {
|
|
8
|
+
test: /\.vue(\.erb)?$/,
|
|
9
|
+
use: [{
|
|
10
|
+
loader: 'vue-loader',
|
|
11
|
+
options: { extractCSS }
|
|
12
|
+
}]
|
|
13
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
require "webpacker/configuration"
|
|
2
|
+
|
|
3
|
+
babelrc = Jets.root.join(".babelrc")
|
|
4
|
+
|
|
5
|
+
if File.exist?(babelrc)
|
|
6
|
+
react_babelrc = JSON.parse(File.read(babelrc))
|
|
7
|
+
react_babelrc["presets"] ||= []
|
|
8
|
+
|
|
9
|
+
unless react_babelrc["presets"].include?("react")
|
|
10
|
+
react_babelrc["presets"].push("react")
|
|
11
|
+
say "Copying react preset to your .babelrc file"
|
|
12
|
+
|
|
13
|
+
File.open(babelrc, "w") do |f|
|
|
14
|
+
f.puts JSON.pretty_generate(react_babelrc)
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
else
|
|
18
|
+
say "Copying .babelrc to app root directory"
|
|
19
|
+
copy_file "#{__dir__}/examples/react/.babelrc", ".babelrc"
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
say "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"
|
|
24
|
+
|
|
25
|
+
say "Installing all react dependencies"
|
|
26
|
+
run "yarn add react react-dom babel-preset-react prop-types"
|
|
27
|
+
|
|
28
|
+
say "Webpacker now supports react.js 🎉", :green
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Install Webpacker
|
|
2
|
+
copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
|
|
3
|
+
|
|
4
|
+
puts "Copying webpack core config"
|
|
5
|
+
directory "#{__dir__}/config/webpack", "config/webpack"
|
|
6
|
+
|
|
7
|
+
say "Copying .postcssrc.yml to app root directory"
|
|
8
|
+
copy_file "#{__dir__}/config/.postcssrc.yml", ".postcssrc.yml"
|
|
9
|
+
|
|
10
|
+
say "Copying .babelrc to app root directory"
|
|
11
|
+
copy_file "#{__dir__}/config/.babelrc", ".babelrc"
|
|
12
|
+
|
|
13
|
+
# Jets handles creating javascript directory after webpacker:install runs
|
|
14
|
+
unless defined?(Jets)
|
|
15
|
+
say "Creating JavaScript app source directory"
|
|
16
|
+
directory "#{__dir__}/javascript", Webpacker.config.source_path, force: options[:force]
|
|
17
|
+
# How to use the FORCE: rake webpacker:install FORCE=1
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
say "Installing binstubs"
|
|
21
|
+
run "bundle binstubs webpacker"
|
|
22
|
+
|
|
23
|
+
if File.exists?(".gitignore")
|
|
24
|
+
append_to_file ".gitignore", <<-EOS
|
|
25
|
+
/public/packs
|
|
26
|
+
/public/packs-test
|
|
27
|
+
/node_modules
|
|
28
|
+
EOS
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
say "Installing all JavaScript dependencies"
|
|
32
|
+
run "yarn add @rails/webpacker coffeescript@1.12.7"
|
|
33
|
+
|
|
34
|
+
say "Installing dev server for live reloading"
|
|
35
|
+
run "yarn add --dev webpack-dev-server"
|
|
36
|
+
|
|
37
|
+
say "Webpacker successfully installed 🎉 🍰", :green
|
data/lib/install/vue.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require "webpacker/configuration"
|
|
2
|
+
|
|
3
|
+
say "Copying vue loader to config/webpack/loaders"
|
|
4
|
+
copy_file "#{__dir__}/loaders/vue.js", Jets.root.join("config/webpack/loaders/vue.js").to_s
|
|
5
|
+
|
|
6
|
+
say "Adding vue loader to config/webpack/environment.js"
|
|
7
|
+
insert_into_file Jets.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 Jets.root.join("config/webpack/environment.js").to_s,
|
|
12
|
+
"environment.loaders.append('vue', vue)\n",
|
|
13
|
+
before: "module.exports"
|
|
14
|
+
|
|
15
|
+
say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
|
|
16
|
+
copy_file "#{__dir__}/examples/vue/hello_vue.js",
|
|
17
|
+
"#{Webpacker.config.source_entry_path}/hello_vue.js"
|
|
18
|
+
|
|
19
|
+
say "Copying Vue app file to #{Webpacker.config.source_entry_path}"
|
|
20
|
+
copy_file "#{__dir__}/examples/vue/app.vue",
|
|
21
|
+
"#{Webpacker.config.source_path}/app.vue"
|
|
22
|
+
|
|
23
|
+
say "Installing all Vue dependencies"
|
|
24
|
+
run "yarn add vue vue-loader vue-template-compiler"
|
|
25
|
+
|
|
26
|
+
say "Webpacker now supports Vue.js 🎉", :green
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
installers = {
|
|
2
|
+
"Angular": :angular,
|
|
3
|
+
"Elm": :elm,
|
|
4
|
+
"React": :react,
|
|
5
|
+
"Vue": :vue,
|
|
6
|
+
"Erb": :erb,
|
|
7
|
+
"Coffee": :coffee
|
|
8
|
+
}.freeze
|
|
9
|
+
|
|
10
|
+
namespace :webpacker do
|
|
11
|
+
namespace :install do
|
|
12
|
+
installers.each do |name, task_name|
|
|
13
|
+
desc "Install everything needed for #{name}"
|
|
14
|
+
task task_name => ["webpacker:verify_install"] do
|
|
15
|
+
template = File.expand_path("../install/#{task_name}.rb", __dir__)
|
|
16
|
+
if Rails::VERSION::MAJOR >= 5
|
|
17
|
+
exec "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{template}"
|
|
18
|
+
else
|
|
19
|
+
exec "#{RbConfig.ruby} ./bin/rake rails:template LOCATION=#{template}"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
tasks = {
|
|
2
|
+
"webpacker:install" => "Installs and setup webpack with Yarn",
|
|
3
|
+
"webpacker:compile" => "Compiles webpack bundles based on environment",
|
|
4
|
+
"webpacker:clobber" => "Removes the webpack compiled output directory",
|
|
5
|
+
"webpacker:check_node" => "Verifies if Node.js is installed",
|
|
6
|
+
"webpacker:check_yarn" => "Verifies if Yarn is installed",
|
|
7
|
+
"webpacker:check_binstubs" => "Verifies that webpack & webpack-dev-server are present",
|
|
8
|
+
"webpacker:verify_install" => "Verifies if Webpacker is installed",
|
|
9
|
+
"webpacker:yarn_install" => "Install all JavaScript dependencies as specified via Yarn",
|
|
10
|
+
"webpacker:install:react" => "Installs and setup example React component",
|
|
11
|
+
"webpacker:install:vue" => "Installs and setup example Vue component",
|
|
12
|
+
"webpacker:install:angular" => "Installs and setup example Angular component",
|
|
13
|
+
"webpacker:install:elm" => "Installs and setup example Elm component",
|
|
14
|
+
"webpacker:install:erb" => "Installs Erb loader with an example",
|
|
15
|
+
"webpacker:install:coffee" => "Installs CoffeeScript loader with an example"
|
|
16
|
+
}.freeze
|
|
17
|
+
|
|
18
|
+
desc "Lists all available tasks in Webpacker"
|
|
19
|
+
task :webpacker do
|
|
20
|
+
puts "Available Webpacker tasks are:"
|
|
21
|
+
tasks.each { |task, message| puts task.ljust(30) + message }
|
|
22
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
namespace :webpacker do
|
|
2
|
+
desc "Verifies that webpack & webpack-dev-server are present."
|
|
3
|
+
task :check_binstubs do
|
|
4
|
+
unless Bundler.which(Gem.win_platform? ? "webpack.bat" : "webpack")
|
|
5
|
+
$stderr.puts "webpack binstubs not found.\n"\
|
|
6
|
+
"Have you run rails webpacker:install ?\n"\
|
|
7
|
+
"Make sure the bin directory or binstubs are not included in .gitignore\n"\
|
|
8
|
+
"Exiting!"
|
|
9
|
+
exit!
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
namespace :webpacker do
|
|
2
|
+
desc "Verifies if Node.js is installed"
|
|
3
|
+
task :check_node do
|
|
4
|
+
begin
|
|
5
|
+
node_version = `node -v || nodejs -v`
|
|
6
|
+
raise Errno::ENOENT if node_version.blank?
|
|
7
|
+
|
|
8
|
+
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
|
|
9
|
+
node_requirement = JSON.parse(pkg_path.read)["engines"]["node"]
|
|
10
|
+
|
|
11
|
+
requirement = Gem::Requirement.new(node_requirement)
|
|
12
|
+
version = Gem::Version.new(node_version.strip.tr("v", ""))
|
|
13
|
+
|
|
14
|
+
unless requirement.satisfied_by?(version)
|
|
15
|
+
$stderr.puts "Webpacker requires Node.js #{requirement} and you are using #{version}"
|
|
16
|
+
$stderr.puts "Please upgrade Node.js https://nodejs.org/en/download/"
|
|
17
|
+
$stderr.puts "Exiting!" && exit!
|
|
18
|
+
end
|
|
19
|
+
rescue Errno::ENOENT
|
|
20
|
+
$stderr.puts "Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/"
|
|
21
|
+
$stderr.puts "Exiting!" && exit!
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
namespace :webpacker do
|
|
2
|
+
desc "Verifies if Yarn is installed"
|
|
3
|
+
task :check_yarn do
|
|
4
|
+
begin
|
|
5
|
+
yarn_version = `yarn --version`
|
|
6
|
+
raise Errno::ENOENT if yarn_version.blank?
|
|
7
|
+
|
|
8
|
+
pkg_path = Pathname.new("#{__dir__}/../../../package.json").realpath
|
|
9
|
+
yarn_requirement = JSON.parse(pkg_path.read)["engines"]["yarn"]
|
|
10
|
+
|
|
11
|
+
requirement = Gem::Requirement.new(yarn_requirement)
|
|
12
|
+
version = Gem::Version.new(yarn_version)
|
|
13
|
+
|
|
14
|
+
unless requirement.satisfied_by?(version)
|
|
15
|
+
$stderr.puts "Webpacker requires Yarn #{requirement} and you are using #{version}"
|
|
16
|
+
$stderr.puts "Please upgrade Yarn https://yarnpkg.com/lang/en/docs/install/"
|
|
17
|
+
$stderr.puts "Exiting!" && exit!
|
|
18
|
+
end
|
|
19
|
+
rescue Errno::ENOENT
|
|
20
|
+
$stderr.puts "Yarn not installed. Please download and install Yarn from https://yarnpkg.com/lang/en/docs/install/"
|
|
21
|
+
$stderr.puts "Exiting!" && exit!
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require "webpacker/configuration"
|
|
2
|
+
|
|
3
|
+
namespace :webpacker do
|
|
4
|
+
desc "Remove the webpack compiled output directory"
|
|
5
|
+
task clobber: ["webpacker:verify_install", :environment] do
|
|
6
|
+
Webpacker.clobber
|
|
7
|
+
$stdout.puts "Removed webpack output path directory #{Webpacker.config.public_output_path}"
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
# Run clobber if the assets:clobber is run
|
|
12
|
+
if Rake::Task.task_defined?("assets:clobber")
|
|
13
|
+
Rake::Task["assets:clobber"].enhance do
|
|
14
|
+
Rake::Task["webpacker:clobber"].invoke
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
|
10
|
+
|
|
11
|
+
def enhance_assets_precompile
|
|
12
|
+
Rake::Task["assets:precompile"].enhance do
|
|
13
|
+
unless Rake::Task.task_defined?("yarn:install")
|
|
14
|
+
# For Rails < 5.1
|
|
15
|
+
Rake::Task["webpacker:yarn_install"].invoke
|
|
16
|
+
end
|
|
17
|
+
Rake::Task["webpacker:compile"].invoke
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
namespace :webpacker do
|
|
22
|
+
desc "Compile JavaScript packs using webpack for production with digests"
|
|
23
|
+
task compile: ["webpacker:verify_install", :environment] do
|
|
24
|
+
ensure_log_goes_to_stdout do
|
|
25
|
+
if Webpacker.compile
|
|
26
|
+
# Successful compilation!
|
|
27
|
+
else
|
|
28
|
+
# Failed compilation
|
|
29
|
+
exit!
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Compile packs after we've compiled all other assets during precompilation
|
|
36
|
+
if Rake::Task.task_defined?("assets:precompile")
|
|
37
|
+
skip_webpacker_precompile = %w(no false n f).include?(ENV["WEBPACKER_PRECOMPILE"])
|
|
38
|
+
enhance_assets_precompile unless skip_webpacker_precompile
|
|
39
|
+
else
|
|
40
|
+
Rake::Task.define_task("assets:precompile" => ["webpacker:yarn_install", "webpacker:compile"])
|
|
41
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
require "active_support/all"
|
|
2
|
+
|
|
3
|
+
namespace :webpacker do
|
|
4
|
+
desc "Install Webpacker in this application"
|
|
5
|
+
task install: [:check_node, :check_yarn] do
|
|
6
|
+
install_template_path = File.expand_path("../../install/template.rb", __dir__)
|
|
7
|
+
|
|
8
|
+
require "rails/generators"
|
|
9
|
+
require "rails/generators/rails/app/app_generator"
|
|
10
|
+
generator = Rails::Generators::AppGenerator.new [Jets.root], {force: ENV['FORCE']}, destination_root: Jets.root
|
|
11
|
+
generator.apply install_template_path, verbose: false
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
require "webpacker/configuration"
|
|
2
|
+
|
|
3
|
+
namespace :webpacker do
|
|
4
|
+
desc "Verifies if Webpacker is installed"
|
|
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
|
+
else
|
|
10
|
+
$stderr.puts "Configuration config/webpacker.yml file not found. \n"\
|
|
11
|
+
"Make sure webpacker:install is run successfully before " \
|
|
12
|
+
"running dependent tasks"
|
|
13
|
+
exit!
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|