webpacker-legacy 0.1.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 (79) hide show
  1. checksums.yaml +15 -0
  2. data/.eslintrc.js +14 -0
  3. data/.gitignore +4 -0
  4. data/.rubocop.yml +124 -0
  5. data/.travis.yml +22 -0
  6. data/CHANGELOG.md +148 -0
  7. data/Gemfile +11 -0
  8. data/Gemfile.lock +137 -0
  9. data/MIT-LICENSE +20 -0
  10. data/README.md +1118 -0
  11. data/Rakefile +12 -0
  12. data/lib/install/angular.rb +22 -0
  13. data/lib/install/bin/webpack-dev-server.tt +43 -0
  14. data/lib/install/bin/webpack.tt +27 -0
  15. data/lib/install/config/.babelrc +17 -0
  16. data/lib/install/config/.postcssrc.yml +3 -0
  17. data/lib/install/config/loaders/core/assets.js +12 -0
  18. data/lib/install/config/loaders/core/babel.js +5 -0
  19. data/lib/install/config/loaders/core/coffee.js +4 -0
  20. data/lib/install/config/loaders/core/erb.js +9 -0
  21. data/lib/install/config/loaders/core/sass.js +15 -0
  22. data/lib/install/config/loaders/installers/angular.js +4 -0
  23. data/lib/install/config/loaders/installers/elm.js +20 -0
  24. data/lib/install/config/loaders/installers/react.js +5 -0
  25. data/lib/install/config/loaders/installers/vue.js +41 -0
  26. data/lib/install/config/webpack/configuration.js +35 -0
  27. data/lib/install/config/webpack/development.js +32 -0
  28. data/lib/install/config/webpack/production.js +35 -0
  29. data/lib/install/config/webpack/shared.js +58 -0
  30. data/lib/install/config/webpack/test.js +6 -0
  31. data/lib/install/config/webpacker.yml +38 -0
  32. data/lib/install/elm.rb +33 -0
  33. data/lib/install/examples/angular/hello_angular.js +7 -0
  34. data/lib/install/examples/angular/hello_angular/app/app.component.ts +9 -0
  35. data/lib/install/examples/angular/hello_angular/app/app.module.ts +16 -0
  36. data/lib/install/examples/angular/hello_angular/index.ts +6 -0
  37. data/lib/install/examples/angular/hello_angular/polyfills.ts +19 -0
  38. data/lib/install/examples/angular/tsconfig.json +19 -0
  39. data/lib/install/examples/elm/Main.elm +54 -0
  40. data/lib/install/examples/elm/hello_elm.js +11 -0
  41. data/lib/install/examples/react/.babelrc +6 -0
  42. data/lib/install/examples/react/hello_react.jsx +26 -0
  43. data/lib/install/examples/vue/app.vue +22 -0
  44. data/lib/install/examples/vue/hello_vue.js +15 -0
  45. data/lib/install/javascript/packs/application.js +10 -0
  46. data/lib/install/react.rb +36 -0
  47. data/lib/install/template.rb +44 -0
  48. data/lib/install/vue.rb +19 -0
  49. data/lib/tasks/installers.rake +22 -0
  50. data/lib/tasks/webpacker.rake +19 -0
  51. data/lib/tasks/webpacker/check_node.rake +20 -0
  52. data/lib/tasks/webpacker/check_webpack_binstubs.rake +11 -0
  53. data/lib/tasks/webpacker/check_yarn.rake +15 -0
  54. data/lib/tasks/webpacker/clobber.rake +17 -0
  55. data/lib/tasks/webpacker/compile.rake +38 -0
  56. data/lib/tasks/webpacker/install.rake +23 -0
  57. data/lib/tasks/webpacker/verify_install.rake +18 -0
  58. data/lib/tasks/webpacker/yarn_install.rake +6 -0
  59. data/lib/webpacker-legacy.rb +2 -0
  60. data/lib/webpacker.rb +40 -0
  61. data/lib/webpacker/compiler.rb +20 -0
  62. data/lib/webpacker/configuration.rb +60 -0
  63. data/lib/webpacker/env.rb +23 -0
  64. data/lib/webpacker/file_loader.rb +24 -0
  65. data/lib/webpacker/helper.rb +62 -0
  66. data/lib/webpacker/manifest.rb +51 -0
  67. data/lib/webpacker/railtie.rb +18 -0
  68. data/lib/webpacker/version.rb +3 -0
  69. data/package.json +31 -0
  70. data/test/configuration_test.rb +32 -0
  71. data/test/env_test.rb +14 -0
  72. data/test/helper_test.rb +23 -0
  73. data/test/manifest_test.rb +30 -0
  74. data/test/test_app/config/secrets.yml +5 -0
  75. data/test/test_app/public/packs/manifest.json +4 -0
  76. data/test/webpacker_test.rb +15 -0
  77. data/webpacker.gemspec +23 -0
  78. data/yarn.lock +1014 -0
  79. metadata +200 -0
