golden-webpack-rails 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +4 -0
  5. data/CODE_OF_CONDUCT.md +13 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +21 -0
  8. data/README.md +77 -0
  9. data/Rakefile +6 -0
  10. data/bin/console +14 -0
  11. data/bin/setup +7 -0
  12. data/lib/rails/generators/webpack/USAGE +29 -0
  13. data/lib/rails/generators/webpack/install_generator.rb +150 -0
  14. data/lib/rails/generators/webpack/templates/assets/App.css +4 -0
  15. data/lib/rails/generators/webpack/templates/assets/App.js +3 -0
  16. data/lib/rails/generators/webpack/templates/assets/App.sass +3 -0
  17. data/lib/rails/generators/webpack/templates/assets/App.scss +9 -0
  18. data/lib/rails/generators/webpack/templates/config/rails_only.js +0 -0
  19. data/lib/rails/generators/webpack/templates/config/webpack/common.js +38 -0
  20. data/lib/rails/generators/webpack/templates/config/webpack/font.js +23 -0
  21. data/lib/rails/generators/webpack/templates/config/webpack/hot.js +63 -0
  22. data/lib/rails/generators/webpack/templates/config/webpack/image.js +18 -0
  23. data/lib/rails/generators/webpack/templates/config/webpack/rails.js +38 -0
  24. data/lib/rails/generators/webpack/templates/config/webpack/react.js +19 -0
  25. data/lib/rails/generators/webpack/templates/config/webpack/sass.js +28 -0
  26. data/lib/rails/generators/webpack/templates/config/webpack_only.js +3 -0
  27. data/lib/rails/generators/webpack/templates/package.json +14 -0
  28. data/lib/rails/generators/webpack/templates/public/index.html +13 -0
  29. data/lib/rails/generators/webpack/templates/server.js +27 -0
  30. data/lib/webpack/rails.rb +6 -0
  31. data/lib/webpack/rails/version.rb +5 -0
  32. data/npm-bundler.png +0 -0
  33. data/webpack-pipeline.png +0 -0
  34. data/webpack-rails.gemspec +27 -0
  35. metadata +139 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e6afc390c75c5f450059f2b1dd4e2967be295523
