simpacker 0.3.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 444b754848602fa63f5531bc7beb0d50714a686ff63bd58192373bac6c66c40f
4
- data.tar.gz: 1fca8576ce3d3d982ab9b23ca043757e98d3bc5af35522cff0f4e2615323b4e6
3
+ metadata.gz: '093b3b132f0eb539351f2e441b6542063c34966c57be970863f131a18881da08'
4
+ data.tar.gz: dd4bcb552fb6679e622649ea990d07a56651d9b854e8c85f7257bdf58d919a7b
5
5
  SHA512:
6
- metadata.gz: 84a3dfc8d926d60e407e0b6c34527e4ba153165f6143f2a5d406cf02d276e69bb19c2b9112c01e89b5c200ce2676d2bc0f9349d203f805c8804cad6599fb35b2
7
- data.tar.gz: 6fa86aa1d886cdc732a94b9c90ca3961d427472ef98a30eb67931ef0fd78d5914dd591a3f0ac9fe0ba32a8049fd678b4d7e603e693860ba23870b5995acf9f75
6
+ metadata.gz: 05ce8120a614e150d79f849f993c407d68d167e3fd501a219298f2d3c53478a07504f9a6b9edc8f04c09b121482aba36ef7886c03b44e12b54fde41535b46d9b
7
+ data.tar.gz: 2fddc269856cc17c2fea0e4b3d95fed81d74e035feefb155682bd236d61866060763f9762c8f949695c4d1f030b0d8b7056bfd5638c1bb1f90ea93d4ea1a33f2
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /Gemfile.lock
10
+ /node_modules/
data/.prettierignore ADDED
@@ -0,0 +1 @@
1
+ **/public/packs/
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ cache: bundler
3
+
4
+ rvm:
5
+ - 2.5
6
+ - 2.6
7
+ - 2.7
8
+ - 3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ ## v1.2.0
2
+
3
+ - Add image_pack_url, favicon_pack_tag to helpers #67
4
+
5
+ ## v1.1.2
6
+
7
+ - Set output option to manifest.json in webpack.config.js
8
+
9
+ ## v1.1.1
10
+
11
+ - Fix deprecation warnings for Ruby 2.7 keyword arguments
12
+
13
+ ## v1.1.0
14
+
15
+ - Allow `Manifest#lookup` to access nested fields.
16
+ - Drop TypeScript from default installer.
17
+ - Improve error handling.
18
+
19
+ ## v1.0.0
20
+
21
+ - Initial release
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
- $ ./node_modules/.bin/wabpack --watch
36
+ $ ./node_modules/.bin/webpack --watch
35
37
  ```
36
38
 
37
- ## Integrations
38
-
39
- See [examples](https://github.com/hokaccha/simpacker/tree/master/example).
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
+ - [Split Chunks](https://github.com/hokaccha/simpacker/tree/master/example/split-chunks)
45
+ - Transpilers
46
+ - [TypeScript](https://github.com/hokaccha/simpacker/tree/master/example/typescript)
47
+ - [Babel](https://github.com/hokaccha/simpacker/tree/master/example/babel)
48
+ - Style Sheets
49
+ - [CSS](https://github.com/hokaccha/simpacker/tree/master/example/css)
50
+ - [Sass](https://github.com/hokaccha/simpacker/tree/master/example/sass)
51
+ - [PostCSS](https://github.com/hokaccha/simpacker/tree/master/example/postcss)
52
+ - Frameworks
53
+ - [React(TypeScript)](https://github.com/hokaccha/simpacker/tree/master/example/react-typescript)
54
+ - [React(Babel)](https://github.com/hokaccha/simpacker/tree/master/example/react-babel)
55
+ - [Vue.js](https://github.com/hokaccha/simpacker/tree/master/example/vue)
56
+ - [Angular](https://github.com/hokaccha/simpacker/tree/master/example/angular)
57
+ - Deployment
58
+ - [CDN](https://github.com/hokaccha/simpacker/tree/master/example/asset-host)
59
+ - [Heroku](https://github.com/hokaccha/simpacker/tree/master/example/heroku)
60
+ - [Docker](https://github.com/hokaccha/simpacker/tree/master/example/docker)
61
+ - Advanced settings
62
+ - [Rails Engines](https://github.com/hokaccha/simpacker/tree/master/example/engines)
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
 
@@ -47,6 +80,8 @@ $ npm install
47
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.
@@ -0,0 +1,3 @@
1
+ export function hello(name) {
2
+ return `Hello ${name}!`;
3
+ }
@@ -8,26 +8,20 @@ module.exports = {
8
8
  mode: isProd ? "production" : "development",
9
9
  devtool: "source-map",
10
10
  entry: {
11
- application: path.resolve(__dirname, "app/javascript/application.ts")
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"
16
+ filename: isProd ? "[name]-[hash].js" : "[name].js",
17
17
  },
18
18
  resolve: {
19
- extensions: [".js", ".ts"]
19
+ extensions: [".js"],
20
20
  },
21
- module: {
22
- rules: [
23
- {
24
- test: /\.tsx?$/,
25
- loader: "ts-loader",
26
- options: {
27
- transpileOnly: true
28
- }
29
- }
30
- ]
31
- },
32
- plugins: [new WebpackAssetsManifest({ publicPath: true })]
21
+ plugins: [
22
+ new WebpackAssetsManifest({
23
+ publicPath: true,
24
+ output: "manifest.json",
25
+ }),
26
+ ],
33
27
  };
@@ -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"
@@ -1,39 +1,14 @@
1
- require "yaml"
2
-
3
1
  module Simpacker
4
2
  class Configuration
5
- attr_accessor :root_path, :config_path, :env
6
-
7
- def initialize(root_path:)
8
- @root_path = root_path
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
- root_path.join(data.fetch("manifest_path"))
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
- data.fetch("cache_manifest")
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
@@ -1,10 +1,33 @@
1
+ require "yaml"
2
+
1
3
  module Simpacker
2
4
  class Context
5
+ class InvalidConfigurationError < StandardError; end
6
+
3
7
  attr_reader :config, :manifest
4
8
 
5
- def initialize(root_path: Rails.root)
6
- @config = Simpacker::Configuration.new(root_path: root_path)
7
- @manifest = Simpacker::Manifest.new(self)
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}"
8
31
  end
9
32
  end
10
33
  end
@@ -26,6 +26,14 @@ module Simpacker
26
26
  image_tag(asset_path(simpacker_context.manifest.lookup!(name)), **options)
27
27
  end
28
28
 
29
+ def image_pack_url(name, **options)
30
+ asset_url(simpacker_context.manifest.lookup!(name), **options)
31
+ end
32
+
33
+ def favicon_pack_tag(name, **options)
34
+ favicon_link_tag(asset_path(simpacker_context.manifest.lookup!(name)), **options)
35
+ end
36
+
29
37
  def simpacker_context
30
38
  Simpacker.default_context
31
39
  end
@@ -1,29 +1,30 @@
1
1
  module Simpacker
2
2
  class Manifest
3
3
  class MissingEntryError < StandardError; end
4
+ class MissingFileError < StandardError; end
4
5
 
5
- attr_reader :context
6
+ attr_reader :config
6
7
 
7
- def initialize(context)
8
- @context = context
8
+ def initialize(config)
9
+ @config = config
9
10
  end
10
11
 
11
- def lookup(name)
12
- data[name.to_s].presence
12
+ def lookup(*names)
13
+ data.dig(*names.map(&:to_s))
13
14
  end
14
15
 
15
- def lookup!(name)
16
- lookup(name) || handle_missing_entry(name)
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(name)
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
26
- if context.config.cache_manifest?
27
+ if config.cache_manifest?
27
28
  @data ||= load
28
29
  else
29
30
  load
@@ -31,10 +32,10 @@ module Simpacker
31
32
  end
32
33
 
33
34
  def load
34
- if context.config.manifest_path.exist?
35
- JSON.parse(context.config.manifest_path.read)
35
+ if config.manifest_path.exist? && config.manifest_path.file?
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
@@ -1,3 +1,3 @@
1
1
  module Simpacker
2
- VERSION = "0.3.0"
2
+ VERSION = "1.2.0"
3
3
  end
data/package.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "private": true,
3
+ "scripts": {
4
+ "format": "prettier --list-different --write '**/*.{js,ts,jsx,tsx}'"
5
+ },
6
+ "devDependencies": {
7
+ "prettier": "^2.2.1"
8
+ }
9
+ }
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", "~> 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"
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
data/yarn.lock ADDED
@@ -0,0 +1,8 @@
1
+ # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ # yarn lockfile v1
3
+
4
+
5
+ prettier@^2.2.1:
6
+ version "2.2.1"
7
+ resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.2.1.tgz#795a1a78dd52f073da0cd42b21f9c91381923ff5"
8
+ integrity sha512-PqyhM2yCjg/oKkFPtTGUojv7gnZAoG80ttl45O6x2Ug/rMJw4wcc9k6aaf2hibP7BGVCCM33gZoGjyvt9mm16Q==
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: 0.3.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuhito Hokamura
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-06-29 00:00:00.000000000 Z
11
+ date: 2021-02-17 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,16 +88,18 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - ".gitignore"
91
+ - ".prettierignore"
92
+ - ".travis.yml"
93
+ - CHANGELOG.md
91
94
  - Gemfile
92
95
  - README.md
93
96
  - Rakefile
94
97
  - bin/console
95
98
  - bin/setup
96
99
  - lib/install/config/simpacker.yml
97
- - lib/install/javascript/application.ts
98
- - lib/install/javascript/greeter.ts
100
+ - lib/install/javascript/application.js
101
+ - lib/install/javascript/greeter.js
99
102
  - lib/install/root/package.json
100
- - lib/install/root/tsconfig.json
101
103
  - lib/install/root/webpack.config.js
102
104
  - lib/install/template.rb
103
105
  - lib/simpacker.rb
@@ -108,12 +110,14 @@ files:
108
110
  - lib/simpacker/railtie.rb
109
111
  - lib/simpacker/version.rb
110
112
  - lib/tasks/simpacker.rake
113
+ - package.json
111
114
  - simpacker.gemspec
115
+ - yarn.lock
112
116
  homepage: https://github.com/hokaccha/simpacker
113
117
  licenses:
114
118
  - MIT
115
119
  metadata: {}
116
- post_install_message:
120
+ post_install_message:
117
121
  rdoc_options: []
118
122
  require_paths:
119
123
  - lib
@@ -128,8 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
132
  - !ruby/object:Gem::Version
129
133
  version: '0'
130
134
  requirements: []
131
- rubygems_version: 3.0.3
132
- signing_key:
135
+ rubygems_version: 3.2.3
136
+ signing_key:
133
137
  specification_version: 4
134
138
  summary: Integrate modern JavaScript build system with Rails.
135
139
  test_files: []
@@ -1,3 +0,0 @@
1
- export function hello(name: string): string {
2
- return `Hello ${name}!`;
3
- }
@@ -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
- }