railspacker 0.1.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 +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +54 -0
- data/Rakefile +27 -0
- data/bin/test +5 -0
- data/lib/generators/railspacker/install_generator.rb +27 -0
- data/lib/generators/templates/config/initializers/railspacker.rb +11 -0
- data/lib/generators/templates/package.json +9 -0
- data/lib/generators/templates/webpack.config.js +47 -0
- data/lib/railspacker/helper.rb +15 -0
- data/lib/railspacker/manifest/build.rb +13 -0
- data/lib/railspacker/manifest/dev_server.rb +15 -0
- data/lib/railspacker/railtie.rb +19 -0
- data/lib/railspacker/version.rb +3 -0
- data/lib/railspacker.rb +12 -0
- data/lib/tasks/railspacker_tasks.rake +9 -0
- metadata +86 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: c24630dcc6c82027087d8970696856e24fb6bd652db7a18546e96e3d42f017e9
|
|
4
|
+
data.tar.gz: eb89e2d01b53f91700902992b8a03bd59b0bdf7ff7235f7c9b683e16319b474b
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 52d2ff5c65e364b98feca23f5df11bb32ca7f279f041faaaba8d0eff2fba9cff99e848ce224edf2a2b3e969a01e3d606198177f29e7eff02e95638383ceff659
|
|
7
|
+
data.tar.gz: 4cd86153360a79885a9a5ffeaca6668fe2a7d70d28a5d8a22cf62244f8b63a131ee925a618bb5346e578a6c842061e9287a6156de549280c352ce4df60d621f6
|
data/MIT-LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Copyright 2019 Alexandre Magro
|
|
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.
|
data/README.md
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Railspacker
|
|
2
|
+
Railspacker is a alternative to Webpacker. The motivation is to give more control over the webpack to the developer, avoiding wrapping it in ruby, opting for the configuration.
|
|
3
|
+
|
|
4
|
+
## Status
|
|
5
|
+
|
|
6
|
+
This is an early version, if you liked the design concept, and intend to use it, let me know. Consider contributing, knowledge with testing for rails plugins will be welcome.
|
|
7
|
+
|
|
8
|
+
## Prerequisites
|
|
9
|
+
|
|
10
|
+
- Ruby 5.1 (+ Yarn);
|
|
11
|
+
- WebpackManifestPlugin on;
|
|
12
|
+
|
|
13
|
+
## Getting started
|
|
14
|
+
Add this line to your application's Gemfile:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
gem 'railspacker'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Then run `bundle install`
|
|
21
|
+
|
|
22
|
+
Next, you need to run the generator:
|
|
23
|
+
```bash
|
|
24
|
+
$ rails generate railspacker:install
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Add script in application template via `pack_path`
|
|
28
|
+
```html
|
|
29
|
+
<%= javascript_include_tag pack_path('pack_name.js') %>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Railspacker has created the necessary files and a preconfiguration for you to begin development. Read the next session to understand how to proceed.
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
### Development
|
|
37
|
+
|
|
38
|
+
Start WebpackDevServer in separated process to serve live code reloading assets:
|
|
39
|
+
```bash
|
|
40
|
+
$ yarn run serve
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**NOTE:** The devServer already comes preconfigured, if you want to change the configuration, be sure to look at the railspacker configuration in `config/initializers/railspacker.rb`
|
|
44
|
+
|
|
45
|
+
### Test
|
|
46
|
+
|
|
47
|
+
System test approach is: compile packs before tests. For this, Railspacker installer added command `Railspacker.run 'build-test'` to your ApplicationSystemTestCase. So, when you run System Tests, yarn will run package script named `'build-test'`. The output `public/packs-test` will be created, and ignored to git via `.gitignore`
|
|
48
|
+
|
|
49
|
+
### Production
|
|
50
|
+
|
|
51
|
+
To production environment, Railspacker enhance the task `rails assets:precompile`. Thus, the packages will be compiled soon after the assets `task:precompile`.
|
|
52
|
+
|
|
53
|
+
## License
|
|
54
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'Railspacker'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
require 'bundler/gem_tasks'
|
|
18
|
+
|
|
19
|
+
require 'rake/testtask'
|
|
20
|
+
|
|
21
|
+
Rake::TestTask.new(:test) do |t|
|
|
22
|
+
t.libs << 'test'
|
|
23
|
+
t.pattern = 'test/**/*_test.rb'
|
|
24
|
+
t.verbose = false
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
task default: :test
|
data/bin/test
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module Railspacker
|
|
2
|
+
module Generators
|
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
|
4
|
+
source_root File.expand_path('../../templates', __FILE__)
|
|
5
|
+
|
|
6
|
+
def create_initializer_file
|
|
7
|
+
copy_file 'package.json', './package.json'
|
|
8
|
+
copy_file 'webpack.config.js', './webpack.config.js'
|
|
9
|
+
copy_file 'config/initializers/railspacker.rb', 'config/initializers/railspacker.rb'
|
|
10
|
+
empty_directory './app/webpack'
|
|
11
|
+
|
|
12
|
+
append_to_file '.gitignore' do
|
|
13
|
+
<<~TEXT
|
|
14
|
+
|
|
15
|
+
# Ignore precompiled javascript packs
|
|
16
|
+
/public/packs
|
|
17
|
+
/public/packs-test
|
|
18
|
+
TEXT
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
inject_into_class 'test/application_system_test_case.rb', 'ApplicationSystemTestCase' do
|
|
22
|
+
" Railspacker.run 'build-test'\n\n"
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# `build` script will run before the `assets:precompile` task
|
|
2
|
+
# Railspacker.before_assets_precompile_script = 'build'
|
|
3
|
+
|
|
4
|
+
Railspacker.manifest = case Rails.env
|
|
5
|
+
when 'development'
|
|
6
|
+
Railspacker::Manifest::DevServer.new(url: 'http://localhost:3001')
|
|
7
|
+
when 'test'
|
|
8
|
+
Railspacker::Manifest::Build.new(public_path: 'packs-test')
|
|
9
|
+
when 'production'
|
|
10
|
+
Railspacker::Manifest::Build.new(public_path: 'packs')
|
|
11
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
// Add dependencies
|
|
2
|
+
//
|
|
3
|
+
// `yarn add webpack clean-webpack-plugin webpack-manifest-plugin`
|
|
4
|
+
|
|
5
|
+
const path = require('path');
|
|
6
|
+
const CleanWebpackPlugin = require('clean-webpack-plugin');
|
|
7
|
+
const ManifestPlugin = require('webpack-manifest-plugin');
|
|
8
|
+
const webpack = require('webpack');
|
|
9
|
+
|
|
10
|
+
module.exports = (env) => {
|
|
11
|
+
const config = {};
|
|
12
|
+
const outputPath = (env == 'test') ? 'public/packs-test' : 'public/packs';
|
|
13
|
+
|
|
14
|
+
config.entry = {
|
|
15
|
+
app: './app/webpack/index.js'
|
|
16
|
+
};
|
|
17
|
+
config.plugins = [
|
|
18
|
+
// Generate a manifest.json to output. Is requred to Railspacker.
|
|
19
|
+
new ManifestPlugin(),
|
|
20
|
+
|
|
21
|
+
// Clean output directory before builds
|
|
22
|
+
new CleanWebpackPlugin([outputPath]),
|
|
23
|
+
|
|
24
|
+
// Enables Hot Module Replacement, otherwise known as HMR.
|
|
25
|
+
new webpack.HotModuleReplacementPlugin()
|
|
26
|
+
];
|
|
27
|
+
config.output = {
|
|
28
|
+
filename: '[name].js',
|
|
29
|
+
path: path.resolve(__dirname, outputPath)
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
if (env === 'development' || env === 'test') {
|
|
33
|
+
config.mode = 'development'
|
|
34
|
+
config.devtool = 'inline-source-map'
|
|
35
|
+
config.devServer = {
|
|
36
|
+
contentBase: path.resolve(__dirname, 'app/webpack'),
|
|
37
|
+
port: 3001,
|
|
38
|
+
hot: true
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
if (env === 'production') {
|
|
43
|
+
config.mode = 'production'
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return config;
|
|
47
|
+
};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Railspacker::Helper
|
|
2
|
+
def pack_path(name)
|
|
3
|
+
manifest = Railspacker.manifest.load
|
|
4
|
+
|
|
5
|
+
if manifest.nil?
|
|
6
|
+
raise "manifest.json not found."
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
if !manifest.key?(name)
|
|
10
|
+
raise "Pack not found in manifest.json: #{name}"
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
[Railspacker.manifest.path_to, manifest[name]].join('/')
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Railspacker::Manifest
|
|
2
|
+
class Build < Struct.new(:public_path, keyword_init: true)
|
|
3
|
+
def load
|
|
4
|
+
file = Rails.public_path.join(public_path).join('manifest.json')
|
|
5
|
+
|
|
6
|
+
JSON.parse File.read(file)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def path_to
|
|
10
|
+
Pathname.new('/').join(public_path)
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require "railspacker/helper"
|
|
2
|
+
|
|
3
|
+
module Railspacker
|
|
4
|
+
class Railtie < ::Rails::Railtie
|
|
5
|
+
rake_tasks do
|
|
6
|
+
load 'tasks/railspacker_tasks.rake'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
initializer 'railspacker.helper' do
|
|
10
|
+
ActiveSupport.on_load :action_controller do
|
|
11
|
+
ActionController::Base.helper Railspacker::Helper
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
ActiveSupport.on_load :action_view do
|
|
15
|
+
include Railspacker::Helper
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
data/lib/railspacker.rb
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require "railspacker/railtie"
|
|
2
|
+
require "railspacker/manifest/build"
|
|
3
|
+
require "railspacker/manifest/dev_server"
|
|
4
|
+
|
|
5
|
+
module Railspacker
|
|
6
|
+
mattr_accessor :manifest
|
|
7
|
+
mattr_accessor :before_assets_precompile_script, default: 'build'
|
|
8
|
+
|
|
9
|
+
def self.run(name)
|
|
10
|
+
system("yarn run #{name}")
|
|
11
|
+
end
|
|
12
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
if Rake::Task.task_defined?("assets:precompile")
|
|
2
|
+
Rake::Task['assets:precompile'].enhance do
|
|
3
|
+
Railspacker.run Railspacker.before_assets_precompile_script
|
|
4
|
+
end
|
|
5
|
+
else
|
|
6
|
+
Rake::Task.define_task("assets:precompile") do
|
|
7
|
+
Railspacker.run Railspacker.before_assets_precompile_script
|
|
8
|
+
end
|
|
9
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: railspacker
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Alexandre Magro
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2019-02-01 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: rails
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '5.1'
|
|
20
|
+
type: :runtime
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '5.1'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: sqlite3
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - ">="
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - ">="
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '0'
|
|
41
|
+
description:
|
|
42
|
+
email:
|
|
43
|
+
- alexandremagro@live.com
|
|
44
|
+
executables: []
|
|
45
|
+
extensions: []
|
|
46
|
+
extra_rdoc_files: []
|
|
47
|
+
files:
|
|
48
|
+
- MIT-LICENSE
|
|
49
|
+
- README.md
|
|
50
|
+
- Rakefile
|
|
51
|
+
- bin/test
|
|
52
|
+
- lib/generators/railspacker/install_generator.rb
|
|
53
|
+
- lib/generators/templates/config/initializers/railspacker.rb
|
|
54
|
+
- lib/generators/templates/package.json
|
|
55
|
+
- lib/generators/templates/webpack.config.js
|
|
56
|
+
- lib/railspacker.rb
|
|
57
|
+
- lib/railspacker/helper.rb
|
|
58
|
+
- lib/railspacker/manifest/build.rb
|
|
59
|
+
- lib/railspacker/manifest/dev_server.rb
|
|
60
|
+
- lib/railspacker/railtie.rb
|
|
61
|
+
- lib/railspacker/version.rb
|
|
62
|
+
- lib/tasks/railspacker_tasks.rake
|
|
63
|
+
homepage: https://github.com/alexandremagro/railspacker
|
|
64
|
+
licenses:
|
|
65
|
+
- MIT
|
|
66
|
+
metadata: {}
|
|
67
|
+
post_install_message:
|
|
68
|
+
rdoc_options: []
|
|
69
|
+
require_paths:
|
|
70
|
+
- lib
|
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
|
+
requirements:
|
|
73
|
+
- - ">="
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
|
+
requirements:
|
|
78
|
+
- - ">="
|
|
79
|
+
- !ruby/object:Gem::Version
|
|
80
|
+
version: '0'
|
|
81
|
+
requirements: []
|
|
82
|
+
rubygems_version: 3.0.1
|
|
83
|
+
signing_key:
|
|
84
|
+
specification_version: 4
|
|
85
|
+
summary: Railspacker is an alternative to Webpacker
|
|
86
|
+
test_files: []
|