4
+ data.tar.gz: 91c76b08a7a1312d0ad4fb6c3e014b59e02fdad4
5
+ SHA512:
6
+ metadata.gz: 91e0d83b642a0c6ded078df7cd81cbc9301c535d0d6208c8eacad873d24aebaec5d3a04f840df445701ff472adbf20cd66c6d818ed20535d2025e9afc1a226bb
7
+ data.tar.gz: 9926397a58f4033884564708dd517f055fd994753c0ba29c0f186f837eb347110bdd1af7ee10da1b7da61b5e54633367b6e5b238c4dcdd1ad656e1bdfe9a6026
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/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in webpack-rails.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tse-Ching Ho
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # Webpack::Rails
2
+
3
+ Webpack for Rails in hybridization or replacement way.
4
+
5
+ ## Advantage
6
+
7
+ Managing libraries with [bundler](https://github.com/bundler/bundler) and [npm](https://github.com/npm/npm) would make project more convenient and consistent.
8
+
9
+ ![npm & bundler](npm-bundler.png)
10
+
11
+ The frontend and backend team could work together more smoothly with [webpack](https://github.com/webpack/webpack) in one project.
12
+
13
+ ![webpack-pipeline](webpack-pipeline.png)
14
+
15
+ ## Installation
16
+
17
+ Add this line to your application's Gemfile:
18
+
19
+ ```ruby
20
+ gem 'golden-webpack-rails'
21
+ ```
22
+
23
+ And then execute:
24
+
25
+ ```
26
+ $ bundle
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ ### Hybridization mode
32
+
33
+ In your application root path, execute generator with a perfered path name like `client`.
34
+
35
+ ```
36
+ $ bundle exec rails generate webpack:install client
37
+ ```
38
+
39
+ It will create a `client` path to be your webpack root path and install npm modules inside.
40
+
41
+ Start develop servers with [foreman](https://github.com/ddollar/foreman).
42
+
43
+ ```
44
+ $ gem install foreman
45
+ $ foreman start -f Procfile.dev
46
+ ```
47
+
48
+ See live reload web page in browser.
49
+
50
+ ```
51
+ $ open http://localhost:4000/webpack-dev-server/
52
+ ```
53
+
54
+ Happy coding with webpack.
55
+
56
+ ### Replacement mode
57
+
58
+ It's still working on.
59
+
60
+ ## Development
61
+
62
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
63
+
64
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
65
+
66
+ ## Contributing
67
+
68
+ Bug reports and pull requests are welcome on GitHub at https://github.com/goldenio/webpack-rails. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
69
+
70
+ ## Acknowledgement
71
+
72
+ This gem is inspired by [Fast Rich Client Rails Development With Webpack and the ES6 Transpiler](http://forum.railsonmaui.com/t/fast-rich-client-rails-development-with-webpack-and-the-es6-transpiler/327) and [it's tutorial](https://github.com/shakacode/react-webpack-rails-tutorial).
73
+
74
+ ## License
75
+
76
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
77
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bundler/setup'
4
+ require 'webpack/rails'
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require 'pry'
11
+ # Pry.start
12
+
13
+ require 'irb'
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ Description:
2
+ It will generate config and rake for use.
3
+
4
+ Example:
5
+ rails generate webpack:install
6
+
7
+ This will create/modify:
8
+ .gitignore
9
+ Procfile.dev
10
+ app/assets/javascripts/application.js
11
+ app/assets/javascripts/generated/.gitkeep
12
+ client/assets/images
13
+ client/assets/javascripts/app.js
14
+ client/assets/stylesheets/app.css
15
+ client/assets/stylesheets/app.sass
16
+ client/assets/stylesheets/app.scss
17
+ client/config/rails_only.js
18
+ client/config/webpack/common.js
19
+ client/config/webpack/font.js
20
+ client/config/webpack/hot.js
21
+ client/config/webpack/image.js
22
+ client/config/webpack/rails.js
23
+ client/config/webpack/react.js
24
+ client/config/webpack/sass.js
25
+ client/config/webpack_only.js
26
+ client/package.json
27
+ client/public/index.html
28
+ client/server.js
29
+ config/application.rb
@@ -0,0 +1,150 @@
1
+ module Webpack
2
+ class InstallGenerator < ::Rails::Generators::Base
3
+
4
+ source_root File.expand_path('../templates', __FILE__)
5
+
6
+ argument :name, type: :string, default: 'client'
7
+ class_option :reactjs, type: :boolean, default: true, description: 'with react.js settings'
8
+
9
+ def add_client
10
+ empty_directory name
11
+ template 'package.json', "#{name}/package.json", name: application_name, author: author
12
+ template 'server.js', "#{name}/server.js"
13
+ end
14
+
15
+ def add_client_npm_modules
16
+ inside name do
17
+ run 'npm install --global webpack'
18
+ run 'npm install --save webpack expose-loader'
19
+ run 'npm install --save-dev webpack-dev-server'
20
+ run 'npm install --save-dev babel-loader coffee-loader'
21
+ run 'npm install --save-dev file-loader url-loader bundle-loader'
22
+ run 'npm install --save-dev style-loader css-loader sass-loader'
23
+ run 'npm install --save jquery'
24
+ run 'npm install --save es5-shim es6-promise'
25
+ if options.reactjs?
26
+ run 'npm install --save react'
27
+ run 'npm install --save-dev jsx-loader react-hot-loader'
28
+ run 'npm install --save alt'
29
+ run 'npm install --save redux react-redux redux-thunk redux-promise'
30
+ end
31
+ end
32
+ end
33
+
34
+ def add_client_fonts
35
+ return unless File.exists? 'app/assets/fonts'
36
+ create_link "#{name}/assets/fonts", '../../app/assets/fonts', symbolic: true
37
+ end
38
+
39
+ def add_client_images
40
+ return unless File.exists? 'app/assets/images'
41
+ create_link "#{name}/assets/images", '../../app/assets/images', symbolic: true
42
+ end
43
+
44
+ def add_client_javascripts
45
+ empty_directory "#{name}/assets/javascripts"
46
+ # create_file "#{name}/assets/javascripts/.gitkeep"
47
+ template 'assets/app.js', "#{name}/assets/javascripts/app.js"
48
+ end
49
+
50
+ def add_client_stylesheets
51
+ empty_directory "#{name}/assets/stylesheets"
52
+ # create_file "#{name}/assets/stylesheets/.gitkeep"
53
+ template 'assets/app.css', "#{name}/assets/stylesheets/app.css"
54
+ template 'assets/app.scss', "#{name}/assets/stylesheets/app.scss"
55
+ template 'assets/app.sass', "#{name}/assets/stylesheets/app.sass"
56
+ end
57
+
58
+ def add_client_config
59
+ empty_directory "#{name}/config"
60
+ empty_directory "#{name}/config/webpack"
61
+ template 'config/webpack/common.js', "#{name}/config/webpack/common.js"
62
+ template 'config/webpack/font.js', "#{name}/config/webpack/font.js"
63
+ template 'config/webpack/image.js', "#{name}/config/webpack/image.js"
64
+ template 'config/webpack/sass.js', "#{name}/config/webpack/sass.js"
65
+ if options.reactjs?
66
+ template 'config/webpack/react.js', "#{name}/config/webpack/react.js"
67
+ end
68
+ template 'config/webpack/hot.js', "#{name}/config/webpack/hot.js"
69
+ template 'config/webpack/rails.js', "#{name}/config/webpack/rails.js"
70
+ template 'config/webpack_only.js', "#{name}/config/webpack_only.js"
71
+ template 'config/rails_only.js', "#{name}/config/rails_only.js"
72
+ end
73
+
74
+ def add_client_public
75
+ empty_directory "#{name}/public"
76
+ template 'public/index.html', "#{name}/public/index.html"
77
+ end
78
+
79
+ def apply_app_stylesheets
80
+ sentinel = " end\nend\n"
81
+ insert_into_file 'config/application.rb', before: sentinel, verbose: false do
82
+ <<-CODE
83
+
84
+ # Add #{name}/assets/stylesheets to asset pipeline's search path.
85
+ config.assets.paths << Rails.root.join('#{name}', 'assets', 'stylesheets')
86
+ CODE
87
+ end
88
+ end
89
+
90
+ def apply_app_javascripts
91
+ gsub_file 'app/assets/javascripts/application.js', '//= require_tree .', '//# require_tree .'
92
+
93
+ empty_directory 'app/assets/javascripts/generated'
94
+ create_file 'app/assets/javascripts/generated/.gitkeep'
95
+ append_to_file 'app/assets/javascripts/application.js' do
96
+ <<-CODE.strip_heredoc
97
+
98
+ // Important to import jquery_ujs before rails-bundle as that patches jquery xhr to use the authenticity token!
99
+ //= require generated/common
100
+ //= require generated/#{name}-bundle
101
+ CODE
102
+ end
103
+ end
104
+
105
+ def add_procfile
106
+ file = 'Procfile.dev'
107
+ create_file file unless File.exists? file
108
+ append_to_file file do
109
+ <<-CODE.strip_heredoc
110
+ webpack_rails: sh -c 'cd #{name} && $(npm bin)/webpack -d --progress --colors --watch --config config/webpack/rails.js'
111
+ webpack_hot: sh -c 'cd #{name} && $(npm bin)/webpack -d --progress --colors --watch --config config/webpack/hot.js'
112
+ webpack_hot_server: sh -c 'cd #{name} && $(npm bin)/webpack-dev-server --config config/webpack/hot.js --hot --inline'
113
+ # node_server: sh -c 'cd #{name} && node server.js'
114
+ webrick: bundle exec rails server -p 3000
115
+ CODE
116
+ end
117
+ end
118
+
119
+ def add_gitignore_files
120
+ append_to_file '.gitignore' do
121
+ <<-CODE.strip_heredoc
122
+
123
+ # Ignore files for npm, webpack
124
+ /#{name}/node_modules
125
+ /#{name}/npm-debug.log
126
+ /#{name}/public/assets
127
+ /app/assets/javascripts/generated/*
128
+ !/app/assets/javascripts/generated/.gitkeep
129
+ CODE
130
+ end
131
+ end
132
+
133
+ private
134
+
135
+ def application_name
136
+ @application_name ||= File.basename(File.realpath('.')).underscore
137
+ end
138
+
139
+ def author
140
+ @author ||= git_config 'user.name'
141
+ end
142
+
143
+ def git_config field
144
+ command = "git config --global #{field}"
145
+ config = run(command, capture: true).strip
146
+ config.empty? ? "YOUR_#{field}".sub('.', '_').upcase : config
147
+ end
148
+
149
+ end
150
+ end
@@ -0,0 +1,4 @@
1
+ body {
2
+ font-size: 16pt;
3
+ background: #ffff00;
4
+ }
@@ -0,0 +1,3 @@
1
+ document.getElementById('content').textContent = 'It works.';
2
+ document.write('<p>Enjoy.</p>');
3
+ document.write('<ul><li>webpack</li><li>rails</li></ul>');
@@ -0,0 +1,3 @@
1
+ ul
2
+ li
3
+ color: #ff0000
@@ -0,0 +1,9 @@
1
+ p {
2
+ font-size: 20pt;
3
+ }
4
+
5
+ ul {
6
+ li {
7
+ margin: 5px;
8
+ }
9
+ }
@@ -0,0 +1,38 @@
1
+ const path = require('path');
2
+ var webpack = require('webpack');
3
+
4
+ var devFlag = new webpack.DefinePlugin({
5
+ __DEV__: JSON.stringify(JSON.parse(process.env.BUILD_DEV || 'true')),
6
+ __PRERELEASE__: JSON.stringify(JSON.parse(process.env.BUILD_PRERELEASE || 'false'))
7
+ });
8
+
9
+ var commonsChunk = new webpack.optimize.CommonsChunkPlugin('common.js')
10
+
11
+ module.exports = {
12
+ context: path.join(__dirname, '../..'),
13
+ entry: {
14
+ app: './assets/javascripts/app.js'
15
+ },
16
+ output: {
17
+ path: path.join(__dirname, '../../public/assets/'),
18
+ filename: '[name]-bundle.js',
19
+ publicPath: '/assets/'
20
+ },
21
+ resolve: {
22
+ root: [
23
+ path.join(__dirname, '../../assets/javascripts'),
24
+ ],
25
+ extensions: [
26
+ '', '.js', '.json', '.coffee'
27
+ ]
28
+ },
29
+ module: {
30
+ loaders: [
31
+ { test: /\.coffee$/, loader: 'coffee-loader' },
32
+ { test: /\.js$/, loader: 'jsx-loader?harmony' },
33
+ ]
34
+ },
35
+ plugins: [
36
+ devFlag, commonsChunk
37
+ ]
38
+ };
@@ -0,0 +1,23 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ resolve: {
5
+ root: [
6
+ path.join(__dirname, '../assets/fonts'),
7
+ ],
8
+ extensions: [
9
+ '.woff', '.woff2', '.ttf', '.eot', '.svg'
10
+ ]
11
+ },
12
+ module: {
13
+ loaders: [
14
+ // The url-loader uses DataUrls.
15
+ { test: /\.woff$/, loader: 'url-loader?limit=10000&minetype=application/font-woff' },
16
+ { test: /\.woff2$/, loader: 'url-loader?limit=10000&minetype=application/font-woff' },
17
+ // The file-loader emits files.
18
+ { test: /\.ttf$/, loader: 'file-loader' },
19
+ { test: /\.eot$/, loader: 'file-loader' },
20
+ { test: /\.svg$/, loader: 'file-loader' }
21
+ ]
22
+ },
23
+ };
@@ -0,0 +1,63 @@
1
+ const path = require('path');
2
+ var config = require('./common');
3
+ var font_config = require('./font');
4
+ var image_config = require('./image');
5
+ var sass_config = require('./sass');
6
+ <%- if options.reactjs? -%>
7
+ var react_config = require('./react');
8
+ <%- end -%>
9
+
10
+ config.output = {
11
+ path: path.join(__dirname, '../../public/assets/'),
12
+ filename: '[name]-bundle.js',
13
+ publicPath: '/assets/'
14
+ }
15
+
16
+ // the CLI have access to your webpack configuration
17
+ // the API doesn't have access to your webpack configuration
18
+ config.devServer = {
19
+ contentBase: './public',
20
+ host: '127.0.0.1',
21
+ port: '4000',
22
+ hot: true, // it doesnot work, use --hot in CLI
23
+ inline: true,
24
+ colors: true,
25
+ info: true,
26
+ quiet: false
27
+ }
28
+
29
+ config.devtool = 'eval-source-map';
30
+
31
+ // Handle common web font files in hot-reload
32
+ config.resolve.root.push(font_config.resolve.root);
33
+ config.resolve.extensions.push(font_config.resolve.extensions);
34
+ config.module.loaders.push(font_config.module.loaders);
35
+
36
+ // Handle common image files in hot-reload
37
+ config.resolve.root.push(image_config.resolve.root);
38
+ config.resolve.extensions.push(image_config.resolve.extensions);
39
+ config.module.loaders.push(image_config.module.loaders);
40
+
41
+ // All the styling loaders only apply to hot-reload, not rails
42
+ // Handle common css/sass files in hot-reload
43
+ config.resolve.root.push(sass_config.resolve.root);
44
+ config.resolve.extensions.push(sass_config.resolve.extensions);
45
+ config.module.loaders.push(sass_config.module.loaders);
46
+
47
+ <%- if options.reactjs? -%>
48
+ // Handle common react files in hot-reload
49
+ config.resolve.root.push(react_config.resolve.root);
50
+ config.resolve.extensions.push(react_config.resolve.extensions);
51
+ config.module.loaders.push(react_config.module.loaders);
52
+ config.module.loaders.push(
53
+ { test: /\.jsx?$/, exclude: /node_modules/, loaders: ['react-hot', 'babel'] }
54
+ );
55
+ <%- end -%>
56
+
57
+ // Add more entry points specific to webpack hot server
58
+ config.entry.webpack_only = path.join(__dirname, '../webpack_only.js');
59
+ <%- if options.reactjs? -%>
60
+ // config.entry.app2 = path.join(__dirname, '../../assets/javascripts/app2.jsx');
61
+ <%- end -%>
62
+
63
+ module.exports = config;
@@ -0,0 +1,18 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ resolve: {
5
+ root: [
6
+ path.join(__dirname, '../assets/images'),
7
+ ],
8
+ extensions: [
9
+ '.png', '.jpg'
10
+ ]
11
+ },
12
+ module: {
13
+ loaders: [
14
+ // inline base64 URLs for <=8k images, direct URLs for the rest
15
+ { test: /\.(png|jpg)$/, loader: 'url-loader?limit=8192' },
16
+ ]
17
+ },
18
+ };
@@ -0,0 +1,38 @@
1
+ const path = require('path');
2
+ var config = require('./common');
3
+ <%- if options.reactjs? -%>
4
+ var react_config = require('./react');
5
+ <%- end -%>
6
+
7
+ config.output = {
8
+ path: path.join(__dirname, '../../../app/assets/javascripts/generated'),
9
+ // filename: '[name]-bundle.js',
10
+ filename: '<%= name %>-bundle.js',
11
+ publicPath: '/assets/'
12
+ }
13
+
14
+ // load jQuery from cdn or rails asset pipeline
15
+ config.externals = { jquery: 'var jQuery' };
16
+ config.module.loaders.push(
17
+ // expose jQuery and $ to any JavaScript files loaded after <%= name %>-bundle.js in the Rails Asset Pipeline.
18
+ { test: require.resolve('jquery'), loader: 'expose?jQuery' },
19
+ { test: require.resolve('jquery'), loader: 'expose?$' }
20
+ );
21
+
22
+ <%- if options.reactjs? -%>
23
+ // Handle common react files in hot-reload
24
+ config.resolve.root.push(react_config.resolve.root);
25
+ config.resolve.extensions.push(react_config.resolve.extensions);
26
+ config.module.loaders.push(react_config.module.loaders);
27
+ config.module.loaders.push(
28
+ { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel' }
29
+ );
30
+ <%- end -%>
31
+
32
+ // Add more entry points specific to rails
33
+ // config.entry.rails_only = path.join(__dirname, '../rails_only.js');
34
+ <%- if options.reactjs? -%>
35
+ // config.entry.app2 = path.join(__dirname, '../../assets/javascripts/app2.jsx');
36
+ <%- end -%>
37
+
38
+ module.exports = config;
@@ -0,0 +1,19 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ resolve: {
5
+ root: [
6
+ path.join(__dirname, '../../assets/javascripts')
7
+ ],
8
+ extensions: [
9
+ '.js', '.jsx'
10
+ ]
11
+ },
12
+ module: {
13
+ loaders: [
14
+ { test: require.resolve('react'), loader: 'expose?React' },
15
+ // { test: /\.jsx?$/, exclude: /node_modules/, loader: 'babel' },
16
+ // { test: /\.jsx?$/, exclude: /node_modules/, loaders: ['react-hot', 'babel'] },
17
+ ]
18
+ },
19
+ };
@@ -0,0 +1,28 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ resolve: {
5
+ root: [
6
+ path.join(__dirname, '../../assets/stylesheets')
7
+ ],
8
+ extensions: [
9
+ '.css', '.sass', '.scss'
10
+ ]
11
+ },
12
+ module: {
13
+ loaders: [
14
+ // sass-loader
15
+ { test: /\.css$/, loader: 'style!css' }, // use ! to chain loaders
16
+ {
17
+ test: /\.sass$/,
18
+ loader: 'style!css!sass?indentedSyntax&outputStyle=expanded&imagePath=/assets/images&' +
19
+ 'includePaths[]=' + encodeURIComponent(path.resolve(__dirname, '../assets/stylesheets')),
20
+ },
21
+ {
22
+ test: /\.scss$/,
23
+ loader: 'style!css!sass?outputStyle=expanded&imagePath=/assets/images&' +
24
+ 'includePaths[]=' + encodeURIComponent(path.resolve(__dirname, '../assets/stylesheets')),
25
+ }
26
+ ]
27
+ },
28
+ };
@@ -0,0 +1,3 @@
1
+ require('app.css');
2
+ require('app.scss');
3
+ require('app.sass');
@@ -0,0 +1,14 @@
1
+ {
2
+ "name": "<%= config[:name] %>",
3
+ "version": "1.0.0",
4
+ "description": "== README",
5
+ "main": "server.js",
6
+ "directories": {
7
+ "test": "test"
8
+ },
9
+ "scripts": {
10
+ "test": "echo \"Error: no test specified\" && exit 1"
11
+ },
12
+ "author": "<%= config[:author] %>",
13
+ "license": "ISC"
14
+ }
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Web page powered by Node.js</title>
6
+ </head>
7
+ <body>
8
+ <div id="content"></div>
9
+ <script type="text/javascript" src="assets/common.js"></script>
10
+ <script type="text/javascript" src="assets/webpack_only-bundle.js"></script>
11
+ <script type="text/javascript" src="assets/app-bundle.js"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,27 @@
1
+ var WebpackDevServer = require('webpack-dev-server');
2
+ var webpack = require('webpack');
3
+ var config = require('./config/webpack/hot');
4
+
5
+ // var bodyParser = require('body-parser');
6
+ // var sleep = require('sleep');
7
+
8
+ var server = new WebpackDevServer(webpack(config), {
9
+ contentBase: './public',
10
+ publicPath: config.output.publicPath,
11
+ hot: true,
12
+ noInfo: false,
13
+ stats: {
14
+ colors: true,
15
+ hash: false,
16
+ version: false,
17
+ chunks: false,
18
+ children: false,
19
+ },
20
+ });
21
+
22
+ server.listen(4000, 'localhost', function(error) {
23
+ if (error) {
24
+ console.log(error);
25
+ }
26
+ console.log('Listening at http://localhost:4000 ...');
27
+ });
@@ -0,0 +1,6 @@
1
+ require 'webpack/rails/version'
2
+
3
+ module Webpack
4
+ module Rails
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module Webpack
2
+ module Rails
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
data/npm-bundler.png ADDED
Binary file
Binary file
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'webpack/rails/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'golden-webpack-rails'
8
+ spec.version = Webpack::Rails::VERSION
9
+ spec.authors = ['Tse-Ching Ho']
10
+ spec.email = ['tsechingho@gmail.com']
11
+
12
+ spec.summary = %q{Webpack for Rails in hybridization or replacement way.}
13
+ spec.description = %q{Webpack for Rails in hybridization or replacement way.}
14
+ spec.homepage = 'https://github.com/goldenio/webpack-rails'
15
+ spec.license = 'MIT'
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = 'exe'
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ['lib']
21
+
22
+ spec.add_dependency 'railties', '>= 4.2', '< 5'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.10'
25
+ spec.add_development_dependency 'rake', '~> 10.0'
26
+ spec.add_development_dependency 'rspec'
27
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: golden-webpack-rails
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Tse-Ching Ho
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-09-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.2'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '5'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.2'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '5'
33
+ - !ruby/object:Gem::Dependency
34
+ name: bundler
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '1.10'
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.10'
47
+ - !ruby/object:Gem::Dependency
48
+ name: rake
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '10.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '10.0'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rspec
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ description: Webpack for Rails in hybridization or replacement way.
76
+ email:
77
+ - tsechingho@gmail.com
78
+ executables: []
79
+ extensions: []
80
+ extra_rdoc_files: []
81
+ files:
82
+ - ".gitignore"
83
+ - ".rspec"
84
+ - ".travis.yml"
85
+ - CODE_OF_CONDUCT.md
86
+ - Gemfile
87
+ - LICENSE.txt
88
+ - README.md
89
+ - Rakefile
90
+ - bin/console
91
+ - bin/setup
92
+ - lib/rails/generators/webpack/USAGE
93
+ - lib/rails/generators/webpack/install_generator.rb
94
+ - lib/rails/generators/webpack/templates/assets/App.css
95
+ - lib/rails/generators/webpack/templates/assets/App.js
96
+ - lib/rails/generators/webpack/templates/assets/App.sass
97
+ - lib/rails/generators/webpack/templates/assets/App.scss
98
+ - lib/rails/generators/webpack/templates/config/rails_only.js
99
+ - lib/rails/generators/webpack/templates/config/webpack/common.js
100
+ - lib/rails/generators/webpack/templates/config/webpack/font.js
101
+ - lib/rails/generators/webpack/templates/config/webpack/hot.js
102
+ - lib/rails/generators/webpack/templates/config/webpack/image.js
103
+ - lib/rails/generators/webpack/templates/config/webpack/rails.js
104
+ - lib/rails/generators/webpack/templates/config/webpack/react.js
105
+ - lib/rails/generators/webpack/templates/config/webpack/sass.js
106
+ - lib/rails/generators/webpack/templates/config/webpack_only.js
107
+ - lib/rails/generators/webpack/templates/package.json
108
+ - lib/rails/generators/webpack/templates/public/index.html
109
+ - lib/rails/generators/webpack/templates/server.js
110
+ - lib/webpack/rails.rb
111
+ - lib/webpack/rails/version.rb
112
+ - npm-bundler.png
113
+ - webpack-pipeline.png
114
+ - webpack-rails.gemspec
115
+ homepage: https://github.com/goldenio/webpack-rails
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.4.5.1
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: Webpack for Rails in hybridization or replacement way.
139
+ test_files: []