simpacker 0.2.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +13 -0
- data/README.md +41 -6
- data/lib/install/javascript/{application.ts → application.js} +0 -0
- data/lib/install/javascript/greeter.js +3 -0
- data/lib/install/root/webpack.config.js +3 -15
- data/lib/install/template.rb +0 -3
- data/lib/simpacker.rb +3 -6
- data/lib/simpacker/configuration.rb +5 -30
- data/lib/simpacker/context.rb +33 -0
- data/lib/simpacker/helper.rb +9 -5
- data/lib/simpacker/manifest.rb +9 -8
- data/lib/simpacker/version.rb +1 -1
- data/simpacker.gemspec +4 -4
- metadata +16 -14
- data/lib/install/javascript/greeter.ts +0 -3
- data/lib/install/root/tsconfig.json +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0523cb48ed8bb338019021e9fb4a1753f891cc2a02b314204641f78751bef706
|
4
|
+
data.tar.gz: 11ba83077029dc703d72d8bdeca29967fb93326805a03f0c463e311cd3f075c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8359e0a9512f9ac4cd3afd44ae2471b777d33dd89b9493265951e12a82acc8b4e6f27b8a6acc456a2e9fdf62e2cd655f3e3d792897af1803657be24d6fe5b41
|
7
|
+
data.tar.gz: 8b6b9d1326a9da1e1439240acaecd77e7fd2f8cf114c66d19b4fcb02fde7c72a7d2a8479411afc85cc6b8a2c0adb6e35714459da2ee80e98c3e510250b348af4
|
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
language: ruby
|
data/CHANGELOG.md
ADDED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Simpacker
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/hokaccha/simpacker.svg?branch=master)](https://travis-ci.org/hokaccha/simpacker) [![Gem Version](https://badge.fury.io/rb/simpacker.svg)](https://badge.fury.io/rb/simpacker)
|
4
|
+
|
3
5
|
Simpacker provides the feature to integrate modern JavaScript build system with Rails, like a [webpacker](https://github.com/rails/webpacker).
|
4
6
|
|
5
7
|
## Installation
|
@@ -7,7 +9,7 @@ Simpacker provides the feature to integrate modern JavaScript build system with
|
|
7
9
|
Create a new rails application without webpacker.
|
8
10
|
|
9
11
|
```
|
10
|
-
$ rails new myapp
|
12
|
+
$ rails new myapp --skip-javascript
|
11
13
|
```
|
12
14
|
|
13
15
|
Add this line to your application's Gemfile:
|
@@ -31,12 +33,43 @@ Add `javascript_pack_tag` in view.
|
|
31
33
|
Run the folloing command to build JavaScript.
|
32
34
|
|
33
35
|
```
|
34
|
-
$
|
36
|
+
$ ./node_modules/.bin/webpack --watch
|
35
37
|
```
|
36
38
|
|
37
|
-
##
|
38
|
-
|
39
|
-
|
39
|
+
## Examples
|
40
|
+
|
41
|
+
- Webpack settings
|
42
|
+
- [webpack-dev-server](https://github.com/hokaccha/simpacker/tree/master/example/webpack-dev-server)
|
43
|
+
- [Multiple Entry Point](https://github.com/hokaccha/simpacker/tree/master/example/multiple-entry-points)
|
44
|
+
- Transpilers
|
45
|
+
- [TypeScript](https://github.com/hokaccha/simpacker/tree/master/example/typescript)
|
46
|
+
- [Babel](https://github.com/hokaccha/simpacker/tree/master/example/babel)
|
47
|
+
- Style Sheets
|
48
|
+
- [CSS](https://github.com/hokaccha/simpacker/tree/master/example/css)
|
49
|
+
- [Sass](https://github.com/hokaccha/simpacker/tree/master/example/sass)
|
50
|
+
- [PostCSS](https://github.com/hokaccha/simpacker/tree/master/example/postcss)
|
51
|
+
- Frameworks
|
52
|
+
- [React(TypeScript)](https://github.com/hokaccha/simpacker/tree/master/example/react-typescript)
|
53
|
+
- [React(Babel)](https://github.com/hokaccha/simpacker/tree/master/example/react-babel)
|
54
|
+
- [Vue.js](https://github.com/hokaccha/simpacker/tree/master/example/vue)
|
55
|
+
- [Angular](https://github.com/hokaccha/simpacker/tree/master/example/angular)
|
56
|
+
- Deployment
|
57
|
+
- [CDN](https://github.com/hokaccha/simpacker/tree/master/example/asset-host)
|
58
|
+
- [Heroku](https://github.com/hokaccha/simpacker/tree/master/example/heroku)
|
59
|
+
- [Docker](https://github.com/hokaccha/simpacker/tree/master/example/docker)
|
60
|
+
- Advanced settings
|
61
|
+
- [Rails Engines](https://github.com/hokaccha/simpacker/tree/master/example/engines)
|
62
|
+
- [Custom helper](https://github.com/hokaccha/simpacker/tree/master/example/custom-helper)
|
63
|
+
- Bundler
|
64
|
+
- [Parcel](https://github.com/hokaccha/simpacker/tree/master/example/parcel)
|
65
|
+
|
66
|
+
## VS. Webpacker
|
67
|
+
|
68
|
+
Webpacker is a great product that you can easily use webpack without knowing it. It also provides many useful features. The difficulty with Webpacker is that you need to configure webpack via webpacker's own DSL and webpacker.yml. If you know how to configure webpack, you need to convert it to webpacker configuration. I want to edit webpack.config.js directly!
|
69
|
+
|
70
|
+
Simpacker provides only minimal features that lookup the manifest.json output by webpack and a create script tag through javascript_pack_tag. You need to know about webpack, but there is little to know about Simpacker.
|
71
|
+
|
72
|
+
However, some useful features of Webpacker, such as yarn integrity and compilation on request, are not available in Simpacker.
|
40
73
|
|
41
74
|
## Deployment
|
42
75
|
|
@@ -44,9 +77,11 @@ Simpacker does not provide feature for deployment. Just run the following comman
|
|
44
77
|
|
45
78
|
```
|
46
79
|
$ npm install
|
47
|
-
$ NODE_ENV=production
|
80
|
+
$ NODE_ENV=production ./node_modules/.bin/webpack
|
48
81
|
```
|
49
82
|
|
83
|
+
See also: [CDN](https://github.com/hokaccha/simpacker/tree/master/example/asset-host), [Heroku](https://github.com/hokaccha/simpacker/tree/master/example/heroku), [Docker](https://github.com/hokaccha/simpacker/tree/master/example/docker)
|
84
|
+
|
50
85
|
## Contributing
|
51
86
|
|
52
87
|
Bug reports and pull requests are welcome on GitHub at https://github.com/hokaccha/simpacker.
|
File without changes
|
@@ -8,27 +8,15 @@ module.exports = {
|
|
8
8
|
mode: isProd ? "production" : "development",
|
9
9
|
devtool: "source-map",
|
10
10
|
entry: {
|
11
|
-
application: path.resolve(__dirname, "app/javascript/application.
|
11
|
+
application: path.resolve(__dirname, "app/javascript/application.js")
|
12
12
|
},
|
13
13
|
output: {
|
14
14
|
path: path.resolve(__dirname, "public/packs"),
|
15
15
|
publicPath: "/packs/",
|
16
|
-
filename: isProd ? "[name]-[hash].js" : "[name].js"
|
17
|
-
chunkFilename: "[id]-[chunkhash].js"
|
16
|
+
filename: isProd ? "[name]-[hash].js" : "[name].js"
|
18
17
|
},
|
19
18
|
resolve: {
|
20
|
-
extensions: [".js"
|
21
|
-
},
|
22
|
-
module: {
|
23
|
-
rules: [
|
24
|
-
{
|
25
|
-
test: /\.tsx?$/,
|
26
|
-
loader: "ts-loader",
|
27
|
-
options: {
|
28
|
-
transpileOnly: true
|
29
|
-
}
|
30
|
-
}
|
31
|
-
]
|
19
|
+
extensions: [".js"]
|
32
20
|
},
|
33
21
|
plugins: [new WebpackAssetsManifest({ publicPath: true })]
|
34
22
|
};
|
data/lib/install/template.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
puts "Copying config files"
|
2
2
|
copy_file "#{__dir__}/config/simpacker.yml", "config/simpacker.yml"
|
3
3
|
copy_file "#{__dir__}/root/webpack.config.js", "webpack.config.js"
|
4
|
-
copy_file "#{__dir__}/root/tsconfig.json", "tsconfig.json"
|
5
4
|
|
6
5
|
unless File.exist?('package.json')
|
7
6
|
copy_file "#{__dir__}/root/package.json", "package.json"
|
@@ -24,8 +23,6 @@ dep_packages = %w(
|
|
24
23
|
webpack
|
25
24
|
webpack-cli
|
26
25
|
webpack-assets-manifest
|
27
|
-
typescript
|
28
|
-
ts-loader
|
29
26
|
).join(' ')
|
30
27
|
|
31
28
|
say "Installing npm packages"
|
data/lib/simpacker.rb
CHANGED
@@ -1,14 +1,11 @@
|
|
1
|
+
require "simpacker/context"
|
1
2
|
require "simpacker/configuration"
|
2
3
|
require "simpacker/manifest"
|
3
4
|
require "simpacker/helper"
|
4
5
|
require "simpacker/railtie"
|
5
6
|
|
6
7
|
module Simpacker
|
7
|
-
def self.
|
8
|
-
@
|
9
|
-
end
|
10
|
-
|
11
|
-
def self.manifest
|
12
|
-
@manifest ||= Simpacker::Manifest.new(config)
|
8
|
+
def self.default_context
|
9
|
+
@default_context ||= Simpacker::Context.new
|
13
10
|
end
|
14
11
|
end
|
@@ -1,39 +1,14 @@
|
|
1
|
-
require "yaml"
|
2
|
-
|
3
1
|
module Simpacker
|
4
2
|
class Configuration
|
5
|
-
attr_accessor :
|
6
|
-
|
7
|
-
def initialize
|
8
|
-
@root_path = Rails.root
|
9
|
-
@config_path = @root_path.join("config/simpacker.yml")
|
10
|
-
@env = Rails.env
|
11
|
-
end
|
3
|
+
attr_accessor :manifest_path, :cache_manifest
|
12
4
|
|
13
|
-
def manifest_path
|
14
|
-
|
5
|
+
def initialize(manifest_path:, cache_manifest: true)
|
6
|
+
@manifest_path = manifest_path
|
7
|
+
@cache_manifest = cache_manifest
|
15
8
|
end
|
16
9
|
|
17
10
|
def cache_manifest?
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def data
|
24
|
-
@data ||= load
|
25
|
-
end
|
26
|
-
|
27
|
-
def load
|
28
|
-
YAML.load(config_path.read)[env]
|
29
|
-
rescue Errno::ENOENT => e
|
30
|
-
raise "Simpacker configuration file not found #{config_path}. " \
|
31
|
-
"Please run rails simpacker:install " \
|
32
|
-
"Error: #{e.message}"
|
33
|
-
rescue Psych::SyntaxError => e
|
34
|
-
raise "YAML syntax error occurred while parsing #{config_path}. " \
|
35
|
-
"Please note that YAML must be consistently indented using spaces. Tabs are not allowed. " \
|
36
|
-
"Error: #{e.message}"
|
11
|
+
!!cache_manifest
|
37
12
|
end
|
38
13
|
end
|
39
14
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require "yaml"
|
2
|
+
|
3
|
+
module Simpacker
|
4
|
+
class Context
|
5
|
+
class InvalidConfigurationError < StandardError; end
|
6
|
+
|
7
|
+
attr_reader :config, :manifest
|
8
|
+
|
9
|
+
def initialize(root_path: Rails.root, env: Rails.env)
|
10
|
+
config = load_config_file(root_path, env)
|
11
|
+
@config = Simpacker::Configuration.new(**config)
|
12
|
+
@manifest = Simpacker::Manifest.new(@config)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def load_config_file(root_path, env)
|
18
|
+
config_path = root_path.join("config/simpacker.yml")
|
19
|
+
yaml = YAML.load(config_path.read)
|
20
|
+
config_env = yaml.fetch(env.to_s)
|
21
|
+
{
|
22
|
+
manifest_path: root_path.join(config_env.fetch('manifest_path')),
|
23
|
+
cache_manifest: config_env.fetch('cache_manifest'),
|
24
|
+
}
|
25
|
+
rescue Errno::ENOENT
|
26
|
+
raise Simpacker::Context::InvalidConfigurationError, "Simpacker configuration file not found #{config_path}"
|
27
|
+
rescue KeyError => err
|
28
|
+
raise Simpacker::Context::InvalidConfigurationError, "Missing field: `#{err.key}` in #{config_path}"
|
29
|
+
rescue Psych::SyntaxError => err
|
30
|
+
raise Simpacker::Context::InvalidConfigurationError, "YAML syntax error occurred while parsing #{config_path}. Error: #{err.message}"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
data/lib/simpacker/helper.rb
CHANGED
@@ -2,28 +2,32 @@ module Simpacker
|
|
2
2
|
module Helper
|
3
3
|
def javascript_pack_tag(*names, **options)
|
4
4
|
sources = names.map do |name|
|
5
|
-
|
5
|
+
simpacker_context.manifest.lookup!("#{name}#{compute_asset_extname(name.to_s, type: :javascript)}")
|
6
6
|
end
|
7
7
|
javascript_include_tag(*sources, **options)
|
8
8
|
end
|
9
9
|
|
10
10
|
def stylesheet_pack_tag(*names, **options)
|
11
11
|
sources = names.map do |name|
|
12
|
-
|
12
|
+
simpacker_context.manifest.lookup!("#{name}#{compute_asset_extname(name.to_s, type: :stylesheet)}")
|
13
13
|
end
|
14
14
|
stylesheet_link_tag(*sources, **options)
|
15
15
|
end
|
16
16
|
|
17
17
|
def asset_pack_path(name, **options)
|
18
|
-
asset_path(
|
18
|
+
asset_path(simpacker_context.manifest.lookup!(name), **options)
|
19
19
|
end
|
20
20
|
|
21
21
|
def asset_pack_url(name, **options)
|
22
|
-
asset_url(
|
22
|
+
asset_url(simpacker_context.manifest.lookup!(name), **options)
|
23
23
|
end
|
24
24
|
|
25
25
|
def image_pack_tag(name, **options)
|
26
|
-
image_tag(asset_path(
|
26
|
+
image_tag(asset_path(simpacker_context.manifest.lookup!(name)), **options)
|
27
|
+
end
|
28
|
+
|
29
|
+
def simpacker_context
|
30
|
+
Simpacker.default_context
|
27
31
|
end
|
28
32
|
end
|
29
33
|
end
|
data/lib/simpacker/manifest.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Simpacker
|
2
2
|
class Manifest
|
3
3
|
class MissingEntryError < StandardError; end
|
4
|
+
class MissingFileError < StandardError; end
|
4
5
|
|
5
6
|
attr_reader :config
|
6
7
|
|
@@ -8,18 +9,18 @@ module Simpacker
|
|
8
9
|
@config = config
|
9
10
|
end
|
10
11
|
|
11
|
-
def lookup(
|
12
|
-
data
|
12
|
+
def lookup(*names)
|
13
|
+
data.dig(*names.map(&:to_s))
|
13
14
|
end
|
14
15
|
|
15
|
-
def lookup!(
|
16
|
-
lookup(
|
16
|
+
def lookup!(*names)
|
17
|
+
lookup(*names) || handle_missing_entry(names)
|
17
18
|
end
|
18
19
|
|
19
20
|
private
|
20
21
|
|
21
|
-
def handle_missing_entry(
|
22
|
-
raise Simpacker::Manifest::MissingEntryError
|
22
|
+
def handle_missing_entry(names)
|
23
|
+
raise Simpacker::Manifest::MissingEntryError, "Missing field: #{names.join('.')}"
|
23
24
|
end
|
24
25
|
|
25
26
|
def data
|
@@ -31,10 +32,10 @@ module Simpacker
|
|
31
32
|
end
|
32
33
|
|
33
34
|
def load
|
34
|
-
if config.manifest_path.exist?
|
35
|
+
if config.manifest_path.exist? && config.manifest_path.file?
|
35
36
|
JSON.parse(config.manifest_path.read)
|
36
37
|
else
|
37
|
-
{}
|
38
|
+
raise Simpacker::Manifest::MissingFileError, "Missing manifest file: #{config.manifest_path}"
|
38
39
|
end
|
39
40
|
end
|
40
41
|
end
|
data/lib/simpacker/version.rb
CHANGED
data/simpacker.gemspec
CHANGED
@@ -21,8 +21,8 @@ Gem::Specification.new do |spec|
|
|
21
21
|
|
22
22
|
spec.add_dependency "railties", ">= 4.2"
|
23
23
|
|
24
|
-
spec.add_development_dependency "bundler", "
|
25
|
-
spec.add_development_dependency "rake", "
|
26
|
-
spec.add_development_dependency "rails", "
|
27
|
-
spec.add_development_dependency "minitest", "
|
24
|
+
spec.add_development_dependency "bundler", ">= 1.16"
|
25
|
+
spec.add_development_dependency "rake", ">= 10.0"
|
26
|
+
spec.add_development_dependency "rails", ">= 5.2"
|
27
|
+
spec.add_development_dependency "minitest", ">= 5.1"
|
28
28
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simpacker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kazuhito Hokamura
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -28,56 +28,56 @@ dependencies:
|
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.16'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.16'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - "
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '10.0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - "
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '10.0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '5.2'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '5.2'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: minitest
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '5.1'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - "
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '5.1'
|
83
83
|
description: Integrate modern JavaScript build system with Rails.
|
@@ -88,20 +88,22 @@ extensions: []
|
|
88
88
|
extra_rdoc_files: []
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
|
+
- ".travis.yml"
|
92
|
+
- CHANGELOG.md
|
91
93
|
- Gemfile
|
92
94
|
- README.md
|
93
95
|
- Rakefile
|
94
96
|
- bin/console
|
95
97
|
- bin/setup
|
96
98
|
- lib/install/config/simpacker.yml
|
97
|
-
- lib/install/javascript/application.
|
98
|
-
- lib/install/javascript/greeter.
|
99
|
+
- lib/install/javascript/application.js
|
100
|
+
- lib/install/javascript/greeter.js
|
99
101
|
- lib/install/root/package.json
|
100
|
-
- lib/install/root/tsconfig.json
|
101
102
|
- lib/install/root/webpack.config.js
|
102
103
|
- lib/install/template.rb
|
103
104
|
- lib/simpacker.rb
|
104
105
|
- lib/simpacker/configuration.rb
|
106
|
+
- lib/simpacker/context.rb
|
105
107
|
- lib/simpacker/helper.rb
|
106
108
|
- lib/simpacker/manifest.rb
|
107
109
|
- lib/simpacker/railtie.rb
|
@@ -127,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
127
129
|
- !ruby/object:Gem::Version
|
128
130
|
version: '0'
|
129
131
|
requirements: []
|
130
|
-
rubygems_version: 3.
|
132
|
+
rubygems_version: 3.1.2
|
131
133
|
signing_key:
|
132
134
|
specification_version: 4
|
133
135
|
summary: Integrate modern JavaScript build system with Rails.
|
@@ -1,18 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"target": "es5",
|
4
|
-
"lib": ["es2019", "dom", "dom.iterable"],
|
5
|
-
"module": "es2015",
|
6
|
-
"moduleResolution": "node",
|
7
|
-
"esModuleInterop": true,
|
8
|
-
"downlevelIteration": true,
|
9
|
-
"sourceMap": true,
|
10
|
-
"removeComments": false,
|
11
|
-
"noImplicitAny": false,
|
12
|
-
"strictNullChecks": true,
|
13
|
-
"strictFunctionTypes": true,
|
14
|
-
"strictBindCallApply": true,
|
15
|
-
"strictPropertyInitialization": true,
|
16
|
-
"noImplicitThis": true
|
17
|
-
}
|
18
|
-
}
|