gems_assets_webpack_bridge 0.9.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f98d4f84753185927415394d7491fa3d9fb4c2ff
4
+ data.tar.gz: 1b3ff95a1fa7e58e6624f6a568a2240136b917e4
5
+ SHA512:
6
+ metadata.gz: ca13a74a68fcfe29826c59c76867304dda07cbe3737ed66c6c3ee36ed886785f9dd8072308a6b3cadc71b9319ba76c334e898a0ab05c75149eafa1579ddd9f6b
7
+ data.tar.gz: c1290e9d3175edff7abad38ce27c7471e25243a8edda746c7aaf06a377043f8d69234c4e977848f0e79924d7505c26e2a8db486a7f389493f7cf7f4f82bfecec
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+ gems_assets_webpack_bridge-*.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in gems_assets_webpack_bridge.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Ilya N. Zykin
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,143 @@
1
+ # GemsAssetsWebpackBridge
2
+
3
+ This Rails gem helps to create a bridge between assets in your ruby gems and [Webpack](https://webpack.js.org/).
4
+
5
+ ![pexels-photo-208684](https://user-images.githubusercontent.com/496713/36936816-18261a9c-1f1b-11e8-9c46-6b6d830fed2c.jpeg)
6
+
7
+ ## The Problem
8
+
9
+ 1. I had a classic monolith Rails application with Sprockets.
10
+ 2. I've split my Rails app into a few Rails gems and moved my assets into gems.
11
+ 3. I started migration from Sprockets to Webpack.
12
+ 4. Webpack didn't know how to find my assets in Rails gems.
13
+
14
+ ## The Solution
15
+
16
+ This gem helps to collect paths to assets' folders in gems and adds some [aliases](https://webpack.js.org/configuration/resolve/#resolve-alias) for Webpack to help it to find assets in classic Rails gems.
17
+
18
+ ## Installation
19
+
20
+ **Gemfile**
21
+
22
+ ```ruby
23
+ gem 'gems_assets_webpack_bridge'
24
+ ```
25
+
26
+ ```
27
+ $ bundle
28
+ ```
29
+
30
+ ## Usage
31
+
32
+ Create a bridge between Rails gems and Webpack:
33
+
34
+ ```ruby
35
+ rake gems_asstes_webpack_bridge:create
36
+ ```
37
+
38
+ ### What is The Bridge?
39
+
40
+ * The Bridge is a JSON file with paths to assets in your gems.
41
+ * The Bridge provides additional [aliases](https://webpack.js.org/configuration/resolve/#resolve-alias) for Webpack to help it to find assets' folders in ruby gems.
42
+ * Every alias has the following naming: `@[UNDERSCORED_GEM_NAME]-[ASSET_TYPE]`.
43
+ * Default asset types are: `images`, `scripts`, `styles`.
44
+ * By default the file has name `gems-assets-webpack-bridge.json` and looks like that:
45
+
46
+ ```json
47
+ {
48
+ "@crop_tool-scripts": "/Users/@username/.rvm/gems/ruby-2.4.2/gems/crop_tool/app/assets/javascripts",
49
+ "@crop_tool-styles": "/Users/@username/.rvm/gems/ruby-2.4.2/gems/crop_tool/app/assets/stylesheets",
50
+ "@jquery_ui_rails-images": "/Users/@username/.rvm/gems/ruby-2.3.3@open-cook.ru/gems/jquery-ui-rails-5.0.0/app/assets/images",
51
+ "@jquery_ui_rails-scripts": "/Users/@username/.rvm/gems/ruby-2.3.3@open-cook.ru/gems/jquery-ui-rails-5.0.0/app/assets/javascripts",
52
+ "@jquery_ui_rails-styles": "/Users/@username/.rvm/gems/ruby-2.3.3@open-cook.ru/gems/jquery-ui-rails-5.0.0/app/assets/stylesheets",
53
+ "@log_js-scripts": "/Users/@username/.rvm/gems/ruby-2.4.2/gems/log_js/app/assets/javascripts",
54
+ "@notifications-scripts": "/Users/@username/.rvm/gems/ruby-2.4.2/gems/notifications/app/assets/javascripts",
55
+ "@notifications-styles": "/Users/@username/.rvm/gems/ruby-2.4.2/gems/notifications/app/assets/stylesheets",
56
+ }
57
+ ```
58
+
59
+ ### How to use The Bridge?
60
+
61
+ Now, when you the bridge file, you can use it in Webpack like this:
62
+
63
+ **webpack.config.js**
64
+
65
+ ```javascript
66
+ // This helper-function reads the bridge file and
67
+ // adds some additional aliases in `WebPackConfig.resolve.alias`
68
+ function addGemsAssetsWebpackBridge (WebPackConfig) {
69
+ const alias = WebPackConfig.resolve.alias
70
+ const bridgeFile = `${rootPath}/gems-assets-webpack-bridge.json`
71
+
72
+ var bridgeAlias = JSON.parse(fs.readFileSync(bridgeFile, 'utf8'))
73
+ return Object.assign(alias, bridgeAlias)
74
+ }
75
+
76
+ let WebpackConfig = {
77
+ entry: {
78
+ ...
79
+ },
80
+
81
+ output: {
82
+ ...
83
+ },
84
+
85
+ resolve : {
86
+ alias: {
87
+ '@vendors': `${rootPath}/assets/vendors`
88
+ }
89
+ }
90
+ }
91
+
92
+ WebPackConfig.resolve.alias = addGemsAssetsWebpackBridge(WebPackConfig)
93
+ module.exports = WebPackConfig
94
+ ```
95
+
96
+ After you added the aliases you can use them in your Webpack entries like this:
97
+
98
+ ```javascript
99
+ require('@log_js-scripts/log_js')
100
+ require('@notifications-scripts/notifications')
101
+ require('@the_comments-scripts/the_comments')
102
+
103
+ require('@notifications-styles/notifications')
104
+ require('@the_comments-styles/the_comments')
105
+ ```
106
+
107
+ ### How can I configure this gem?
108
+
109
+ You can create a new initializer in your Rails app change options:
110
+
111
+ **config/initializers/gems_assets_webpack_bridge.rb**
112
+
113
+ ```ruby
114
+ GemsAssetsWebpackBridge.configure do |config|
115
+ # From a root of your Rails app
116
+ config.bridge_path = '/configs/gems-webpack-bridge.json'
117
+
118
+ # From a root of every Rails gem
119
+ config.assets_types = {
120
+ # Default values
121
+ images: 'app/assets/images',
122
+ scripts: 'app/assets/javascripts',
123
+ styles: 'app/assets/stylesheets',
124
+
125
+ # Your custom values
126
+ vendor_select2_images: 'vendors/select2/images',
127
+ }
128
+ end
129
+ ```
130
+
131
+ ### Should I add the bridge file in my VCS?
132
+
133
+ No. Paths will be different for different users. Just add `gems-assets-webpack-bridge.json` in your `.gitignore` and run `rake gems_asstes_webpack_bridge:create` when you need it.
134
+
135
+ ### Should I change my deployment process?
136
+
137
+ You have to run `rake gems_asstes_webpack_bridge:create` before every Webpack compilation during deployment. Otherwise Webpack will know nothing about aliases and a compilation won't work.
138
+
139
+ ### License
140
+
141
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
142
+
143
+ [Bridge image @ pexels.com](https://www.pexels.com/photo/architecture-autumn-blue-blue-sky-208684/)
data/README.ru.md ADDED
@@ -0,0 +1,143 @@
1
+ # GemsAssetsWebpackBridge
2
+
3
+ Рельсовый гем, который помогает построить мост между ассетами в руби гемах и [Вебпаком](https://webpack.js.org/).
4
+
5
+ ![pexels-photo-208684](https://user-images.githubusercontent.com/496713/36936816-18261a9c-1f1b-11e8-9c46-6b6d830fed2c.jpeg)
6
+
7
+ ## Проблема
8
+
9
+ 1. У меня было классическое монолитное рельсовое приложение со Sprockets.
10
+ 2. Я разделил приложение на несколько рельсовых гемов и перенес в них ассеты.
11
+ 3. Я начал миграцию со Sprockets на Webpack.
12
+ 4. Webpack ничего не знал о путях к ассетах в моих рельсовых гемах.
13
+
14
+ ## Решение
15
+
16
+ Этот гем помогает собрать пути к ассетам в руби гемах и сделать [ссылки (алиасы)](https://webpack.js.org/configuration/resolve/#resolve-alias) для Вебпака, чтобы он мог найти ассеты в руби гемах.
17
+
18
+ ## Установка
19
+
20
+ **Gemfile**
21
+
22
+ ```ruby
23
+ gem 'gems_assets_webpack_bridge'
24
+ ```
25
+
26
+ ```
27
+ $ bundle
28
+ ```
29
+
30
+ ## Использование
31
+
32
+ Создать мост между рельсовыми гемами и Вебпаком:
33
+
34
+ ```ruby
35
+ rake gems_asstes_webpack_bridge:create
36
+ ```
37
+
38
+ ### Что такое Мост?
39
+
40
+ * Мост это JSON файл с путями к папкам ассетов в ваших руби гемах.
41
+ * Мост формирует [ссылки (алиасы)](https://webpack.js.org/configuration/resolve/#resolve-alias) для Вебпака, чтобы помочь ему найти ваши ассеты.
42
+ * Каждая ссылка имеет следующий формат: `@[UNDERSCORED_GEM_NAME]-[ASSET_TYPE]`.
43
+ * Типы ассетов по умолачнию: `images`, `scripts`, `styles`.
44
+ * Имя файла-моста по-умолчанию `gems-assets-webpack-bridge.json` и выглядит он примерно так:
45
+
46
+ ```json
47
+ {
48
+ "@crop_tool-scripts": "/Users/@username/.rvm/gems/ruby-2.4.2/gems/crop_tool/app/assets/javascripts",
49
+ "@crop_tool-styles": "/Users/@username/.rvm/gems/ruby-2.4.2/gems/crop_tool/app/assets/stylesheets",
50
+ "@jquery_ui_rails-images": "/Users/@username/.rvm/gems/ruby-2.3.3@open-cook.ru/gems/jquery-ui-rails-5.0.0/app/assets/images",
51
+ "@jquery_ui_rails-scripts": "/Users/@username/.rvm/gems/ruby-2.3.3@open-cook.ru/gems/jquery-ui-rails-5.0.0/app/assets/javascripts",
52
+ "@jquery_ui_rails-styles": "/Users/@username/.rvm/gems/ruby-2.3.3@open-cook.ru/gems/jquery-ui-rails-5.0.0/app/assets/stylesheets",
53
+ "@log_js-scripts": "/Users/@username/.rvm/gems/ruby-2.4.2/gems/log_js/app/assets/javascripts",
54
+ "@notifications-scripts": "/Users/@username/.rvm/gems/ruby-2.4.2/gems/notifications/app/assets/javascripts",
55
+ "@notifications-styles": "/Users/@username/.rvm/gems/ruby-2.4.2/gems/notifications/app/assets/stylesheets",
56
+ }
57
+ ```
58
+
59
+ ### Как использовать Мост?
60
+
61
+ Теперь, когда у вас есть файл-мост, вы можете использовать его в конфиге Вебпака:
62
+
63
+ **webpack.config.js**
64
+
65
+ ```javascript
66
+ // Эта функция читает файл-мост
67
+ // И добавляет ссылки в `WebPackConfig.resolve.alias`
68
+ function addGemsAssetsWebpackBridge (WebPackConfig) {
69
+ const alias = WebPackConfig.resolve.alias
70
+ const bridgeFile = `${rootPath}/gems-assets-webpack-bridge.json`
71
+
72
+ var bridgeAlias = JSON.parse(fs.readFileSync(bridgeFile, 'utf8'))
73
+ return Object.assign(alias, bridgeAlias)
74
+ }
75
+
76
+ let WebpackConfig = {
77
+ entry: {
78
+ ...
79
+ },
80
+
81
+ output: {
82
+ ...
83
+ },
84
+
85
+ resolve : {
86
+ alias: {
87
+ '@vendors': `${rootPath}/assets/vendors`
88
+ }
89
+ }
90
+ }
91
+
92
+ WebPackConfig.resolve.alias = addGemsAssetsWebpackBridge(WebPackConfig)
93
+ module.exports = WebPackConfig
94
+ ```
95
+
96
+ После того, как вы добавили ссылки в Вебпак, вы можете использовать их в энтри-поинтах:
97
+
98
+ ```javascript
99
+ require('@log_js-scripts/log_js')
100
+ require('@notifications-scripts/notifications')
101
+ require('@the_comments-scripts/the_comments')
102
+
103
+ require('@notifications-styles/notifications')
104
+ require('@the_comments-styles/the_comments')
105
+ ```
106
+
107
+ ### Как я могу сконфигурировать этот гем?
108
+
109
+ Создайте инициализатор в приложении и вы сможете настроить следующие значения:
110
+
111
+ **config/initializers/gems_assets_webpack_bridge.rb**
112
+
113
+ ```ruby
114
+ GemsAssetsWebpackBridge.configure do |config|
115
+ # От корня рельсового приложения
116
+ config.bridge_path = '/configs/gems-webpack-bridge.json'
117
+
118
+ # От корня любого гема
119
+ config.assets_types = {
120
+ # Значения по-умолчанию
121
+ images: 'app/assets/images',
122
+ scripts: 'app/assets/javascripts',
123
+ styles: 'app/assets/stylesheets',
124
+
125
+ # Ваши кастомные пути
126
+ vendor_select2_images: 'vendors/select2/images',
127
+ }
128
+ end
129
+ ```
130
+
131
+ ### Нужно ли мне добавлять файл-мост в мою систему контроля версий?
132
+
133
+ Нет. Пути будут у всех разные. Просто добавьте `gems-assets-webpack-bridge.json` в ваш `.gitignre` и запускайте `rake gems_asstes_webpack_bridge:create` когда вам это потребуется.
134
+
135
+ ### Нужно ли мне поменять процесс деплоя?
136
+
137
+ Вам нужно запускать `rake gems_asstes_webpack_bridge:create` перед каждой компиляцией Вебпака во время деплоя. Иначе Вебпак не будет ничего знать о дополнительных ссылках и компиляция не будет работать.
138
+
139
+ ### License
140
+
141
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
142
+
143
+ [Bridge image @ pexels.com](https://www.pexels.com/photo/architecture-autumn-blue-blue-sky-208684/)
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require_relative "./version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gems_assets_webpack_bridge"
8
+ spec.version = GemsAssetsWebpackBridge::VERSION
9
+ spec.authors = ["Ilya N. Zykin"]
10
+ spec.email = ["zykin-ilya@ya.ru"]
11
+
12
+ spec.summary = %q{The Bridge between Rails gems and Webpack}
13
+ spec.description = %q{Helps to make visible Rails gems's assets in Webpack}
14
+ spec.homepage = "https://github.com/the-teacher"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_development_dependency "bundler", "~> 1.16"
34
+ spec.add_development_dependency "rake", "~> 10.0"
35
+ end
data/lib/config.rb ADDED
@@ -0,0 +1,25 @@
1
+ module GemsAssetsWebpackBridge
2
+ def self.configure(&block)
3
+ yield @config ||= GemsAssetsWebpackBridge::Configuration.new
4
+ end
5
+
6
+ def self.config
7
+ @config
8
+ end
9
+
10
+ class Configuration
11
+ include ActiveSupport::Configurable
12
+
13
+ config_accessor :assets_types, :bridge_path
14
+ end
15
+
16
+ configure do |config|
17
+ config.assets_types = {
18
+ images: 'app/assets/images',
19
+ scripts: 'app/assets/javascripts',
20
+ styles: 'app/assets/stylesheets'
21
+ }
22
+
23
+ config.bridge_path = 'gems-assets-webpack-bridge.json'
24
+ end
25
+ end
@@ -0,0 +1,6 @@
1
+ require_relative "../version"
2
+ require_relative "./config"
3
+
4
+ module GemsAssetsWebpackBridge
5
+ class Engine < Rails::Engine; end
6
+ end
@@ -0,0 +1,30 @@
1
+ require 'json'
2
+
3
+ # rake gems_assets_webpack_bridge:create
4
+ namespace :gems_assets_webpack_bridge do
5
+ task create: :environment do
6
+ assets_types = GemsAssetsWebpackBridge.config.assets_types
7
+ bridge_path = GemsAssetsWebpackBridge.config.bridge_path
8
+
9
+ bridge = Bundler.load.specs.inject({}) do |bridge, gem|
10
+ assets_types.each do |type_name, type_path|
11
+ assets_path = "#{gem.full_gem_path}/#{type_path}"
12
+
13
+ if Dir.exist?(assets_path)
14
+ path_name = "@#{gem.name.underscore}-#{type_name}"
15
+ bridge[path_name] = assets_path
16
+ end
17
+ end
18
+
19
+ bridge
20
+ end
21
+
22
+ bridge_file = "#{Rails.root}/#{bridge_path}"
23
+ File.open(bridge_file, 'w') do |file|
24
+ file.write JSON.pretty_generate(bridge)
25
+ end
26
+
27
+ puts "GemsAssetsWebpackBridge"
28
+ puts "The bridge-file is created: #{bridge_file}"
29
+ end
30
+ end
data/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module GemsAssetsWebpackBridge
2
+ VERSION = "0.9.0"
3
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gems_assets_webpack_bridge
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.0
5
+ platform: ruby
6
+ authors:
7
+ - Ilya N. Zykin
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: Helps to make visible Rails gems's assets in Webpack
42
+ email:
43
+ - zykin-ilya@ya.ru
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - README.ru.md
53
+ - Rakefile
54
+ - gems_assets_webpack_bridge.gemspec
55
+ - lib/config.rb
56
+ - lib/gems_assets_webpack_bridge.rb
57
+ - lib/tasks/gems_assets_webpack_bridge.rake
58
+ - version.rb
59
+ homepage: https://github.com/the-teacher
60
+ licenses:
61
+ - MIT
62
+ metadata:
63
+ allowed_push_host: https://rubygems.org
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.6.14
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: The Bridge between Rails gems and Webpack
84
+ test_files: []