jetpacker 0.1.0 → 0.2.0

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.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintignore +4 -0
  3. data/.eslintrc.js +14 -0
  4. data/.gitignore +11 -11
  5. data/.node-version +1 -0
  6. data/.rubocop.yml +125 -0
  7. data/.travis.yml +54 -5
  8. data/CHANGELOG.jetpacker.md +7 -0
  9. data/CHANGELOG.md +1000 -0
  10. data/CONTRIBUTING.md +33 -0
  11. data/Gemfile +9 -3
  12. data/Gemfile.lock +157 -21
  13. data/MIT-LICENSE +20 -0
  14. data/README.md +671 -16
  15. data/Rakefile +8 -3
  16. data/docs/assets.md +119 -0
  17. data/docs/cloud9.md +310 -0
  18. data/docs/css.md +253 -0
  19. data/docs/deployment.md +130 -0
  20. data/docs/docker.md +68 -0
  21. data/docs/engines.md +200 -0
  22. data/docs/env.md +65 -0
  23. data/docs/es6.md +72 -0
  24. data/docs/folder-structure.md +66 -0
  25. data/docs/misc.md +23 -0
  26. data/docs/props.md +223 -0
  27. data/docs/testing.md +137 -0
  28. data/docs/troubleshooting.md +156 -0
  29. data/docs/typescript.md +126 -0
  30. data/docs/v4-upgrade.md +142 -0
  31. data/docs/webpack-dev-server.md +92 -0
  32. data/docs/webpack.md +364 -0
  33. data/docs/yarn.md +23 -0
  34. data/gemfiles/Gemfile-rails-edge +12 -0
  35. data/gemfiles/Gemfile-rails.4.2.x +9 -0
  36. data/gemfiles/Gemfile-rails.5.0.x +9 -0
  37. data/gemfiles/Gemfile-rails.5.1.x +9 -0
  38. data/gemfiles/Gemfile-rails.5.2.x +9 -0
  39. data/gemfiles/Gemfile-rails.6.0.x +9 -0
  40. data/jetpacker.gemspec +28 -22
  41. data/lib/install/angular.rb +23 -0
  42. data/lib/install/bin/webpack +18 -0
  43. data/lib/install/bin/webpack-dev-server +18 -0
  44. data/lib/install/binstubs.rb +4 -0
  45. data/lib/install/coffee.rb +25 -0
  46. data/lib/install/config/.browserslistrc +1 -0
  47. data/lib/install/config/babel.config.js +72 -0
  48. data/lib/install/config/postcss.config.js +12 -0
  49. data/lib/install/config/webpack/development.js +5 -0
  50. data/lib/install/config/webpack/environment.js +3 -0
  51. data/lib/install/config/webpack/production.js +5 -0
  52. data/lib/install/config/webpack/test.js +5 -0
  53. data/lib/install/config/webpacker.yml +96 -0
  54. data/lib/install/elm.rb +39 -0
  55. data/lib/install/erb.rb +25 -0
  56. data/lib/install/examples/angular/hello_angular.js +7 -0
  57. data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
  58. data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
  59. data/lib/install/examples/angular/hello_angular/index.ts +8 -0
  60. data/lib/install/examples/angular/hello_angular/polyfills.ts +73 -0
  61. data/lib/install/examples/coffee/hello_coffee.coffee +4 -0
  62. data/lib/install/examples/elm/Main.elm +55 -0
  63. data/lib/install/examples/elm/hello_elm.js +16 -0
  64. data/lib/install/examples/erb/hello_erb.js.erb +6 -0
  65. data/lib/install/examples/react/babel.config.js +87 -0
  66. data/lib/install/examples/react/hello_react.jsx +26 -0
  67. data/lib/install/examples/react/tsconfig.json +20 -0
  68. data/lib/install/examples/stimulus/application.js +1 -0
  69. data/lib/install/examples/stimulus/controllers/hello_controller.js +18 -0
  70. data/lib/install/examples/stimulus/controllers/index.js +9 -0
  71. data/lib/install/examples/svelte/app.svelte +11 -0
  72. data/lib/install/examples/svelte/hello_svelte.js +20 -0
  73. data/lib/install/examples/typescript/hello_typescript.ts +4 -0
  74. data/lib/install/examples/typescript/tsconfig.json +23 -0
  75. data/lib/install/examples/vue/app.vue +22 -0
  76. data/lib/install/examples/vue/hello_vue.js +72 -0
  77. data/lib/install/javascript/packs/application.js +18 -0
  78. data/lib/install/loaders/coffee.js +6 -0
  79. data/lib/install/loaders/elm.js +25 -0
  80. data/lib/install/loaders/erb.js +11 -0
  81. data/lib/install/loaders/svelte.js +9 -0
  82. data/lib/install/loaders/typescript.js +11 -0
  83. data/lib/install/loaders/vue.js +6 -0
  84. data/lib/install/react.rb +18 -0
  85. data/lib/install/stimulus.rb +12 -0
  86. data/lib/install/svelte.rb +29 -0
  87. data/lib/install/template.rb +55 -0
  88. data/lib/install/typescript.rb +46 -0
  89. data/lib/install/vue.rb +49 -0
  90. data/lib/jetpacker/version.rb +2 -1
  91. data/lib/tasks/installers.rake +37 -0
  92. data/lib/tasks/webpacker.rake +28 -0
  93. data/lib/tasks/webpacker/binstubs.rake +11 -0
  94. data/lib/tasks/webpacker/check_binstubs.rake +12 -0
  95. data/lib/tasks/webpacker/check_node.rake +24 -0
  96. data/lib/tasks/webpacker/check_yarn.rake +24 -0
  97. data/lib/tasks/webpacker/clean.rake +21 -0
  98. data/lib/tasks/webpacker/clobber.rake +16 -0
  99. data/lib/tasks/webpacker/compile.rake +43 -0
  100. data/lib/tasks/webpacker/info.rake +20 -0
  101. data/lib/tasks/webpacker/install.rake +13 -0
  102. data/lib/tasks/webpacker/verify_install.rake +13 -0
  103. data/lib/tasks/webpacker/yarn_install.rake +21 -0
  104. data/lib/webpacker.rb +46 -0
  105. data/lib/webpacker/commands.rb +50 -0
  106. data/lib/webpacker/compiler.rb +107 -0
  107. data/lib/webpacker/configuration.rb +113 -0
  108. data/lib/webpacker/dev_server.rb +66 -0
  109. data/lib/webpacker/dev_server_proxy.rb +31 -0
  110. data/lib/webpacker/dev_server_runner.rb +72 -0
  111. data/lib/webpacker/env.rb +39 -0
  112. data/lib/webpacker/helper.rb +176 -0
  113. data/lib/webpacker/instance.rb +37 -0
  114. data/lib/webpacker/manifest.rb +118 -0
  115. data/lib/webpacker/railtie.rb +98 -0
  116. data/lib/webpacker/rake_tasks.rb +6 -0
  117. data/lib/webpacker/runner.rb +22 -0
  118. data/lib/webpacker/version.rb +4 -0
  119. data/lib/webpacker/webpack_runner.rb +32 -0
  120. data/package.json +82 -0
  121. data/package/__tests__/config.js +55 -0
  122. data/package/__tests__/dev_server.js +43 -0
  123. data/package/__tests__/development.js +30 -0
  124. data/package/__tests__/env.js +46 -0
  125. data/package/__tests__/production.js +29 -0
  126. data/package/__tests__/staging.js +29 -0
  127. data/package/__tests__/test.js +26 -0
  128. data/package/config.js +37 -0
  129. data/package/config_types/__tests__/config_list.js +118 -0
  130. data/package/config_types/__tests__/config_object.js +43 -0
  131. data/package/config_types/config_list.js +75 -0
  132. data/package/config_types/config_object.js +55 -0
  133. data/package/config_types/index.js +7 -0
  134. data/package/dev_server.js +20 -0
  135. data/package/env.js +19 -0
  136. data/package/environments/__tests__/base.js +74 -0
  137. data/package/environments/base.js +166 -0
  138. data/package/environments/development.js +51 -0
  139. data/package/environments/production.js +79 -0
  140. data/package/environments/test.js +3 -0
  141. data/package/index.js +24 -0
  142. data/package/rules/babel.js +21 -0
  143. data/package/rules/css.js +3 -0
  144. data/package/rules/file.js +20 -0
  145. data/package/rules/index.js +20 -0
  146. data/package/rules/module.css.js +3 -0
  147. data/package/rules/module.sass.js +8 -0
  148. data/package/rules/node_modules.js +24 -0
  149. data/package/rules/sass.js +8 -0
  150. data/package/utils/__tests__/deep_assign.js +32 -0
  151. data/package/utils/__tests__/deep_merge.js +10 -0
  152. data/package/utils/__tests__/get_style_rule.js +65 -0
  153. data/package/utils/__tests__/objectify.js +9 -0
  154. data/package/utils/deep_assign.js +22 -0
  155. data/package/utils/deep_merge.js +22 -0
  156. data/package/utils/get_style_rule.js +45 -0
  157. data/package/utils/helpers.js +58 -0
  158. data/package/utils/objectify.js +3 -0
  159. data/test/command_test.rb +33 -0
  160. data/test/compiler_test.rb +75 -0
  161. data/test/configuration_test.rb +108 -0
  162. data/test/dev_server_runner_test.rb +51 -0
  163. data/test/dev_server_test.rb +47 -0
  164. data/test/env_test.rb +23 -0
  165. data/test/helper_test.rb +142 -0
  166. data/test/manifest_test.rb +42 -0
  167. data/test/rake_tasks_test.rb +69 -0
  168. data/test/test_app/Rakefile +3 -0
  169. data/test/test_app/app/javascript/packs/application.js +10 -0
  170. data/test/test_app/bin/webpack +14 -0
  171. data/test/test_app/bin/webpack-dev-server +14 -0
  172. data/test/test_app/config.ru +5 -0
  173. data/test/test_app/config/application.rb +12 -0
  174. data/test/test_app/config/environment.rb +4 -0
  175. data/test/test_app/config/webpack/development.js +0 -0
  176. data/test/test_app/config/webpacker.yml +97 -0
  177. data/test/test_app/config/webpacker_public_root.yml +19 -0
  178. data/test/test_app/package.json +13 -0
  179. data/test/test_app/public/packs/manifest.json +31 -0
  180. data/test/test_app/yarn.lock +11 -0
  181. data/test/test_helper.rb +33 -0
  182. data/test/webpack_runner_test.rb +51 -0
  183. data/test/webpacker_test.rb +13 -0
  184. data/yarn.lock +8321 -0
  185. metadata +267 -29
  186. data/.rspec +0 -3
  187. data/LICENSE.txt +0 -21
  188. data/bin/console +0 -14
  189. data/bin/setup +0 -8
  190. data/lib/jetpacker.rb +0 -6
