simpacker 0.2.1 → 1.1.2

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: 19fc629b0f347b8160978738f12a04a454e058f94a4495a54746c29331f65858
4
- data.tar.gz: f9f27e87b24584439f8565b4ba960117c999ddfec9b3332bac4c1d85d6e16963
3
+ metadata.gz: c3cb3ad3505e3888c12a5684f094f2a5f051299ca3ebd3cda5440459a0183055
4
+ data.tar.gz: 7de94dbbc14ba099dca995ebe03186b1e3ce9c2cf05fa99059dbce9dd61e36e4
5
5
  SHA512:
6
- metadata.gz: b798ec5ac44e5d64f5daa0e5da10b78a97fa91149202b7ed9c9b92851dcb2e5f74ddbd4e498c924f6345cadf369bac13aba7560891fe6a0f784b62c607cce4a5
7
- data.tar.gz: 68f8e76ccf7d0ae88d5ecd862533f5e71af32850f11d5ba0a6c6cd58aa3a761959af677fe6a2e14d67e51fe4dbf6677d833292c81e56f6b42d264d4850596ef5
6
+ metadata.gz: f1c2090cc19f6c64457514550456b888c87ec49c89a053d5bff3c3d1c761e493e6c28e772f4be5c3b3686aaeccf4b3e9cc000d416fdaffe1ccc4377b74ac6729
7
+ data.tar.gz: e873dd15a63c99184ecf743de842325a6fadcfc21b0660172700d8c0565fa5550a852bd332eabc45cd9b1e2c84b1ba47d97c9e81953cea94ac3947046f04a51d
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /Gemfile.lock
10
+ /node_modules/
@@ -0,0 +1 @@
1
+ **/public/packs/
@@ -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
@@ -0,0 +1,17 @@
1
+ ## v1.1.2
2
+
3
+ - Set output option to manifest.json in webpack.config.js
4
+
5
+ ## v1.1.1
6
+
7
+ - Fix deprecation warnings for Ruby 2.7 keyword arguments
8
+
9
+ ## v1.1.0
10
+
11
+ - Allow `Manifest#lookup` to access nested fields.
12
+ - Drop TypeScript from default installer.
13
+ - Improve error handling.
14
+
15
+ ## v1.0.0
16
+
17
+ - 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
- $ npx 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
 
@@ -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 npx webpack
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,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.config
8
- @config ||= Simpacker::Configuration.new
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 :root_path, :config_path, :env
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
- 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
@@ -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
@@ -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
- Simpacker.manifest.lookup!("#{name}#{compute_asset_extname(name.to_s, type: :javascript)}")
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
- Simpacker.manifest.lookup!("#{name}#{compute_asset_extname(name.to_s, type: :stylesheet)}")
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(Simpacker.manifest.lookup!(name), **options)
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(Simpacker.manifest.lookup!(name), **options)
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(Simpacker.manifest.lookup!(name)), **options)
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
@@ -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(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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Simpacker
2
- VERSION = "0.2.1"
2
+ VERSION = "1.1.2"
3
3
  end
@@ -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
+ }
@@ -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
@@ -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.2.1
4
+ version: 1.1.2
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-24 00:00:00.000000000 Z
11
+ date: 2021-01-20 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,31 +88,36 @@ 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
104
106
  - lib/simpacker/configuration.rb
107
+ - lib/simpacker/context.rb
105
108
  - lib/simpacker/helper.rb
106
109
  - lib/simpacker/manifest.rb
107
110
  - lib/simpacker/railtie.rb
108
111
  - lib/simpacker/version.rb
109
112
  - lib/tasks/simpacker.rake
113
+ - package.json
110
114
  - simpacker.gemspec
115
+ - yarn.lock
111
116
  homepage: https://github.com/hokaccha/simpacker
112
117
  licenses:
113
118
  - MIT
114
119
  metadata: {}
115
- post_install_message:
120
+ post_install_message:
116
121
  rdoc_options: []
117
122
  require_paths:
118
123
  - lib
@@ -127,8 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
127
132
  - !ruby/object:Gem::Version
128
133
  version: '0'
129
134
  requirements: []
130
- rubygems_version: 3.0.3
131
- signing_key:
135
+ rubygems_version: 3.2.3
136
+ signing_key:
132
137
  specification_version: 4
133
138
  summary: Integrate modern JavaScript build system with Rails.
134
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
- }