frontrunner 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9ea87ed4e2b6ec196503d17a654df0f1dd7245b3
4
+ data.tar.gz: 304a3c9eb2c55cc4cbbd08809607fdfbd8c2aebd
5
+ SHA512:
6
+ metadata.gz: 76d1d50882926e9f11e1d2029d8c0ffd1c588de1e1f331d78d8dbcf9bb69f83c18dba3ee4f6b8717b31dee28b12cef83d3a5b62371a773fb3e046c9414612d95
7
+ data.tar.gz: 42c914ffd62905639e9cd247c28c7da3233c7add2aa2272ced94464928604d691135fdf14dc2836b7ab34ccf1f62074444a2fb70b20469150d31f0db346f01fc
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ ## 0.1.0
2
+
3
+ - First release
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in frontrunner.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,230 @@
1
+ # Frontrunner
2
+
3
+ :fire: Webpack for Rails
4
+
5
+ Why Webpack?
6
+
7
+ - Manage your JavaScript and CSS dependencies with [npm](https://www.npmjs.com/), the JavaScript package manager
8
+ - Use modules to keep your code organized
9
+ - *Optional* Use hot module replacement for faster iteration
10
+
11
+ But there are also a few drawbacks:
12
+
13
+ - More complex development process
14
+ - Longer build times, as there is currently no way to [cache between builds](https://github.com/webpack/webpack/issues/250)
15
+
16
+ As with the Rails asset pipeline (Sprockets), you also get:
17
+
18
+ - Minification and compression
19
+ - Digests for long-term caching
20
+ - Coffeescript and Sass support
21
+ - Source maps (Sprockets 4+)
22
+ - ES6 support (Sprockets 4+)
23
+ - *Optional* JSX support for React
24
+
25
+ Frontrunner plays nicely with the Rails asset pipeline. This makes it easy to transition existing apps at your own pace. While it may be tempting to remove Sprockets, some Rails engines like [RailsAdmin](https://github.com/sferik/rails_admin) depend on it. You never know when you’ll want to add one of these, so we recommend keeping it around.
26
+
27
+ Like Rails, [jQuery](https://github.com/jquery/jquery), [jQuery UJS](https://github.com/rails/jquery-ujs), and [Turbolinks](https://github.com/turbolinks/turbolinks) are added to start, but these can be easily removed if desired.
28
+
29
+ ## The Setup
30
+
31
+ Here are the files and directories we’ll use.
32
+
33
+ Files | Description
34
+ --- | ---
35
+ package.json | Gemfile for npm
36
+ npm-shrinkwrap.json | Gemfile.lock for npm
37
+ webpack.config.js | Webpack config
38
+ node_modules | npm packages
39
+ app/webpack | app/assets equivalent
40
+
41
+ ## Installation
42
+
43
+ Add this line to your application’s Gemfile
44
+
45
+ ```ruby
46
+ gem 'frontrunner'
47
+ ```
48
+
49
+ And run:
50
+
51
+ ```sh
52
+ bundle install
53
+ ```
54
+
55
+ Generate files
56
+
57
+ ```sh
58
+ rails generate frontrunner:install
59
+ ```
60
+
61
+ And run:
62
+
63
+ ```sh
64
+ npm install && npm shrinkwrap --dev
65
+ ```
66
+
67
+ Then, add to your layout:
68
+
69
+ ```erb
70
+ <%= webpack_include_tag "application" %>
71
+ ```
72
+
73
+ ## Development
74
+
75
+ Run:
76
+
77
+ ```sh
78
+ npm run server
79
+ ```
80
+
81
+ This will start the [webpack-dev-server](https://webpack.github.io/docs/webpack-dev-server.html) at `http://localhost:8080`.
82
+
83
+ It’s possible to serve Webpack assets through Sprockets rather than a separate web server in development, but this can be significantly slower.
84
+
85
+ If you use [Foreman](https://github.com/ddollar/foreman), you can create a `Procfile.dev` with:
86
+
87
+ ```
88
+ web: bin/rails server
89
+ webpack: npm run server
90
+ ```
91
+
92
+ And run it with:
93
+
94
+ ```sh
95
+ foreman start -f Procfile.dev
96
+ ```
97
+
98
+ ## Packages
99
+
100
+ Add new packages with npm.
101
+
102
+ ```sh
103
+ npm install underscore -S
104
+ ```
105
+
106
+ Use the `-S` option to save it to `package.json`.
107
+
108
+ You can now include the package in your JavaScript.
109
+
110
+ ```js
111
+ var _ = require("underscore");
112
+ var trips = _.map([1, 2, 3], function (i) { return i * 3; });
113
+ console.log(trips);
114
+ ```
115
+
116
+ ### Bootstrap
117
+
118
+ Run:
119
+
120
+ ```sh
121
+ npm install bootstrap-sass -S
122
+ ```
123
+
124
+ For CSS, in `application.scss`, add:
125
+
126
+ ```scss
127
+ $icon-font-path: "~bootstrap-sass/assets/fonts/bootstrap/";
128
+ @import "bootstrap-sass/assets/stylesheets/bootstrap";
129
+ ```
130
+
131
+ Or only include specific components with:
132
+
133
+ ```scss
134
+ @import "bootstrap-sass/assets/stylesheets/bootstrap/variables";
135
+ @import "bootstrap-sass/assets/stylesheets/bootstrap/mixins";
136
+ @import "bootstrap-sass/assets/stylesheets/bootstrap/alerts";
137
+ ```
138
+
139
+ For JavaScript, in `application.js`, add:
140
+
141
+ ```js
142
+ require("bootstrap-sass/assets/javascripts/bootstrap");
143
+ ```
144
+
145
+ Or only include specific components with:
146
+
147
+ ```js
148
+ require("bootstrap-sass/assets/javascripts/bootstrap/alert");
149
+ ```
150
+
151
+ ### React
152
+
153
+ Run:
154
+
155
+ ```sh
156
+ npm install react react-dom -S
157
+ ```
158
+
159
+ [React Hot Loader](http://gaearon.github.io/react-hot-loader/) and support for `jsx` are already included. See [Hot Module Replacement](#hot-module-replacement) for how to activate.
160
+
161
+ ## Entry Points
162
+
163
+ During installation, a single [entry point](https://webpack.github.io/docs/multiple-entry-points.html) - `application` - is created.
164
+
165
+ To add another entry point - for instance, for a blog - create `blog.js` and add it to `webpack.config.js`.
166
+
167
+ ```js
168
+ {
169
+ entry: {
170
+ application: "application",
171
+ blog: "blog"
172
+ }
173
+ }
174
+ ```
175
+
176
+ To include it in your views, use:
177
+
178
+ ```erb
179
+ <%= webpack_include_tag "blog" %>
180
+ ```
181
+
182
+ ## Hot Module Replacement
183
+
184
+ Use [hot module replacement](https://webpack.github.io/docs/hot-module-replacement.html) to update code without reloading the page.
185
+
186
+ Just run `npm run server:hot` instead of `npm run server`.
187
+
188
+ If you use React, this includes the [React Hot Loader](http://gaearon.github.io/react-hot-loader/).
189
+
190
+ ## Deployment
191
+
192
+ Node.js is required to build the assets. As part of the build process, run:
193
+
194
+ ```sh
195
+ npm run assets:precompile
196
+ ```
197
+
198
+ ### Heroku
199
+
200
+ On Heroku, you’ll need to use multiple buildpacks.
201
+
202
+ ```sh
203
+ heroku buildpacks:add heroku/nodejs
204
+ heroku buildpacks:add heroku/ruby
205
+ ```
206
+
207
+ And ask Heroku to install dev dependencies from `package.json`.
208
+
209
+ ```sh
210
+ heroku config:set NPM_CONFIG_PRODUCTION=false
211
+ ```
212
+
213
+ And in `package.json`, under `scripts`, add:
214
+
215
+ ```json
216
+ {
217
+ "scripts": {
218
+ "heroku-postbuild": "npm run assets:precompile"
219
+ }
220
+ }
221
+ ```
222
+
223
+ ## Contributing
224
+
225
+ Everyone is encouraged to help improve this project. Here are a few ways you can help:
226
+
227
+ - [Report bugs](https://github.com/ankane/frontrunner/issues)
228
+ - Fix bugs and [submit pull requests](https://github.com/ankane/frontrunner/pulls)
229
+ - Write, clarify, or fix documentation
230
+ - Suggest or add new features
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: :test
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "frontrunner/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "frontrunner"
8
+ spec.version = Frontrunner::VERSION
9
+ spec.authors = ["Andrew Kane"]
10
+ spec.email = ["andrew@chartkick.com"]
11
+
12
+ spec.summary = "Webpack for Rails"
13
+ spec.homepage = "https://github.com/ankane/frontrunner"
14
+
15
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
16
+ spec.bindir = "exe"
17
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency "activesupport"
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,11 @@
1
+ require "frontrunner/helper"
2
+ require "frontrunner/version"
3
+ require "active_support/lazy_load_hooks"
4
+
5
+ module Frontrunner
6
+ class Error < StandardError; end
7
+ end
8
+
9
+ ActiveSupport.on_load(:action_view) do
10
+ include Frontrunner::Helper
11
+ end
@@ -0,0 +1,21 @@
1
+ module Frontrunner
2
+ module Helper
3
+ def webpack_include_tag(*sources)
4
+ options = sources.extract_options!
5
+ sources =
6
+ sources.map do |source|
7
+ @webpack_manifest = nil if Rails.env.development?
8
+ entry = webpack_manifest[source]
9
+ raise Frontrunner::Error, "Could not find webpack entry point: #{source}" unless entry
10
+ entry["js"]
11
+ end
12
+ javascript_include_tag *sources, options
13
+ end
14
+
15
+ def webpack_manifest
16
+ @webpack_manifest ||= JSON.parse(File.read(Rails.root.join("webpack-assets.json")))
17
+ rescue => e
18
+ raise Frontrunner::Error, "Error reading webpack manifest - be sure to start the dev server"
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Frontrunner
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,19 @@
1
+ require "rails/generators"
2
+
3
+ module Frontrunner
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("../templates", __FILE__)
7
+
8
+ def perform
9
+ copy_file "package.json", "package.json"
10
+ copy_file "webpack.config.js", "webpack.config.js"
11
+ append_file ".gitignore", "\n# Webpack\n/node_modules/\nnpm-debug.log\nwebpack-assets.json\n"
12
+ create_file "app/webpack/images/.keep"
13
+ copy_file "application.js", "app/webpack/javascripts/application.js"
14
+ copy_file "hello.coffee", "app/webpack/javascripts/hello.coffee"
15
+ copy_file "application.scss", "app/webpack/stylesheets/application.scss"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ // Styles
2
+ require("application.scss");
3
+
4
+ // jQuery
5
+ window.$ = window.jQuery = require("jquery");
6
+
7
+ // Rails UJS
8
+ require("jquery-ujs");
9
+
10
+ // Turbolinks
11
+ const Turbolinks = require("turbolinks");
12
+ Turbolinks.start();
13
+
14
+ // Hi!
15
+ const hello = require("hello");
16
+ console.log(hello("Webpack"));
@@ -0,0 +1,5 @@
1
+ $primary-color: #ccc;
2
+
3
+ body {
4
+ color: $primary-color;
5
+ }
@@ -0,0 +1,2 @@
1
+ module.exports = (name) ->
2
+ "Hello #{name}!"
@@ -0,0 +1,33 @@
1
+ {
2
+ "dependencies": {
3
+ "jquery": "^2.2.4",
4
+ "jquery-ujs": "^1.2.1",
5
+ "turbolinks": "^5.0.0-beta5"
6
+ },
7
+ "devDependencies": {
8
+ "assets-webpack-plugin": "^3.4.0",
9
+ "babel-core": "^6.9.0",
10
+ "babel-loader": "^6.2.4",
11
+ "babel-plugin-react-require": "^2.1.0",
12
+ "babel-preset-es2015": "^6.9.0",
13
+ "babel-preset-react": "^6.5.0",
14
+ "coffee-loader": "^0.7.2",
15
+ "coffee-script": "^1.10.0",
16
+ "compression-webpack-plugin": "^0.3.1",
17
+ "css-loader": "^0.23.1",
18
+ "file-loader": "^0.8.5",
19
+ "node-sass": "^3.7.0",
20
+ "react-hot-loader": "^1.3.0",
21
+ "sass-loader": "^3.2.0",
22
+ "style-loader": "^0.13.1",
23
+ "url-loader": "^0.5.7",
24
+ "webpack": "^1.13.1",
25
+ "webpack-dev-server": "^1.14.1"
26
+ },
27
+ "scripts": {
28
+ "assets:precompile": "webpack",
29
+ "server": "webpack-dev-server",
30
+ "server:hot": "webpack-dev-server --inline --hot"
31
+ },
32
+ "private": true
33
+ }
@@ -0,0 +1,61 @@
1
+ var path = require("path");
2
+ var webpack = require("webpack");
3
+ var AssetsPlugin = require("assets-webpack-plugin");
4
+ var CompressionPlugin = require("compression-webpack-plugin");
5
+
6
+ var development = !process.env.RAILS_ENV || process.env.RAILS_ENV === "development";
7
+
8
+ var config = {
9
+ entry: {
10
+ application: "application"
11
+ },
12
+ output: {
13
+ path: path.join(__dirname, "public", "webpack"),
14
+ filename: development ? "[name].js" : "[name]-[hash].js",
15
+ publicPath: development ? "http://localhost:8080/" : "/webpack/",
16
+ },
17
+ module: {
18
+ loaders: [
19
+ {test: /\.css$/, loader: "style-loader!css-loader"},
20
+ {test: /\.scss$/, loader: "style-loader!css-loader!sass-loader"},
21
+ {test: /\.jsx?$|\.tag$/, exclude: /node_modules/, loader: "react-hot!babel-loader?cacheDirectory&presets[]=es2015&presets[]=react&plugins[]=react-require"},
22
+ {test: /\.coffee$/, loader: "coffee-loader"},
23
+ {test: /\.woff2?$|\.ttf$|\.eot$|\.svg$/, loader: "file"}
24
+ ]
25
+ },
26
+ plugins: [
27
+ new webpack.DefinePlugin({
28
+ "process.env": JSON.stringify({
29
+ NODE_ENV: process.env.RAILS_ENV
30
+ })
31
+ }),
32
+ new AssetsPlugin({path: path.join(__dirname)})
33
+ ],
34
+ resolve: {
35
+ root: [
36
+ path.join(__dirname, "app", "webpack", "javascripts"),
37
+ path.join(__dirname, "app", "webpack", "stylesheets"),
38
+ path.join(__dirname, "app", "webpack", "images")
39
+ ],
40
+ extensions: ["", ".js", ".jsx", ".coffee"]
41
+ },
42
+ sassLoader: {
43
+ includePaths: [
44
+ path.join(__dirname, "node_modules")
45
+ ]
46
+ }
47
+ };
48
+
49
+ if (development) {
50
+ config.devtool = "#eval-cheap-module-inline-source-map";
51
+ } else {
52
+ config.plugins.push(
53
+ new webpack.optimize.UglifyJsPlugin({sourceMap: false, compress: {warnings: false}}),
54
+ new webpack.optimize.DedupePlugin(),
55
+ new webpack.optimize.OccurenceOrderPlugin(),
56
+ new CompressionPlugin()
57
+ );
58
+ config.bail = true;
59
+ }
60
+
61
+ module.exports = config;
metadata ADDED
@@ -0,0 +1,101 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: frontrunner
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Andrew Kane
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ description:
56
+ email:
57
+ - andrew@chartkick.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - ".gitignore"
63
+ - CHANGELOG.md
64
+ - Gemfile
65
+ - README.md
66
+ - Rakefile
67
+ - frontrunner.gemspec
68
+ - lib/frontrunner.rb
69
+ - lib/frontrunner/helper.rb
70
+ - lib/frontrunner/version.rb
71
+ - lib/generators/frontrunner/install_generator.rb
72
+ - lib/generators/frontrunner/templates/application.js
73
+ - lib/generators/frontrunner/templates/application.scss
74
+ - lib/generators/frontrunner/templates/hello.coffee
75
+ - lib/generators/frontrunner/templates/package.json
76
+ - lib/generators/frontrunner/templates/webpack.config.js
77
+ homepage: https://github.com/ankane/frontrunner
78
+ licenses: []
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.6.1
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Webpack for Rails
100
+ test_files: []
101
+ has_rdoc: