webpacker-for-component 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.eslintrc.js +14 -0
- data/.gitignore +6 -0
- data/.rubocop.yml +124 -0
- data/.travis.yml +22 -0
- data/Gemfile +13 -0
- data/MIT-LICENSE +20 -0
- data/README.md +325 -0
- data/Rakefile +12 -0
- data/docs/assets.md +106 -0
- data/docs/css.md +82 -0
- data/docs/deployment.md +39 -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 +105 -0
- data/docs/testing.md +45 -0
- data/docs/troubleshooting.md +65 -0
- data/docs/typescript.md +116 -0
- data/docs/webpack-dev-server.md +32 -0
- data/docs/webpack.md +156 -0
- data/docs/yarn.md +12 -0
- data/lib/install/angular.rb +15 -0
- data/lib/install/bin/webpack-dev-server.tt +68 -0
- data/lib/install/bin/webpack.tt +30 -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/test.js +3 -0
- data/lib/install/config/webpacker.yml +56 -0
- data/lib/install/elm.rb +24 -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/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 +44 -0
- data/lib/install/javascript/packs/application.js +10 -0
- data/lib/install/react.rb +28 -0
- data/lib/install/template.rb +35 -0
- data/lib/install/vue.rb +12 -0
- data/lib/tasks/installers.rake +22 -0
- data/lib/tasks/webpacker-for-component/check_binstubs.rake +12 -0
- data/lib/tasks/webpacker-for-component/check_node.rake +25 -0
- data/lib/tasks/webpacker-for-component/check_yarn.rake +24 -0
- data/lib/tasks/webpacker-for-component/clobber.rake +16 -0
- data/lib/tasks/webpacker-for-component/compile.rake +34 -0
- data/lib/tasks/webpacker-for-component/install.rake +13 -0
- data/lib/tasks/webpacker-for-component/verify_install.rake +16 -0
- data/lib/tasks/webpacker-for-component/yarn_install.rake +6 -0
- data/lib/tasks/webpacker.rake +19 -0
- data/lib/webpacker-for-component.rb +28 -0
- data/lib/webpacker-for-component/commands.rb +23 -0
- data/lib/webpacker-for-component/compiler.rb +78 -0
- data/lib/webpacker-for-component/configuration.rb +88 -0
- data/lib/webpacker-for-component/dev_server.rb +51 -0
- data/lib/webpacker-for-component/dev_server_proxy.rb +25 -0
- data/lib/webpacker-for-component/helper.rb +65 -0
- data/lib/webpacker-for-component/instance.rb +44 -0
- data/lib/webpacker-for-component/manifest.rb +79 -0
- data/lib/webpacker-for-component/railtie.rb +41 -0
- data/lib/webpacker-for-component/version.rb +4 -0
- data/package.json +62 -0
- data/package/asset_host.js +21 -0
- data/package/config.js +8 -0
- data/package/environment.js +95 -0
- data/package/environments/development.js +46 -0
- data/package/environments/production.js +34 -0
- data/package/environments/test.js +3 -0
- data/package/index.js +16 -0
- data/package/loaders/babel.js +11 -0
- data/package/loaders/coffee.js +4 -0
- data/package/loaders/elm.js +19 -0
- data/package/loaders/erb.js +9 -0
- data/package/loaders/file.js +15 -0
- data/package/loaders/style.js +31 -0
- data/package/loaders/typescript.js +4 -0
- data/package/loaders/vue.js +12 -0
- data/test/command_test.rb +27 -0
- data/test/compiler_test.rb +20 -0
- data/test/configuration_test.rb +56 -0
- data/test/dev_server_test.rb +24 -0
- data/test/helper_test.rb +39 -0
- data/test/manifest_test.rb +20 -0
- data/test/test_app/config/secrets.yml +5 -0
- data/test/webpacker_test_helper.rb +40 -0
- data/webpacker-for-component.gemspec +23 -0
- data/yarn.lock +5162 -0
- metadata +111 -7
data/docs/yarn.md
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require "webpacker-for-component/configuration"
|
2
|
+
|
3
|
+
puts "Copying angular example entry file to #{Webpacker.config.source_entry_path}"
|
4
|
+
copy_file "#{__dir__}/examples/angular/hello_angular.js", "#{Webpacker.config.source_entry_path}/hello_angular.js"
|
5
|
+
|
6
|
+
puts "Copying hello_angular app to #{Webpacker.config.source_path}"
|
7
|
+
directory "#{__dir__}/examples/angular/hello_angular", "#{Webpacker.config.source_path}/hello_angular"
|
8
|
+
|
9
|
+
puts "Copying tsconfig.json to the Rails root directory for typescript"
|
10
|
+
copy_file "#{__dir__}/examples/angular/tsconfig.json", "tsconfig.json"
|
11
|
+
|
12
|
+
puts "Installing all angular dependencies"
|
13
|
+
run "yarn add typescript ts-loader core-js zone.js rxjs @angular/core @angular/common @angular/compiler @angular/platform-browser @angular/platform-browser-dynamic"
|
14
|
+
|
15
|
+
puts "Webpacker now supports angular and typescript 🎉"
|
@@ -0,0 +1,68 @@
|
|
1
|
+
<%= shebang %>
|
2
|
+
$stdout.sync = true
|
3
|
+
|
4
|
+
require "shellwords"
|
5
|
+
require "yaml"
|
6
|
+
require "socket"
|
7
|
+
|
8
|
+
ENV["RAILS_ENV"] ||= "development"
|
9
|
+
RAILS_ENV = ENV["RAILS_ENV"]
|
10
|
+
|
11
|
+
ENV["NODE_ENV"] ||= RAILS_ENV
|
12
|
+
NODE_ENV = ENV["NODE_ENV"]
|
13
|
+
|
14
|
+
APP_PATH = File.expand_path("../", __dir__)
|
15
|
+
CONFIG_FILE = File.join(APP_PATH, "config/webpacker.yml")
|
16
|
+
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules")
|
17
|
+
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js")
|
18
|
+
|
19
|
+
DEFAULT_LISTEN_HOST_ADDR = NODE_ENV == 'development' ? 'localhost' : '0.0.0.0'
|
20
|
+
|
21
|
+
def args(key)
|
22
|
+
index = ARGV.index(key)
|
23
|
+
index ? ARGV[index + 1] : nil
|
24
|
+
end
|
25
|
+
|
26
|
+
begin
|
27
|
+
dev_server = YAML.load_file(CONFIG_FILE)[RAILS_ENV]["dev_server"]
|
28
|
+
|
29
|
+
HOSTNAME = args('--host') || dev_server["host"]
|
30
|
+
PORT = args('--port') || dev_server["port"]
|
31
|
+
HTTPS = ARGV.include?('--https') || dev_server["https"]
|
32
|
+
DEV_SERVER_ADDR = "http#{"s" if HTTPS}://#{HOSTNAME}:#{PORT}"
|
33
|
+
LISTEN_HOST_ADDR = args('--listen-host') || DEFAULT_LISTEN_HOST_ADDR
|
34
|
+
|
35
|
+
rescue Errno::ENOENT, NoMethodError
|
36
|
+
$stdout.puts "Webpack dev_server configuration not found in #{CONFIG_FILE}."
|
37
|
+
$stdout.puts "Please run bundle exec rails webpacker:install to install webpacker"
|
38
|
+
exit!
|
39
|
+
end
|
40
|
+
|
41
|
+
begin
|
42
|
+
server = TCPServer.new(LISTEN_HOST_ADDR, PORT)
|
43
|
+
server.close
|
44
|
+
|
45
|
+
rescue Errno::EADDRINUSE
|
46
|
+
$stdout.puts "Another program is running on port #{PORT}. Set a new port in #{CONFIG_FILE} for dev_server"
|
47
|
+
exit!
|
48
|
+
end
|
49
|
+
|
50
|
+
# Delete supplied host, port and listen-host CLI arguments
|
51
|
+
["--host", "--port", "--listen-host"].each do |arg|
|
52
|
+
ARGV.delete(args(arg))
|
53
|
+
ARGV.delete(arg)
|
54
|
+
end
|
55
|
+
|
56
|
+
env = { "NODE_PATH" => NODE_MODULES_PATH.shellescape }
|
57
|
+
|
58
|
+
cmd = [
|
59
|
+
"#{NODE_MODULES_PATH}/.bin/webpack-dev-server", "--progress", "--color",
|
60
|
+
"--config", WEBPACK_CONFIG,
|
61
|
+
"--host", LISTEN_HOST_ADDR,
|
62
|
+
"--public", "#{HOSTNAME}:#{PORT}",
|
63
|
+
"--port", PORT.to_s
|
64
|
+
] + ARGV
|
65
|
+
|
66
|
+
Dir.chdir(APP_PATH) do
|
67
|
+
system env, *cmd
|
68
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
<%= shebang %>
|
2
|
+
$stdout.sync = true
|
3
|
+
|
4
|
+
require "shellwords"
|
5
|
+
|
6
|
+
ENV["RAILS_ENV"] ||= "development"
|
7
|
+
RAILS_ENV = ENV["RAILS_ENV"]
|
8
|
+
|
9
|
+
ENV["NODE_ENV"] ||= RAILS_ENV
|
10
|
+
NODE_ENV = ENV["NODE_ENV"]
|
11
|
+
|
12
|
+
APP_PATH = File.expand_path("../", __dir__)
|
13
|
+
NODE_MODULES_PATH = File.join(APP_PATH, "node_modules")
|
14
|
+
WEBPACK_CONFIG = File.join(APP_PATH, "config/webpack/#{NODE_ENV}.js")
|
15
|
+
|
16
|
+
unless File.exist?(WEBPACK_CONFIG)
|
17
|
+
puts "Webpack configuration not found."
|
18
|
+
puts "Please run bundle exec rails webpacker:install to install webpacker"
|
19
|
+
exit!
|
20
|
+
end
|
21
|
+
|
22
|
+
env = { "NODE_PATH" => NODE_MODULES_PATH.shellescape }
|
23
|
+
cmd = [ "#{NODE_MODULES_PATH}/.bin/webpack", "--config", WEBPACK_CONFIG ] + ARGV
|
24
|
+
|
25
|
+
Dir.chdir(APP_PATH) do
|
26
|
+
system env, *cmd
|
27
|
+
end
|
28
|
+
|
29
|
+
require 'fileutils'
|
30
|
+
FileUtils.cp_r 'public/packs/', '../../public/.'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"presets": [
|
3
|
+
["env", {
|
4
|
+
"modules": false,
|
5
|
+
"targets": {
|
6
|
+
"browsers": "> 1%",
|
7
|
+
"uglify": true
|
8
|
+
},
|
9
|
+
"useBuiltIns": true
|
10
|
+
}]
|
11
|
+
],
|
12
|
+
|
13
|
+
"plugins": [
|
14
|
+
"syntax-dynamic-import",
|
15
|
+
"transform-object-rest-spread",
|
16
|
+
["transform-class-properties", { "spec": true }]
|
17
|
+
]
|
18
|
+
}
|
@@ -0,0 +1,56 @@
|
|
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/angular
|
7
|
+
cache_path: tmp/cache/webpacker
|
8
|
+
|
9
|
+
# Additional paths webpack should lookup modules
|
10
|
+
# ['app/assets', 'engine/foo/app/assets']
|
11
|
+
resolved_paths: []
|
12
|
+
|
13
|
+
# Reload manifest.json on all requests so we reload latest compiled packs
|
14
|
+
cache_manifest: false
|
15
|
+
|
16
|
+
extensions:
|
17
|
+
- .coffee
|
18
|
+
- .erb
|
19
|
+
- .js
|
20
|
+
- .jsx
|
21
|
+
- .ts
|
22
|
+
- .vue
|
23
|
+
- .sass
|
24
|
+
- .scss
|
25
|
+
- .css
|
26
|
+
- .png
|
27
|
+
- .svg
|
28
|
+
- .gif
|
29
|
+
- .jpeg
|
30
|
+
- .jpg
|
31
|
+
|
32
|
+
development:
|
33
|
+
<<: *default
|
34
|
+
compile: true
|
35
|
+
|
36
|
+
dev_server:
|
37
|
+
host: localhost
|
38
|
+
port: 3035
|
39
|
+
hmr: false
|
40
|
+
https: false
|
41
|
+
|
42
|
+
test:
|
43
|
+
<<: *default
|
44
|
+
compile: true
|
45
|
+
|
46
|
+
# Compile test packs to a separate directory
|
47
|
+
public_output_path: packs-test
|
48
|
+
|
49
|
+
production:
|
50
|
+
<<: *default
|
51
|
+
|
52
|
+
# Production depends on precompilation of packs prior to booting for performance.
|
53
|
+
compile: false
|
54
|
+
|
55
|
+
# Cache manifest.json for performance
|
56
|
+
cache_manifest: true
|
data/lib/install/elm.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "webpacker-for-component/configuration"
|
2
|
+
|
3
|
+
puts "Copying elm example entry file to #{Webpacker.config.source_entry_path}"
|
4
|
+
copy_file "#{__dir__}/examples/elm/Main.elm", "#{Webpacker.config.source_entry_path}/Main.elm"
|
5
|
+
|
6
|
+
puts "Copying elm app file to #{Webpacker.config.source_entry_path}"
|
7
|
+
copy_file "#{__dir__}/examples/elm/hello_elm.js",
|
8
|
+
"#{Webpacker.config.source_entry_path}/hello_elm.js"
|
9
|
+
|
10
|
+
puts "Installing all elm dependencies"
|
11
|
+
run "yarn add elm elm-webpack-loader"
|
12
|
+
run "yarn add --dev elm-hot-loader"
|
13
|
+
run "yarn run elm package install -- --yes"
|
14
|
+
|
15
|
+
puts "Updating Webpack paths to include Elm file extension"
|
16
|
+
insert_into_file Webpacker.config.config_path, " - .elm\n", after: /extensions:\n/
|
17
|
+
|
18
|
+
puts "Updating elm source location"
|
19
|
+
gsub_file "elm-package.json", /\"\.\"\n/, %("#{Webpacker.config.source_entry_path}"\n)
|
20
|
+
|
21
|
+
puts "Updating .gitignore to include elm-stuff folder"
|
22
|
+
insert_into_file ".gitignore", "/elm-stuff\n", before: "/node_modules\n"
|
23
|
+
|
24
|
+
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,8 @@
|
|
1
|
+
import './polyfills.ts';
|
2
|
+
|
3
|
+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
|
4
|
+
import { AppModule } from './app/app.module';
|
5
|
+
|
6
|
+
document.addEventListener('DOMContentLoaded', () => {
|
7
|
+
platformBrowserDynamic().bootstrapModule(AppModule);
|
8
|
+
});
|
@@ -0,0 +1,73 @@
|
|
1
|
+
/**
|
2
|
+
* This file includes polyfills needed by Angular and is loaded before the app.
|
3
|
+
* You can add your own extra polyfills to this file.
|
4
|
+
*
|
5
|
+
* This file is divided into 2 sections:
|
6
|
+
* 1. Browser polyfills. These are applied before loading ZoneJS and are sorted by browsers.
|
7
|
+
* 2. Application imports. Files imported after ZoneJS that should be loaded before your main
|
8
|
+
* file.
|
9
|
+
*
|
10
|
+
* The current setup is for so-called "evergreen" browsers; the last versions of browsers that
|
11
|
+
* automatically update themselves. This includes Safari >= 10, Chrome >= 55 (including Opera),
|
12
|
+
* Edge >= 13 on the desktop, and iOS 10 and Chrome on mobile.
|
13
|
+
*
|
14
|
+
* Learn more in https://angular.io/docs/ts/latest/guide/browser-support.html
|
15
|
+
*/
|
16
|
+
|
17
|
+
/***************************************************************************************************
|
18
|
+
* BROWSER POLYFILLS
|
19
|
+
*/
|
20
|
+
|
21
|
+
/** IE9, IE10 and IE11 requires all of the following polyfills. **/
|
22
|
+
// import 'core-js/es6/symbol';
|
23
|
+
// import 'core-js/es6/object';
|
24
|
+
// import 'core-js/es6/function';
|
25
|
+
// import 'core-js/es6/parse-int';
|
26
|
+
// import 'core-js/es6/parse-float';
|
27
|
+
// import 'core-js/es6/number';
|
28
|
+
// import 'core-js/es6/math';
|
29
|
+
// import 'core-js/es6/string';
|
30
|
+
// import 'core-js/es6/date';
|
31
|
+
// import 'core-js/es6/array';
|
32
|
+
// import 'core-js/es6/regexp';
|
33
|
+
// import 'core-js/es6/map';
|
34
|
+
// import 'core-js/es6/weak-map';
|
35
|
+
// import 'core-js/es6/set';
|
36
|
+
|
37
|
+
/** IE10 and IE11 requires the following for NgClass support on SVG elements */
|
38
|
+
// import 'classlist.js'; // Run `npm install --save classlist.js`.
|
39
|
+
|
40
|
+
/** Evergreen browsers require these. **/
|
41
|
+
import 'core-js/es6/reflect';
|
42
|
+
import 'core-js/es7/reflect';
|
43
|
+
|
44
|
+
|
45
|
+
/**
|
46
|
+
* Required to support Web Animations `@angular/animation`.
|
47
|
+
* Needed for: All but Chrome, Firefox and Opera. http://caniuse.com/#feat=web-animation
|
48
|
+
**/
|
49
|
+
// import 'web-animations-js'; // Run `npm install --save web-animations-js`.
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
/***************************************************************************************************
|
54
|
+
* Zone JS is required by Angular itself.
|
55
|
+
*/
|
56
|
+
import 'zone.js/dist/zone';
|
57
|
+
// import 'zone.js/dist/long-stack-trace-zone' // async stack traces with zone.js
|
58
|
+
|
59
|
+
|
60
|
+
|
61
|
+
/***************************************************************************************************
|
62
|
+
* APPLICATION IMPORTS
|
63
|
+
*/
|
64
|
+
|
65
|
+
/**
|
66
|
+
* Date, currency, decimal and percent pipes.
|
67
|
+
* Needed for: All but Chrome, Firefox, Edge, IE11 and Safari 10
|
68
|
+
*/
|
69
|
+
// import 'intl'; // Run `npm install --save intl`.
|
70
|
+
/**
|
71
|
+
* Need to import at least one locale-data with intl.
|
72
|
+
*/
|
73
|
+
// import 'intl/locale-data/jsonp/en';
|
@@ -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
|
+
}
|