webpacker-react-on-rails 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.
- checksums.yaml +7 -0
- data/.eslintrc.js +14 -0
- data/.gitignore +4 -0
- data/.rubocop.yml +124 -0
- data/.travis.yml +22 -0
- data/CHANGELOG.md +208 -0
- data/Gemfile +21 -0
- data/Gemfile.lock +137 -0
- data/MIT-LICENSE +20 -0
- data/README.md +1244 -0
- data/Rakefile +12 -0
- data/lib/install/angular.rb +18 -0
- data/lib/install/bin/webpack-dev-server.tt +71 -0
- data/lib/install/bin/webpack.tt +32 -0
- data/lib/install/config/.babelrc +18 -0
- data/lib/install/config/.postcssrc.yml +3 -0
- data/lib/install/config/loaders/core/assets.js +12 -0
- data/lib/install/config/loaders/core/babel.js +5 -0
- data/lib/install/config/loaders/core/coffee.js +4 -0
- data/lib/install/config/loaders/core/erb.js +9 -0
- data/lib/install/config/loaders/core/sass.js +18 -0
- data/lib/install/config/loaders/installers/angular.js +4 -0
- data/lib/install/config/loaders/installers/elm.js +20 -0
- data/lib/install/config/loaders/installers/react.js +5 -0
- data/lib/install/config/loaders/installers/vue.js +41 -0
- data/lib/install/config/webpack/configuration.js +45 -0
- data/lib/install/config/webpack/development.js +31 -0
- data/lib/install/config/webpack/production.js +35 -0
- data/lib/install/config/webpack/shared.js +53 -0
- data/lib/install/config/webpack/test.js +6 -0
- data/lib/install/config/webpacker.yml +47 -0
- data/lib/install/elm.rb +29 -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 +6 -0
- data/lib/install/examples/angular/hello_angular/polyfills.ts +19 -0
- data/lib/install/examples/angular/tsconfig.json +19 -0
- data/lib/install/examples/elm/Main.elm +54 -0
- data/lib/install/examples/elm/hello_elm.js +11 -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 +43 -0
- data/lib/install/javascript/packs/application.js +10 -0
- data/lib/install/react.rb +31 -0
- data/lib/install/template.rb +42 -0
- data/lib/install/vue.rb +15 -0
- data/lib/tasks/installers.rake +22 -0
- data/lib/tasks/webpacker.rake +19 -0
- data/lib/tasks/webpacker/check_binstubs.rake +12 -0
- data/lib/tasks/webpacker/check_node.rake +20 -0
- data/lib/tasks/webpacker/check_yarn.rake +15 -0
- data/lib/tasks/webpacker/clobber.rake +17 -0
- data/lib/tasks/webpacker/compile.rake +38 -0
- data/lib/tasks/webpacker/install.rake +12 -0
- data/lib/tasks/webpacker/verify_install.rake +16 -0
- data/lib/tasks/webpacker/yarn_install.rake +6 -0
- data/lib/webpacker.rb +26 -0
- data/lib/webpacker/compiler.rb +59 -0
- data/lib/webpacker/configuration.rb +83 -0
- data/lib/webpacker/dev_server.rb +78 -0
- data/lib/webpacker/env.rb +23 -0
- data/lib/webpacker/file_loader.rb +47 -0
- data/lib/webpacker/helper.rb +69 -0
- data/lib/webpacker/manifest.rb +101 -0
- data/lib/webpacker/railtie.rb +18 -0
- data/lib/webpacker/version.rb +3 -0
- data/package.json +31 -0
- data/test/compiler_test.rb +25 -0
- data/test/configuration_test.rb +36 -0
- data/test/dev_server_test.rb +56 -0
- data/test/env_test.rb +14 -0
- data/test/helper_test.rb +45 -0
- data/test/manifest_test.rb +77 -0
- data/test/test_app/config/secrets.yml +5 -0
- data/test/test_app/public/packs/manifest.json +6 -0
- data/test/webpacker_test.rb +20 -0
- data/webpacker.gemspec +23 -0
- data/yarn.lock +1014 -0
- metadata +192 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
# Note: You must restart bin/webpack-dev-server for changes to take effect
|
2
|
+
|
3
|
+
default: &default
|
4
|
+
source_path: app/javascript
|
5
|
+
source_entry_path: packs
|
6
|
+
public_output_path: packs
|
7
|
+
|
8
|
+
compile: false
|
9
|
+
|
10
|
+
# Additional paths webpack should lookup modules
|
11
|
+
# ['app/assets', 'engine/foo/app/assets']
|
12
|
+
resolved_paths: []
|
13
|
+
|
14
|
+
extensions:
|
15
|
+
- .coffee
|
16
|
+
- .erb
|
17
|
+
- .js
|
18
|
+
- .jsx
|
19
|
+
- .ts
|
20
|
+
- .vue
|
21
|
+
- .sass
|
22
|
+
- .scss
|
23
|
+
- .css
|
24
|
+
- .png
|
25
|
+
- .svg
|
26
|
+
- .gif
|
27
|
+
- .jpeg
|
28
|
+
- .jpg
|
29
|
+
|
30
|
+
development:
|
31
|
+
<<: *default
|
32
|
+
|
33
|
+
dev_server:
|
34
|
+
host: localhost
|
35
|
+
port: 8080
|
36
|
+
https: false
|
37
|
+
hot: false
|
38
|
+
|
39
|
+
test:
|
40
|
+
<<: *default
|
41
|
+
|
42
|
+
public_output_path: packs-test
|
43
|
+
# Compile webpack assets during lookup when running tests
|
44
|
+
compile: true
|
45
|
+
|
46
|
+
production:
|
47
|
+
<<: *default
|
data/lib/install/elm.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
require "webpacker/configuration"
|
2
|
+
|
3
|
+
puts "Copying elm loader to config/webpack/loaders"
|
4
|
+
copy_file "#{__dir__}/config/loaders/installers/elm.js",
|
5
|
+
"config/webpack/loaders/elm.js"
|
6
|
+
|
7
|
+
puts "Copying elm example entry file to #{Webpacker::Configuration.entry_path}"
|
8
|
+
copy_file "#{__dir__}/examples/elm/Main.elm", "#{Webpacker::Configuration.entry_path}/Main.elm"
|
9
|
+
|
10
|
+
puts "Copying elm app file to #{Webpacker::Configuration.entry_path}"
|
11
|
+
copy_file "#{__dir__}/examples/elm/hello_elm.js",
|
12
|
+
"#{Webpacker::Configuration.entry_path}/hello_elm.js"
|
13
|
+
|
14
|
+
puts "Installing all elm dependencies"
|
15
|
+
run "yarn add elm elm-webpack-loader"
|
16
|
+
run "yarn add --dev elm-hot-loader"
|
17
|
+
run "yarn run elm package install -- --yes"
|
18
|
+
|
19
|
+
puts "Updating Webpack paths to include Elm file extension"
|
20
|
+
insert_into_file Webpacker::Configuration.file_path, " - .elm\n", after: /extensions:\n/
|
21
|
+
|
22
|
+
puts "Updating elm source location"
|
23
|
+
source_path = File.join(Webpacker::Configuration.source, Webpacker::Configuration.fetch(:source_entry_path))
|
24
|
+
gsub_file "elm-package.json", /\"\.\"\n/, %("#{source_path}"\n)
|
25
|
+
|
26
|
+
puts "Updating .gitignore to include elm-stuff folder"
|
27
|
+
insert_into_file ".gitignore", "/elm-stuff\n", before: "/node_modules\n"
|
28
|
+
|
29
|
+
puts "Webpacker now supports elm 🎉"
|
@@ -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,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,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,43 @@
|
|
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
|
+
})
|
16
|
+
|
17
|
+
|
18
|
+
// The above code uses Vue without the compiler, which means you cannot
|
19
|
+
// use Vue to target elements in your existing html templates. You would
|
20
|
+
// need to always use single file components.
|
21
|
+
// To be able to target elements in your existing html/erb templates,
|
22
|
+
// comment out the above code and uncomment the below
|
23
|
+
// Add <%= javascript_pack_tag 'hello_vue' %> to your layout
|
24
|
+
// Then add this markup to your html template:
|
25
|
+
//
|
26
|
+
// <div id='hello'>
|
27
|
+
// {{message}}
|
28
|
+
// <app></app>
|
29
|
+
// </div>
|
30
|
+
|
31
|
+
|
32
|
+
// import Vue from 'vue/dist/vue.esm'
|
33
|
+
// import App from './app.vue'
|
34
|
+
//
|
35
|
+
// document.addEventListener('DOMContentLoaded', () => {
|
36
|
+
// const app = new Vue({
|
37
|
+
// el: '#hello',
|
38
|
+
// data: {
|
39
|
+
// message: "Can you say hello?"
|
40
|
+
// },
|
41
|
+
// components: { App }
|
42
|
+
// })
|
43
|
+
// })
|
@@ -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,31 @@
|
|
1
|
+
require "webpacker/configuration"
|
2
|
+
|
3
|
+
babelrc = Rails.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
|
+
puts "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
|
+
puts "Copying .babelrc to app root directory"
|
19
|
+
copy_file "#{__dir__}/examples/react/.babelrc", ".babelrc"
|
20
|
+
end
|
21
|
+
|
22
|
+
puts "Copying react loader to config/webpack/loaders"
|
23
|
+
copy_file "#{__dir__}/config/loaders/installers/react.js", "config/webpack/loaders/react.js"
|
24
|
+
|
25
|
+
puts "Copying react example entry file to #{Webpacker::Configuration.entry_path}"
|
26
|
+
copy_file "#{__dir__}/examples/react/hello_react.jsx", "#{Webpacker::Configuration.entry_path}/hello_react.jsx"
|
27
|
+
|
28
|
+
puts "Installing all react dependencies"
|
29
|
+
run "yarn add react react-dom babel-preset-react prop-types"
|
30
|
+
|
31
|
+
puts "Webpacker now supports react.js 🎉"
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Install webpacker
|
2
|
+
copy_file "#{__dir__}/config/webpacker.yml", "config/webpacker.yml"
|
3
|
+
|
4
|
+
puts "Copying webpack core config and loaders"
|
5
|
+
directory "#{__dir__}/config/webpack", "config/webpack"
|
6
|
+
directory "#{__dir__}/config/loaders/core", "config/webpack/loaders"
|
7
|
+
|
8
|
+
puts "Copying .postcssrc.yml to app root directory"
|
9
|
+
copy_file "#{__dir__}/config/.postcssrc.yml", ".postcssrc.yml"
|
10
|
+
|
11
|
+
puts "Copying .babelrc to app root directory"
|
12
|
+
copy_file "#{__dir__}/config/.babelrc", ".babelrc"
|
13
|
+
|
14
|
+
puts "Creating javascript app source directory"
|
15
|
+
directory "#{__dir__}/javascript", "#{Webpacker::Configuration.source}"
|
16
|
+
|
17
|
+
puts "Copying binstubs"
|
18
|
+
directory "#{__dir__}/bin", "bin"
|
19
|
+
|
20
|
+
chmod "bin", 0755 & ~File.umask, verbose: false
|
21
|
+
|
22
|
+
if File.exists?(".gitignore")
|
23
|
+
append_to_file ".gitignore", <<-EOS
|
24
|
+
/public/packs
|
25
|
+
/public/packs-test
|
26
|
+
/node_modules
|
27
|
+
EOS
|
28
|
+
end
|
29
|
+
|
30
|
+
puts "Installing all JavaScript dependencies"
|
31
|
+
run "yarn add webpack webpack-merge js-yaml path-complete-extname " \
|
32
|
+
"webpack-manifest-plugin babel-loader@7.x coffee-loader coffee-script " \
|
33
|
+
"babel-core babel-preset-env babel-polyfill compression-webpack-plugin rails-erb-loader glob " \
|
34
|
+
"extract-text-webpack-plugin node-sass file-loader sass-loader css-loader style-loader " \
|
35
|
+
"postcss-loader postcss-cssnext postcss-smart-import resolve-url-loader " \
|
36
|
+
"babel-plugin-syntax-dynamic-import babel-plugin-transform-class-properties " \
|
37
|
+
"babel-plugin-transform-object-rest-spread"
|
38
|
+
|
39
|
+
puts "Installing dev server for live reloading"
|
40
|
+
run "yarn add --dev webpack-dev-server"
|
41
|
+
|
42
|
+
puts "Webpacker successfully installed 🎉 🍰"
|
data/lib/install/vue.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "webpacker/configuration"
|
2
|
+
|
3
|
+
puts "Copying vue loader to config/webpack/loaders"
|
4
|
+
copy_file "#{__dir__}/config/loaders/installers/vue.js", "config/webpack/loaders/vue.js"
|
5
|
+
|
6
|
+
puts "Copying the example entry file to #{Webpacker::Configuration.entry_path}"
|
7
|
+
copy_file "#{__dir__}/examples/vue/hello_vue.js", "#{Webpacker::Configuration.entry_path}/hello_vue.js"
|
8
|
+
|
9
|
+
puts "Copying vue app file to #{Webpacker::Configuration.entry_path}"
|
10
|
+
copy_file "#{__dir__}/examples/vue/app.vue", "#{Webpacker::Configuration.entry_path}/app.vue"
|
11
|
+
|
12
|
+
puts "Installing all vue dependencies"
|
13
|
+
run "yarn add vue vue-loader vue-template-compiler"
|
14
|
+
|
15
|
+
puts "Webpacker now supports vue.js 🎉"
|