@@ -0,0 +1,33 @@
1
+ # encoding: UTF-8
2
+
3
+ require "webpacker/configuration"
4
+
5
+ current_dir = File.dirname(__FILE__)
6
+
7
+ puts "Copying elm loader to config/webpack/loaders"
8
+ copy_file "#{current_dir}/config/loaders/installers/elm.js",
9
+ "config/webpack/loaders/elm.js"
10
+
11
+ puts "Copying elm example entry file to #{Webpacker::Configuration.entry_path}"
12
+ copy_file "#{current_dir}/examples/elm/Main.elm", "#{Webpacker::Configuration.entry_path}/Main.elm"
13
+
14
+ puts "Copying elm app file to #{Webpacker::Configuration.entry_path}"
15
+ copy_file "#{current_dir}/examples/elm/hello_elm.js",
16
+ "#{Webpacker::Configuration.entry_path}/hello_elm.js"
17
+
18
+ puts "Installing all elm dependencies"
19
+ run "yarn add elm elm-webpack-loader"
20
+ run "yarn add --dev elm-hot-loader"
21
+ run "yarn run elm package install -- --yes"
22
+
23
+ puts "Updating Webpack paths to include Elm file extension"
24
+ insert_into_file Webpacker::Configuration.file_path, " - .elm\n", after: /extensions:\n/
25
+
26
+ puts "Updating elm source location"
27
+ source_path = File.join(Webpacker::Configuration.source, Webpacker::Configuration.fetch(:source_entry_path))
28
+ gsub_file "elm-package.json", /\"\.\"\n/, %("#{source_path}"\n)
29
+
30
+ puts "Updating .gitignore to include elm-stuff folder"
31
+ insert_into_file ".gitignore", "/elm-stuff\n", before: "/node_modules\n"
32
+
33
+ puts "Webpacker now supports elm 🎉"
@@ -0,0 +1,7 @@
1
+ // Run this Angular example by adding the following HTML markup to your view:
2
+ //
3
+ // <hello-angular>Loading...</hello-angular>
4
+ //
5
+ // <%= javascript_pack_tag 'hello_angular' %>
6
+
7
+ require('../hello_angular')
@@ -0,0 +1,9 @@
1
+ import { Component } from '@angular/core';
2
+
3
+ @Component({
4
+ selector: 'hello-angular',
5
+ template: `<h1>Hello {{name}}</h1>`
6
+ })
7
+ export class AppComponent {
8
+ name = 'Angular!';
9
+ }
@@ -0,0 +1,16 @@
1
+ import { BrowserModule } from '@angular/platform-browser';
2
+ import { NgModule } from '@angular/core';
3
+
4
+ import { AppComponent } from './app.component';
5
+
6
+ @NgModule({
7
+ declarations: [
8
+ AppComponent
9
+ ],
10
+ imports: [
11
+ BrowserModule
12
+ ],
13
+ providers: [],
14
+ bootstrap: [AppComponent]
15
+ })
16
+ export class AppModule { }
@@ -0,0 +1,6 @@
1
+ import './polyfills.ts';
2
+
3
+ import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
4
+ import { AppModule } from './app/app.module';
5
+
6
+ platformBrowserDynamic().bootstrapModule(AppModule);
@@ -0,0 +1,19 @@
1
+ // This file includes polyfills needed by Angular and is loaded before
2
+ // the app. You can add your own extra polyfills to this file.
3
+ import 'core-js/es6/symbol';
4
+ import 'core-js/es6/object';
5
+ import 'core-js/es6/function';
6
+ import 'core-js/es6/parse-int';
7
+ import 'core-js/es6/parse-float';
8
+ import 'core-js/es6/number';
9
+ import 'core-js/es6/math';
10
+ import 'core-js/es6/string';
11
+ import 'core-js/es6/date';
12
+ import 'core-js/es6/array';
13
+ import 'core-js/es6/regexp';
14
+ import 'core-js/es6/map';
15
+ import 'core-js/es6/set';
16
+ import 'core-js/es6/reflect';
17
+
18
+ import 'core-js/es7/reflect';
19
+ import 'zone.js/dist/zone';
@@ -0,0 +1,19 @@
1
+ {
2
+ "compilerOptions": {
3
+ "declaration": false,
4
+ "emitDecoratorMetadata": true,
5
+ "experimentalDecorators": true,
6
+ "lib": ["es6", "dom"],
7
+ "module": "es6",
8
+ "moduleResolution": "node",
9
+ "sourceMap": true,
10
+ "target": "es5"
11
+ },
12
+ "exclude": [
13
+ "**/*.spec.ts",
14
+ "node_modules",
15
+ "vendor",
16
+ "public"
17
+ ],
18
+ "compileOnSave": false
19
+ }
@@ -0,0 +1,54 @@
1
+ module Main exposing (..)
2
+
3
+ import Html exposing (Html, h1, text)
4
+ import Html.Attributes exposing (style)
5
+
6
+ -- MODEL
7
+
8
+ type alias Model =
9
+ {
10
+ }
11
+
12
+ -- INIT
13
+
14
+ init : (Model, Cmd Message)
15
+ init =
16
+ (Model, Cmd.none)
17
+
18
+ -- VIEW
19
+
20
+ view : Model -> Html Message
21
+ view model =
22
+ -- The inline style is being used for example purposes in order to keep this example simple and
23
+ -- avoid loading additional resources. Use a proper stylesheet when building your own app.
24
+ h1 [style [("display", "flex"), ("justify-content", "center")]]
25
+ [text "Hello Elm!"]
26
+
27
+ -- MESSAGE
28
+
29
+ type Message
30
+ = None
31
+
32
+ -- UPDATE
33
+
34
+ update : Message -> Model -> (Model, Cmd Message)
35
+ update message model =
36
+ (model, Cmd.none)
37
+
38
+ -- SUBSCRIPTIONS
39
+
40
+ subscriptions : Model -> Sub Message
41
+ subscriptions model =
42
+ Sub.none
43
+
44
+ -- MAIN
45
+
46
+ main : Program Never Model Message
47
+ main =
48
+ Html.program
49
+ {
50
+ init = init,
51
+ view = view,
52
+ update = update,
53
+ subscriptions = subscriptions
54
+ }
@@ -0,0 +1,11 @@
1
+ // Run this example by adding <%= javascript_pack_tag "hello_elm" %> to the head of your layout
2
+ // file, like app/views/layouts/application.html.erb. It will render "Hello Elm!" within the page.
3
+
4
+ import Elm from './Main'
5
+
6
+ document.addEventListener('DOMContentLoaded', () => {
7
+ const target = document.createElement('div')
8
+
9
+ document.body.appendChild(target)
10
+ Elm.Main.embed(target)
11
+ })
@@ -0,0 +1,6 @@
1
+ {
2
+ "presets": [
3
+ ["env", { "modules": false } ],
4
+ "react"
5
+ ]
6
+ }
@@ -0,0 +1,26 @@
1
+ // Run this example by adding <%= javascript_pack_tag 'hello_react' %> to the head of your layout file,
2
+ // like app/views/layouts/application.html.erb. All it does is render <div>Hello React</div> at the bottom
3
+ // of the page.
4
+
5
+ import React from 'react'
6
+ import ReactDOM from 'react-dom'
7
+ import PropTypes from 'prop-types'
8
+
9
+ const Hello = props => (
10
+ <div>Hello {props.name}!</div>
11
+ )
12
+
13
+ Hello.defaultProps = {
14
+ name: 'David'
15
+ }
16
+
17
+ Hello.propTypes = {
18
+ name: PropTypes.string
19
+ }
20
+
21
+ document.addEventListener('DOMContentLoaded', () => {
22
+ ReactDOM.render(
23
+ <Hello name="React" />,
24
+ document.body.appendChild(document.createElement('div')),
25
+ )
26
+ })
@@ -0,0 +1,22 @@
1
+ <template>
2
+ <div id="app">
3
+ <p>{{ message }}</p>
4
+ </div>
5
+ </template>
6
+
7
+ <script>
8
+ export default {
9
+ data: function () {
10
+ return {
11
+ message: "Hello Vue!"
12
+ }
13
+ }
14
+ }
15
+ </script>
16
+
17
+ <style scoped>
18
+ p {
19
+ font-size: 2em;
20
+ text-align: center;
21
+ }
22
+ </style>
@@ -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' %> to the head of your layout file,
4
+ // like app/views/layouts/application.html.erb.
5
+ // All it does is render <div>Hello Vue</div> at the bottom of the page.
6
+
7
+ import Vue from 'vue'
8
+ import App from './app.vue'
9
+
10
+ document.addEventListener('DOMContentLoaded', () => {
11
+ document.body.appendChild(document.createElement('hello'))
12
+ const app = new Vue(App).$mount('hello')
13
+
14
+ console.log(app)
15
+ })
@@ -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,36 @@
1
+ # encoding: UTF-8
2
+
3
+ require "webpacker/configuration"
4
+
5
+
6
+ current_dir = File.dirname(__FILE__)
7
+
8
+ babelrc = Rails.root.join(".babelrc")
9
+
10
+ if File.exist?(babelrc)
11
+ react_babelrc = JSON.parse(File.read(babelrc))
12
+ react_babelrc["presets"] ||= []
13
+
14
+ unless react_babelrc["presets"].include?("react")
15
+ react_babelrc["presets"].push("react")
16
+ puts "Copying react preset to your .babelrc file"
17
+
18
+ File.open(babelrc, "w") do |f|
19
+ f.puts JSON.pretty_generate(react_babelrc)
20
+ end
21
+ end
22
+ else
23
+ puts "Copying .babelrc to app root directory"
24
+ copy_file "#{current_dir}/examples/react/.babelrc", ".babelrc"
25
+ end
26
+
27
+ puts "Copying react loader to config/webpack/loaders"
28
+ copy_file "#{current_dir}/config/loaders/installers/react.js", "config/webpack/loaders/react.js"
29
+
30
+ puts "Copying react example entry file to #{Webpacker::Configuration.entry_path}"
31
+ copy_file "#{current_dir}/examples/react/hello_react.jsx", "#{Webpacker::Configuration.entry_path}/hello_react.jsx"
32
+
33
+ puts "Installing all react dependencies"
34
+ run "yarn add react react-dom babel-preset-react prop-types"
35
+
36
+ puts "Webpacker now supports react.js 🎉"
@@ -0,0 +1,44 @@
1
+ # encoding: UTF-8
2
+
3
+ # Install webpacker
4
+ current_dir = File.dirname(__FILE__)
5
+
6
+ copy_file "#{current_dir}/config/webpacker.yml", "config/webpacker.yml"
7
+
8
+ puts "Copying webpack core config and loaders"
9
+ directory "#{current_dir}/config/webpack", "config/webpack"
10
+ directory "#{current_dir}/config/loaders/core", "config/webpack/loaders"
11
+
12
+ puts "Copying .postcssrc.yml to app root directory"
13
+ copy_file "#{current_dir}/config/.postcssrc.yml", ".postcssrc.yml"
14
+
15
+ puts "Copying .babelrc to app root directory"
16
+ copy_file "#{current_dir}/config/.babelrc", ".babelrc"
17
+
18
+ puts "Creating javascript app source directory"
19
+ directory "#{current_dir}/javascript", "#{Webpacker::Configuration.source}"
20
+
21
+ puts "Copying binstubs"
22
+ directory "#{current_dir}/bin", "bin"
23
+
24
+ chmod "bin", 0755 & ~File.umask, verbose: false
25
+
26
+ if File.exists?(".gitignore")
27
+ append_to_file ".gitignore", <<-EOS
28
+ /public/packs
29
+ /node_modules
30
+ EOS
31
+ end
32
+
33
+ puts "Installing all JavaScript dependencies"
34
+ run "yarn add webpack webpack-merge js-yaml path-complete-extname " \
35
+ "webpack-manifest-plugin babel-loader@7.x coffee-loader coffee-script " \
36
+ "babel-core babel-preset-env babel-polyfill compression-webpack-plugin rails-erb-loader glob " \
37
+ "extract-text-webpack-plugin node-sass file-loader sass-loader css-loader style-loader " \
38
+ "postcss-loader postcss-cssnext postcss-smart-import resolve-url-loader " \
39
+ "babel-plugin-syntax-dynamic-import babel-plugin-transform-class-properties"
40
+
41
+ puts "Installing dev server for live reloading"
42
+ run "yarn add --dev webpack-dev-server"
43
+
44
+ puts "Webpacker successfully installed 🎉 🍰"
@@ -0,0 +1,19 @@
1
+ # encoding: UTF-8
2
+
3
+ require "webpacker/configuration"
4
+
5
+ current_dir = File.dirname(__FILE__)
6
+
7
+ puts "Copying vue loader to config/webpack/loaders"
8
+ copy_file "#{current_dir}/config/loaders/installers/vue.js", "config/webpack/loaders/vue.js"
9
+
10
+ puts "Copying the example entry file to #{Webpacker::Configuration.entry_path}"
11
+ copy_file "#{current_dir}/examples/vue/hello_vue.js", "#{Webpacker::Configuration.entry_path}/hello_vue.js"
12
+
13
+ puts "Copying vue app file to #{Webpacker::Configuration.entry_path}"
14
+ copy_file "#{current_dir}/examples/vue/app.vue", "#{Webpacker::Configuration.entry_path}/app.vue"
15
+
16
+ puts "Installing all vue dependencies"
17
+ run "yarn add vue vue-loader vue-template-compiler"
18
+
19
+ puts "Webpacker now supports vue.js 🎉"
@@ -0,0 +1,22 @@
1
+ INSTALLERS = {
2
+ Angular: :angular,
3
+ Elm: :elm,
4
+ React: :react,
5
+ Vue: :vue
6
+ }.freeze
7
+
8
+ namespace :webpacker do
9
+ namespace :install do
10
+ INSTALLERS.each do |name, task_name|
11
+ desc "Install everything needed for #{name}"
12
+ task task_name => ["webpacker:verify_install"] do
13
+ template = File.expand_path("../install/#{task_name}.rb", File.dirname(__FILE__))
14
+ if Rails::VERSION::MAJOR >= 5
15
+ exec "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{template}"
16
+ else
17
+ exec "rake rails:template LOCATION=#{template}"
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ tasks = {
2
+ "webpacker:install" => "Installs and setup webpack with yarn",
3
+ "webpacker:compile" => "Compiles webpack bundles based on environment",
4
+ "webpacker:check_node" => "Verifies if Node.js is installed",
5
+ "webpacker:check_yarn" => "Verifies if yarn is installed",
6
+ "webpacker:check_webpack_binstubs" => "Verifies that bin/webpack & bin/webpack-dev-server are present",
7
+ "webpacker:verify_install" => "Verifies if webpacker is installed",
8
+ "webpacker:yarn_install" => "Support for older Rails versions. Install all JavaScript dependencies as specified via Yarn",
9
+ "webpacker:install:react" => "Installs and setup example React component",
10
+ "webpacker:install:vue" => "Installs and setup example Vue component",
11
+ "webpacker:install:angular" => "Installs and setup example Angular component",
12
+ "webpacker:install:elm" => "Installs and setup example Elm component"
13
+ }.freeze
14
+
15
+ desc "Lists all available tasks in webpacker"
16
+ task :webpacker do
17
+ puts "Available webpacker tasks are:"
18
+ tasks.each { |task, message| puts task.ljust(30) + message }
19
+ end
@@ -0,0 +1,20 @@
1
+ namespace :webpacker do
2
+ desc "Verifies if Node.js is installed"
3
+ task :check_node do
4
+ begin
5
+ node_version = `node -v`
6
+ node_version = `nodejs -v` if node_version.blank?
7
+ required_node_version = "6.4"
8
+
9
+ raise Errno::ENOENT if node_version.blank?
10
+ if Gem::Version.new(node_version.strip.tr("v", "")) < Gem::Version.new(required_node_version)
11
+ puts "Webpacker requires Node.js >= v#{required_node_version} and you are using #{node_version}"
12
+ puts "Please upgrade Node.js https://nodejs.org/en/download/"
13
+ puts "Exiting!" && exit!
14
+ end
15
+ rescue Errno::ENOENT
16
+ puts "Node.js not installed. Please download and install Node.js https://nodejs.org/en/download/"
17
+ puts "Exiting!" && exit!
18
+ end
19
+ end
20
+ end