webpacker-remote 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c7c82d3d11b075effbc9efd05042438065ea37b9a46b2ad16298807fa9085706
4
+ data.tar.gz: 4e4d31ad15d8f4c9ec935e4dd332a426c7898889575196e42cd8061140799417
5
+ SHA512:
6
+ metadata.gz: 750042b0c9f5132196ad095c4ae340bedaa3d26973c4efe4e45af67c8203ca03f920e2c8a1b16974a5c314d0e03b48f830503503e806d05736db29ac23ce802c
7
+ data.tar.gz: ed9d1bb82d933b0d2af2170fc13c517acf996b905fe3a5115d66fcedd37de8a9ac34520efca0bae3e9170fa39c07731d49afdfc772f034875a1a352572860ecf
@@ -0,0 +1,33 @@
1
+ name: branch
2
+ on:
3
+ push:
4
+ branches-ignore:
5
+ - master
6
+ jobs:
7
+ build:
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ ruby: [ '2.7' ]
12
+ webpacker: [ '5.2.1' ]
13
+ name: Ruby ${{ matrix.ruby }}, Webpacker ${{ matrix.webpacker }}
14
+ steps:
15
+ - uses: actions/checkout@v2
16
+ - uses: actions/setup-ruby@v1
17
+ with:
18
+ ruby-version: ${{ matrix.ruby }}
19
+ - uses: actions/cache@v2
20
+ with:
21
+ path: vendor/bundle
22
+ key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.webpacker }}-${{ hashFiles('**/Gemfile') }}
23
+ restore-keys: |
24
+ ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.webpacker }}
25
+ - name: Test
26
+ env:
27
+ WEBPACKER_GEM_VERSION: ${{ matrix.webpacker }}
28
+ CI: true
29
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
30
+ run: |
31
+ bundle config path vendor/bundle
32
+ bundle install --jobs 4 --retry 3
33
+ bundle exec rake ci
@@ -0,0 +1,38 @@
1
+ name: ci
2
+ on:
3
+ pull_request:
4
+ types:
5
+ - opened
6
+ - synchronize
7
+ - reopened
8
+ push:
9
+ branches:
10
+ - master
11
+ jobs:
12
+ build:
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby: [ '2.7' ]
17
+ webpacker: [ '5.2.1' ]
18
+ name: Ruby ${{ matrix.ruby }}, Webpacker ${{ matrix.webpacker }}
19
+ steps:
20
+ - uses: actions/checkout@v2
21
+ - uses: actions/setup-ruby@v1
22
+ with:
23
+ ruby-version: ${{ matrix.ruby }}
24
+ - uses: actions/cache@v2
25
+ with:
26
+ path: vendor/bundle
27
+ key: ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.webpacker }}-${{ hashFiles('**/Gemfile') }}
28
+ restore-keys: |
29
+ ${{ runner.os }}-gems-${{ matrix.ruby }}-${{ matrix.webpacker }}
30
+ - name: Test
31
+ env:
32
+ WEBPACKER_GEM_VERSION: ${{ matrix.webpacker }}
33
+ CI: true
34
+ CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
35
+ run: |
36
+ bundle config path vendor/bundle
37
+ bundle install --jobs 4 --retry 3
38
+ bundle exec rake ci
@@ -0,0 +1,6 @@
1
+ Gemfile.lock
2
+ .rspec_status
3
+ .bundle
4
+ .rspec
5
+ bin
6
+ coverage/
@@ -0,0 +1,20 @@
1
+ AllCops:
2
+ NewCops: enable
3
+
4
+ Metrics/ClassLength:
5
+ Max: 150
6
+
7
+ Metrics/AbcSize:
8
+ Max: 30
9
+
10
+ Metrics/MethodLength:
11
+ Max: 30
12
+
13
+ Metrics/BlockLength:
14
+ Enabled: false
15
+
16
+ Style/Documentation:
17
+ Enabled: false
18
+
19
+ Style/ClassAndModuleChildren:
20
+ EnforcedStyle: compact
data/Gemfile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'codecov', require: false
8
+
9
+ gem 'rake', '~> 12.0'
10
+ gem 'rspec-github', '~> 2.3'
11
+
12
+ gem 'rubocop', '~> 1.0'
13
+ gem 'rubocop-performance', '~> 1.9.2'
14
+ gem 'rubocop-rake', '~> 0.5.1'
15
+ gem 'rubocop-rspec', '~> 2.1.0'
16
+
17
+ group :development do
18
+ gem 'benchmark-ips', require: false
19
+ gem 'pry-byebug', '~> 3.9'
20
+ end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2020 Vlad Bokov
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,103 @@
1
+ # Webpacker::Remote
2
+
3
+ ![](https://github.com/lunatic-cat/webpacker-remote/workflows/ci/badge.svg)
4
+ [![Gem Version](https://badge.fury.io/rb/webpacker-remote.svg)](https://badge.fury.io/rb/webpacker-remote)
5
+ [![codecov](https://codecov.io/gh/lunatic-cat/webpacker-remote/branch/master/graph/badge.svg?token=X5K67X3V0Z)](undefined)
6
+
7
+ - support for `create-react-app` developed in a separate repo
8
+ - support for multiple external frontend builds, right now `webpacker` is [a singleton](https://github.com/rails/webpacker/blob/6ba995aed2b609a27e4e35ec28b2a7f688cce0cf/lib/webpacker/helper.rb#L5L7)
9
+
10
+ ## Usage
11
+
12
+ - build `webpack` bundle & upload `build` directory (incl. `manifest.json`) before deploy
13
+ - in `config/initializers/remote_webpacker.rb`
14
+
15
+ ```rb
16
+ REMOTE_WEBPACKER = Webpacker::Remote.new(uri: 'https://../manifest.json')
17
+ ```
18
+
19
+ - in `app/views/layouts/application.html.erb` (**not** `javascript_pack_tag`)
20
+
21
+ ```rb
22
+ <%= javascript_packs_with_chunks_tag 'main', webpacker: REMOTE_WEBPACKER %>
23
+ ```
24
+
25
+ Of course, you can use as many build as you like and do blue-green deployments using gems like `rollout`
26
+
27
+ ## CRA Requirements
28
+
29
+ For `create-react-app` you should use `webpack-assets-manifest` instead of built-in `webpack-manifest-plugin`. You have to patch configuration like this:
30
+
31
+ - in `package.json`
32
+
33
+ ```diff
34
+ + "customize-cra": "^1.0.0",
35
+ + "react-app-rewired": "^2.1.8"
36
+ + "webpack-assets-manifest": "^3.1.1"
37
+ ...
38
+ - "build": "react-scripts build"
39
+ + "build": "react-app-rewired build"
40
+ ```
41
+
42
+ - add `config-overrides.js`
43
+
44
+ ```js
45
+ const { override } = require("customize-cra");
46
+ const WebpackAssetsManifest = require('webpack-assets-manifest')
47
+
48
+ const whenInMode = (mode, fn) => config => (config.mode == mode) ? fn(config) : config;
49
+
50
+ const removeWebpackPlugin = pluginName => config => {
51
+ config.plugins = config.plugins.filter(
52
+ p => p.constructor.name !== pluginName
53
+ );
54
+ return config;
55
+ };
56
+
57
+ const addWebpackPlugin = plugin => config => {
58
+ config.plugins.push(plugin);
59
+ return config;
60
+ };
61
+
62
+ const webpackerAssetManifestConfig = {
63
+ integrity: false,
64
+ entrypoints: true,
65
+ writeToDisk: true,
66
+ output: 'manifest.json'
67
+ };
68
+
69
+ module.exports = override(
70
+ removeWebpackPlugin('ManifestPlugin'),
71
+ whenInMode('production', addWebpackPlugin(new WebpackAssetsManifest(webpackerAssetManifestConfig)))
72
+ );
73
+ ```
74
+
75
+ - check `PUBLIC_URL='https://...' npm run build` and `build/manifest.json` should look like this:
76
+
77
+ ```json
78
+ {
79
+ "entrypoints": {
80
+ "main": {
81
+ "js": [
82
+ "static/js/runtime-main...js",
83
+ "static/js/2...chunk.js",
84
+ "static/js/main...chunk.js"
85
+ ],
86
+ "js.map": [
87
+ "static/js/runtime-main...js.map",
88
+ "static/js/2...chunk.js.map",
89
+ "static/js/main...chunk.js.map"
90
+ ],
91
+ "css": [
92
+ "static/css/2...chunk.css",
93
+ "static/css/main...chunk.css"
94
+ ]
95
+ }
96
+ },
97
+ "main.css": "static/css/main...chunk.css",
98
+ "main.js": "static/js/main...chunk.js",
99
+ "main.js.map": "static/js/main...chunk.js.map",
100
+ "runtime-main.js": "static/js/runtime-main...js",
101
+ "runtime-main.js.map": "static/js/runtime-main...js.map"
102
+ }
103
+ ```
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
9
+
10
+ RSpec::Core::RakeTask.new(:spec_github) do |t|
11
+ t.rspec_opts = '--format RSpec::Github::Formatter -f progress'
12
+ end
13
+
14
+ task ci: %i[rubocop spec_github]
15
+ task default: %i[rubocop spec]
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'uri'
5
+ require 'net/http'
6
+ require 'webpacker'
7
+
8
+ class Webpacker::Remote < Webpacker::Instance
9
+ require 'webpacker/remote/manifest'
10
+ require 'webpacker/remote/configuration'
11
+
12
+ VERSION = '0.1.0'
13
+
14
+ class Error < StandardError; end
15
+
16
+ attr_reader :public_manifest_content
17
+
18
+ # fetch early, fail fast
19
+ def initialize(uri:, root_path: nil, config_path: nil) # rubocop:disable Lint/UnusedMethodArgument
20
+ super(root_path: nil, config_path: nil)
21
+ @public_manifest_content = JSON.parse(self.class.get_http_response(uri))
22
+ @root_path = @config_path = Pathname.new('/non-existing-path-for-ctor-compatibility')
23
+ rescue StandardError => e
24
+ raise Error, "#{e.class}: #{e.message}"
25
+ end
26
+
27
+ def manifest
28
+ @manifest ||= Webpacker::Remote::Manifest.new(self)
29
+ end
30
+
31
+ def config
32
+ @config ||= Webpacker::Remote::Configuration.new(
33
+ root_path: root_path,
34
+ config_path: config_path,
35
+ env: env
36
+ )
37
+ end
38
+
39
+ # right now this only supports builds done ahead of time
40
+ def env
41
+ 'production'
42
+ end
43
+
44
+ def self.get_http_response(uri)
45
+ Net::HTTP.get_response(URI.parse(uri)).body
46
+ end
47
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'webpacker/configuration'
4
+
5
+ class Webpacker::Remote::Configuration < Webpacker::Configuration
6
+ def load
7
+ {
8
+ cache_manifest: true,
9
+ check_yarn_integrity: false,
10
+ compile: false
11
+ }
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'webpacker/manifest'
4
+
5
+ class Webpacker::Remote::Manifest < Webpacker::Manifest
6
+ def load
7
+ @webpacker.public_manifest_content
8
+ end
9
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ Gem::Specification.new do |spec|
4
+ spec.name = 'webpacker-remote'
5
+ spec.version = '0.1.0'
6
+ spec.authors = ['Vlad Bokov']
7
+ spec.email = ['vlad@lunatic.cat']
8
+ spec.license = 'MIT'
9
+
10
+ spec.summary = 'Inject external webpack builds into Rails'
11
+ spec.description = 'Use your webpack builds independently'
12
+ spec.homepage = 'https://github.com/lunatic-cat/webpacker-remote'
13
+ spec.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
14
+
15
+ spec.metadata['homepage_uri'] = spec.homepage
16
+ spec.metadata['source_code_uri'] = 'https://github.com/lunatic-cat/webpacker-remote'
17
+
18
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
19
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
20
+ end
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_dependency('webpacker', ENV.fetch('WEBPACKER_GEM_VERSION', '~> 5.2'))
24
+
25
+ spec.add_development_dependency('rspec', '~> 3.0')
26
+ spec.add_development_dependency('rspec-expectations', '~> 3.0')
27
+ spec.add_development_dependency('simplecov', '~> 0.19')
28
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: webpacker-remote
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vlad Bokov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-01-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: webpacker
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-expectations
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.19'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.19'
69
+ description: Use your webpack builds independently
70
+ email:
71
+ - vlad@lunatic.cat
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".github/workflows/branch.yml"
77
+ - ".github/workflows/ci.yml"
78
+ - ".gitignore"
79
+ - ".rubocop.yml"
80
+ - Gemfile
81
+ - LICENSE
82
+ - README.md
83
+ - Rakefile
84
+ - lib/webpacker/remote.rb
85
+ - lib/webpacker/remote/configuration.rb
86
+ - lib/webpacker/remote/manifest.rb
87
+ - webpacker-remote.gemspec
88
+ homepage: https://github.com/lunatic-cat/webpacker-remote
89
+ licenses:
90
+ - MIT
91
+ metadata:
92
+ homepage_uri: https://github.com/lunatic-cat/webpacker-remote
93
+ source_code_uri: https://github.com/lunatic-cat/webpacker-remote
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: 2.4.0
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubygems_version: 3.0.8
110
+ signing_key:
111
+ specification_version: 4
112
+ summary: Inject external webpack builds into Rails
113
+ test_files: []