@@ -0,0 +1,72 @@
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
+ const app = new Vue({
13
+ render: h => h(App)
14
+ }).$mount()
15
+ document.body.appendChild(app.$el)
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 project is 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
+ // return {
67
+ // message: "Can you say hello?"
68
+ // }
69
+ // },
70
+ // components: { App }
71
+ // })
72
+ // })
@@ -0,0 +1,18 @@
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
+
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
+
18
+ console.log('Hello World from Webpacker')
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ test: /\.coffee(\.erb)?$/,
3
+ use: [{
4
+ loader: 'coffee-loader'
5
+ }]
6
+ }
@@ -0,0 +1,25 @@
1
+ const { resolve } = require('path')
2
+
3
+ const isProduction = process.env.NODE_ENV === 'production'
4
+ const isDevelopment = process.env.NODE_ENV === 'development'
5
+ const elmSource = resolve(process.cwd())
6
+ const elmBinary = `${elmSource}/node_modules/.bin/elm`
7
+
8
+ const options = {
9
+ cwd: elmSource,
10
+ pathToElm: elmBinary,
11
+ optimize: isProduction,
12
+ verbose: isDevelopment,
13
+ debug: isDevelopment
14
+ }
15
+
16
+ const elmWebpackLoader = {
17
+ loader: 'elm-webpack-loader',
18
+ options: options
19
+ }
20
+
21
+ module.exports = {
22
+ test: /\.elm(\.erb)?$/,
23
+ exclude: [/elm-stuff/, /node_modules/],
24
+ use: isProduction ? [elmWebpackLoader] : [{ loader: 'elm-hot-webpack-loader' }, elmWebpackLoader]
25
+ }
@@ -0,0 +1,11 @@
1
+ module.exports = {
2
+ test: /\.erb$/,
3
+ enforce: 'pre',
4
+ exclude: /node_modules/,
5
+ use: [{
6
+ loader: 'rails-erb-loader',
7
+ options: {
8
+ runner: (/^win/.test(process.platform) ? 'ruby ' : '') + 'bin/rails runner'
9
+ }
10
+ }]
11
+ }
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ test: /\.svelte$/,
3
+ use: [{
4
+ loader: 'svelte-loader',
5
+ options: {
6
+ hotReload: true
7
+ }
8
+ }],
9
+ }
@@ -0,0 +1,11 @@
1
+ const PnpWebpackPlugin = require('pnp-webpack-plugin')
2
+
3
+ module.exports = {
4
+ test: /\.tsx?(\.erb)?$/,
5
+ use: [
6
+ {
7
+ loader: 'ts-loader',
8
+ options: PnpWebpackPlugin.tsLoaderOptions()
9
+ }
10
+ ]
11
+ }
@@ -0,0 +1,6 @@
1
+ module.exports = {
2
+ test: /\.vue(\.erb)?$/,
3
+ use: [{
4
+ loader: 'vue-loader'
5
+ }]
6
+ }
@@ -0,0 +1,18 @@
1
+ require "webpacker/configuration"
2
+ require "fileutils"
3
+
4
+ replace_babel_config = FileUtils.compare_file(Jets.root.join("babel.config.js"), "#{__dir__}/config/babel.config.js")
5
+
6
+ say "Copying babel.config.js to app root directory"
7
+ copy_file "#{__dir__}/examples/react/babel.config.js", "babel.config.js", force: replace_babel_config
8
+
9
+ say "Copying react example entry file to #{Webpacker.config.source_entry_path}"
10
+ copy_file "#{__dir__}/examples/react/hello_react.jsx", "#{Webpacker.config.source_entry_path}/hello_react.jsx"
11
+
12
+ say "Updating webpack paths to include .jsx file extension"
13
+ insert_into_file Webpacker.config.config_path, "- .jsx\n".indent(4), after: /\s+extensions:\n/
14
+
15
+ say "Installing all react dependencies"
16
+ run "yarn add react react-dom @babel/preset-react prop-types babel-plugin-transform-react-remove-prop-types"
17
+
18
+ say "Webpacker now supports react.js 🎉", :green
@@ -0,0 +1,12 @@
1
+ say "Appending Stimulus setup code to #{Webpacker.config.source_entry_path}/application.js"
2
+ append_to_file "#{Webpacker.config.source_entry_path}/application.js" do
3
+ "\n" + open("#{__dir__}/examples/stimulus/application.js").read
4
+ end
5
+
6
+ say "Creating controllers directory"
7
+ directory "#{__dir__}/examples/stimulus/controllers", "#{Webpacker.config.source_path}/controllers"
8
+
9
+ say "Installing all Stimulus dependencies"
10
+ run "yarn add stimulus"
11
+
12
+ say "Webpacker now supports Stimulus.js 🎉", :green
@@ -0,0 +1,29 @@
1
+ require "webpacker/configuration"
2
+
3
+ say "Copying svelte loader to config/webpack/loaders"
4
+ copy_file "#{__dir__}/loaders/svelte.js", Jets.root.join("config/webpack/loaders/svelte.js").to_s
5
+
6
+ say "Adding svelte loader to config/webpack/environment.js"
7
+ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
8
+ "const svelte = require('./loaders/svelte')\n",
9
+ after: /require\(('|")@rails\/webpacker\1\);?\n/
10
+
11
+ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
12
+ "environment.loaders.prepend('svelte', svelte)\n",
13
+ before: "module.exports"
14
+
15
+ say "Copying Svelte example entry file to #{Webpacker.config.source_entry_path}"
16
+ copy_file "#{__dir__}/examples/svelte/hello_svelte.js",
17
+ "#{Webpacker.config.source_entry_path}/hello_svelte.js"
18
+
19
+ say "Copying Svelte app file to #{Webpacker.config.source_path}"
20
+ copy_file "#{__dir__}/examples/svelte/app.svelte",
21
+ "#{Webpacker.config.source_path}/app.svelte"
22
+
23
+ say "Installing all Svelte dependencies"
24
+ run "yarn add svelte svelte-loader"
25
+
26
+ say "Updating webpack paths to include .svelte file extension"
27
+ insert_into_file Webpacker.config.config_path, "- .svelte\n".indent(4), after: /\s+extensions:\n/
28
+
29
+ say "Webpacker now supports Svelte 🎉", :green
@@ -0,0 +1,55 @@
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 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
+ if Dir.exists?(Webpacker.config.source_path)
17
+ say "The JavaScript app source directory already exists"
18
+ else
19
+ say "Creating JavaScript app source directory"
20
+ directory "#{__dir__}/javascript", Webpacker.config.source_path
21
+ end
22
+
23
+ apply "#{__dir__}/binstubs.rb"
24
+
25
+ if File.exists?(".gitignore")
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
35
+ end
36
+
37
+ if Webpacker::VERSION =~ /^[0-9]+\.[0-9]+\.[0-9]+$/
38
+ say "Installing all JavaScript dependencies [#{Webpacker::VERSION}]"
39
+ run "yarn add @rails/webpacker@#{Webpacker::VERSION}"
40
+ else
41
+ say "Installing all JavaScript dependencies [from prerelease rails/webpacker]"
42
+ run "yarn add @rails/webpacker@next"
43
+ end
44
+
45
+ say "Installing dev server for live reloading"
46
+ run "yarn add --dev webpack-dev-server"
47
+
48
+ if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
49
+ say "You need to allow webpack-dev-server host as allowed origin for connect-src.", :yellow
50
+ say "This can be done in Rails 5.2+ for development environment in the CSP initializer", :yellow
51
+ say "config/initializers/content_security_policy.rb with a snippet like this:", :yellow
52
+ say "policy.connect_src :self, :https, \"http://localhost:3035\", \"ws://localhost:3035\" if Jets.env.development?", :yellow
53
+ end
54
+
55
+ say "Webpacker successfully installed 🎉 🍰", :green
@@ -0,0 +1,46 @@
1
+ require "webpacker/configuration"
2
+
3
+ additional_packages = ""
4
+ example_source = "typescript"
5
+
6
+ # Additional configuration is required for React projects
7
+ package_json = Jets.root.join("package.json")
8
+ if File.exist?(package_json)
9
+ package = JSON.parse(File.read(package_json))
10
+ package["dependencies"] ||= {}
11
+
12
+ if package["dependencies"].keys.include?("react")
13
+ additional_packages = "@types/react @types/react-dom"
14
+ example_source = "react"
15
+ end
16
+ end
17
+
18
+ say "Copying typescript loader to config/webpack/loaders"
19
+ copy_file "#{__dir__}/loaders/typescript.js", Jets.root.join("config/webpack/loaders/typescript.js").to_s
20
+
21
+ say "Adding typescript loader to config/webpack/environment.js"
22
+ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
23
+ "const typescript = require('./loaders/typescript')\n",
24
+ after: /require\(('|")@rails\/webpacker\1\);?\n/
25
+
26
+ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
27
+ "environment.loaders.prepend('typescript', typescript)\n",
28
+ before: "module.exports"
29
+
30
+ say "Copying tsconfig.json to the Rails root directory for typescript"
31
+ copy_file "#{__dir__}/examples/#{example_source}/tsconfig.json", "tsconfig.json"
32
+
33
+ say "Updating webpack paths to include .ts file extension"
34
+ insert_into_file Webpacker.config.config_path, "- .ts\n".indent(4), after: /\s+extensions:\n/
35
+
36
+ say "Updating webpack paths to include .tsx file extension"
37
+ insert_into_file Webpacker.config.config_path, "- .tsx\n".indent(4), after: /\s+extensions:\n/
38
+
39
+ say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
40
+ copy_file "#{__dir__}/examples/typescript/hello_typescript.ts",
41
+ "#{Webpacker.config.source_entry_path}/hello_typescript.ts"
42
+
43
+ say "Installing all typescript dependencies"
44
+ run "yarn add typescript ts-loader #{additional_packages}"
45
+
46
+ say "Webpacker now supports typescript 🎉", :green
@@ -0,0 +1,49 @@
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 plugin to config/webpack/environment.js"
7
+ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
8
+ "const { VueLoaderPlugin } = require('vue-loader')\n",
9
+ after: /require\(('|")@rails\/webpacker\1\);?\n/
10
+
11
+ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
12
+ "environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin())\n",
13
+ before: "module.exports"
14
+
15
+ say "Adding vue loader to config/webpack/environment.js"
16
+ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
17
+ "const vue = require('./loaders/vue')\n",
18
+ after: "require('vue-loader')\n"
19
+
20
+ insert_into_file Jets.root.join("config/webpack/environment.js").to_s,
21
+ "environment.loaders.prepend('vue', vue)\n",
22
+ before: "module.exports"
23
+
24
+ say "Updating webpack paths to include .vue file extension"
25
+ insert_into_file Webpacker.config.config_path, "- .vue\n".indent(4), after: /\s+extensions:\n/
26
+
27
+ say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
28
+ copy_file "#{__dir__}/examples/vue/hello_vue.js",
29
+ "#{Webpacker.config.source_entry_path}/hello_vue.js"
30
+
31
+ say "Copying Vue app file to #{Webpacker.config.source_entry_path}"
32
+ copy_file "#{__dir__}/examples/vue/app.vue",
33
+ "#{Webpacker.config.source_path}/app.vue"
34
+
35
+ say "Installing all Vue dependencies"
36
+ run "yarn add vue vue-loader vue-template-compiler"
37
+
38
+ if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
39
+ say "You need to enable unsafe-eval rule.", :yellow
40
+ say "This can be done in Rails 5.2+ for development environment in the CSP initializer", :yellow
41
+ say "config/initializers/content_security_policy.rb with a snippet like this:", :yellow
42
+ say "if Jets.env.development?", :yellow
43
+ say " policy.script_src :self, :https, :unsafe_eval", :yellow
44
+ say "else", :yellow
45
+ say " policy.script_src :self, :https", :yellow
46
+ say "end", :yellow
47
+ end
48
+
49
+ say "Webpacker now supports Vue.js 🎉", :green
@@ -1,3 +1,4 @@
1
+ # Separate version from Webpacker version for the jetpacker gem
1
2
  module Jetpacker
2
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
3
4
  end
@@ -0,0 +1,37 @@
1
+ installers = {
2
+ "Angular": :angular,
3
+ "Elm": :elm,
4
+ "React": :react,
5
+ "Vue": :vue,
6
+ "Erb": :erb,
7
+ "Coffee": :coffee,
8
+ "Typescript": :typescript,
9
+ "Svelte": :svelte,
10
+ "Stimulus": :stimulus
11
+ }.freeze
12
+
13
+ dependencies = {
14
+ "Angular": [:typescript]
15
+ }
16
+
17
+ namespace :webpacker do
18
+ namespace :install do
19
+ installers.each do |name, task_name|
20
+ desc "Install everything needed for #{name}"
21
+ task task_name => ["webpacker:verify_install"] do
22
+ require "rails/generators"
23
+ require "rails/generators/rails/app/app_generator"
24
+ generator = Rails::Generators::AppGenerator.new [Jets.root], {force: ENV['FORCE']}, destination_root: Jets.root
25
+
26
+ template = File.expand_path("../install/#{task_name}.rb", __dir__)
27
+ generator.apply template, verbose: false
28
+
29
+ dependencies[name] ||= []
30
+ dependencies[name].each do |dependency|
31
+ dependency_template = File.expand_path("../install/#{dependency}.rb", __dir__)
32
+ generator.apply dependency_template, verbose: false
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,28 @@
1
+ tasks = {
2
+ "webpacker:info" => "Provides information on Webpacker's environment",
3
+ "webpacker:install" => "Installs and setup webpack with Yarn",
4
+ "webpacker:compile" => "Compiles webpack bundles based on environment",
5
+ "webpacker:clean" => "Remove old compiled webpacks",
6
+ "webpacker:clobber" => "Removes the webpack compiled output directory",
7
+ "webpacker:check_node" => "Verifies if Node.js is installed",
8
+ "webpacker:check_yarn" => "Verifies if Yarn is installed",
9
+ "webpacker:check_binstubs" => "Verifies that webpack & webpack-dev-server are present",
10
+ "webpacker:binstubs" => "Installs Webpacker binstubs in this application",
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"
22
+ }.freeze
23
+
24
+ desc "Lists all available tasks in Webpacker"
25
+ task :webpacker do
26
+ puts "Available Webpacker tasks are:"
27
+ tasks.each { |task, message| puts task.ljust(30) + message }
28
+ end