nanoc-webpack.rb 0.5.6 → 0.7.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 +4 -4
- data/README.md +27 -56
- data/lib/nanoc/webpack/filter.rb +18 -10
- data/lib/nanoc/webpack/version.rb +1 -1
- data/nanoc-webpack.rb.gemspec +1 -1
- data/spec/filter_spec.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6089712cbc312cd503ad06f0a1d54e27351901f86b870460f1c6d3c205566d4c
|
4
|
+
data.tar.gz: 8c932b943c81803365dcd2e9a7c46b5cfec2790fb05964c73b60e557fcf1461a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b9f6f1cc40ada346daac98c1b401dc613c327e41c5bf48b1bf4c6ecad8b50c267b3a46164336e677dd8c28415f2c7262b28cab9ff4ea897c7f6a96491cc3c2a
|
7
|
+
data.tar.gz: 62595779fdff296640fa1ddd0030ab3d97e580378f0129c5a5d9260fe13b92e9a08a006316c8ad5de420133557d7f9542a776f7d2c909c2e37642d1c788a8996
|
data/README.md
CHANGED
@@ -2,50 +2,44 @@
|
|
2
2
|
|
3
3
|
nanoc-webpack.rb is a
|
4
4
|
[nanoc](https://nanoc.app)
|
5
|
-
filter
|
6
|
-
that integrates
|
5
|
+
filter that integrates
|
7
6
|
[webpack](https://webpack.js.org/)
|
8
|
-
into nanoc
|
9
|
-
|
7
|
+
into nanoc. <br>
|
8
|
+
The filter acts as a bridge that connects nanoc,
|
9
|
+
and the JavaScript, TypeScript, and nodejs ecosystems.
|
10
10
|
|
11
11
|
## Examples
|
12
12
|
|
13
|
-
|
13
|
+
**Defaults**
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
The following example forwards the entry point `/js/main/App.tsx` to webpack,
|
18
|
-
and then writes the result to `/js/app.js`. This example and all the other
|
19
|
-
examples assume that the files `webpack.config.js`, `tsconfig.json`, and
|
20
|
-
`package.json` already exist at the root of the project:
|
15
|
+
The following example forwards the entry point `/js/main/App.tsx`
|
16
|
+
to webpack. <br> The result is then written to `/js/main/app.js`:
|
21
17
|
|
22
18
|
``` ruby
|
23
19
|
# Rules
|
24
20
|
require "nanoc-webpack"
|
25
21
|
compile "/js/main/App.tsx" do
|
26
22
|
filter(:webpack)
|
27
|
-
write("/js/app.js")
|
23
|
+
write("/js/main/app.js")
|
28
24
|
end
|
29
25
|
```
|
30
26
|
|
31
|
-
|
32
|
-
|
33
|
-
#### Option: "depend_on"
|
27
|
+
**Option: depend_on**
|
34
28
|
|
35
|
-
|
36
|
-
|
37
|
-
|
29
|
+
When a file or directory tracked by the `depend_on` option
|
30
|
+
is observed to have changed, nanoc will initiate a recompilation
|
31
|
+
of the entry point:
|
38
32
|
|
39
33
|
```ruby
|
40
34
|
# Rules
|
41
35
|
require "nanoc-webpack"
|
42
36
|
compile "/js/main/App.tsx" do
|
43
37
|
filter(:webpack, depend_on: ["/js/lib", "/js/components", "/js/hooks"])
|
44
|
-
write("/js/app.js")
|
38
|
+
write("/js/main/app.js")
|
45
39
|
end
|
46
40
|
```
|
47
41
|
|
48
|
-
|
42
|
+
**Option: reject**
|
49
43
|
|
50
44
|
The `depend_on` option can be combined with the `reject` option to exclude
|
51
45
|
certain files or directories from being tracked. For example, maybe you want
|
@@ -58,63 +52,40 @@ compile "/js/main/App.tsx" do
|
|
58
52
|
filter :webpack,
|
59
53
|
depend_on: ["/js/lib", "/js/components", "/js/hooks"],
|
60
54
|
reject: proc { |path| path.start_with?("/js/lib/foo/") }
|
61
|
-
write("/js/app.js")
|
55
|
+
write("/js/main/app.js")
|
62
56
|
end
|
63
57
|
```
|
64
58
|
|
65
|
-
|
59
|
+
**Option: cli**
|
66
60
|
|
67
|
-
The `
|
68
|
-
to the webpack executable.
|
69
|
-
<br>
|
70
|
-
`$ webpack build --help verbose` provides a list of all available options,
|
71
|
-
and
|
61
|
+
The `cli` option forwards command-line options directly
|
62
|
+
to the webpack executable. <br>
|
72
63
|
[Nanoc::Webpack.default_options](https://0x1eef.github.io/x/nanoc-webpack.rb/Nanoc/Webpack.html#default_options-class_method)
|
73
|
-
returns the default options nanoc-webpack.rb will
|
64
|
+
returns the default options nanoc-webpack.rb will
|
65
|
+
forward to webpack:
|
74
66
|
|
75
67
|
```ruby
|
76
68
|
# Rules
|
77
69
|
require "nanoc-webpack"
|
78
70
|
compile "/js/main/App.tsx" do
|
79
|
-
filter
|
80
|
-
write("/js/app.js")
|
71
|
+
filter(:webpack, cli: {"--no-stats" => true})
|
72
|
+
write("/js/main/app.js")
|
81
73
|
end
|
82
74
|
```
|
83
75
|
|
84
|
-
|
85
|
-
## Requirements
|
86
|
-
|
87
|
-
nanoc-webpack.rb assumes that:
|
88
|
-
|
89
|
-
* A "node" executable is available in $PATH.
|
90
|
-
* "webpack" / "webpack-cli" exist as dependencies in package.json.
|
91
|
-
|
92
|
-
## Sources
|
93
|
-
|
94
|
-
* [Source code (GitHub)](https://github.com/0x1eef/nanoc-webpack.rb)
|
95
|
-
* [Source code (GitLab)](https://gitlab.com/0x1eef/nanoc-webpack.rb)
|
96
|
-
|
97
76
|
## <a id='install'>Install</a>
|
98
77
|
|
99
|
-
**Git**
|
100
|
-
|
101
|
-
nanoc-webpack.rb is distributed as a RubyGem through its git repositories. <br>
|
102
|
-
[GitHub](https://github.com/0x1eef/nanoc-webpack.rb),
|
103
|
-
and
|
104
|
-
[GitLab](https://gitlab.com/0x1eef/nanoc-webpack.rb)
|
105
|
-
are available as sources.
|
106
|
-
|
107
|
-
```ruby
|
108
|
-
# Gemfile
|
109
|
-
gem "nanoc-webpack.rb", github: "0x1eef/nanoc-webpack.rb", tag: "v0.5.6"
|
110
|
-
```
|
111
|
-
|
112
78
|
**Rubygems.org**
|
113
79
|
|
114
80
|
nanoc-webpack.rb can also be installed via rubygems.org.
|
115
81
|
|
116
82
|
gem install nanoc-webpack.rb
|
117
83
|
|
84
|
+
## Sources
|
85
|
+
|
86
|
+
* [GitHub](https://github.com/0x1eef/nanoc-webpack.rb#readme)
|
87
|
+
* [GitLab](https://gitlab.com/0x1eef/nanoc-webpack.rb#about)
|
88
|
+
|
118
89
|
## License
|
119
90
|
|
120
91
|
[BSD Zero Clause](https://choosealicense.com/licenses/0bsd/).
|
data/lib/nanoc/webpack/filter.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
##
|
4
|
-
# Compiles a
|
4
|
+
# Compiles a nanoc item with webpack.
|
5
5
|
class Nanoc::Webpack::Filter < Nanoc::Filter
|
6
6
|
require_relative "filter/dependable"
|
7
|
-
Error = Class.new(RuntimeError)
|
8
7
|
include FileUtils
|
9
8
|
include Dependable
|
9
|
+
Error = Class.new(RuntimeError)
|
10
10
|
|
11
11
|
identifier :webpack
|
12
12
|
type :text
|
@@ -18,28 +18,36 @@ class Nanoc::Webpack::Filter < Nanoc::Filter
|
|
18
18
|
# )
|
19
19
|
#
|
20
20
|
# @return [Hash]
|
21
|
-
# Returns the default command-line options
|
21
|
+
# Returns the default command-line options forwarded to webpack.
|
22
22
|
def self.default_options
|
23
23
|
@default_options ||= {"--cache-type" => "filesystem"}
|
24
24
|
end
|
25
25
|
|
26
|
+
##
|
27
|
+
# @param [String] content
|
28
|
+
# The contents of a file.
|
29
|
+
#
|
30
|
+
# @param [Hash] options
|
31
|
+
# A hash of options.
|
32
|
+
#
|
33
|
+
# @return [void]
|
26
34
|
def run(content, options = {})
|
27
|
-
|
28
|
-
depend_on dependable(paths: options
|
35
|
+
options = Ryo.from(options)
|
36
|
+
depend_on dependable(paths: options.depend_on, reject: options.reject)
|
29
37
|
.map { items[_1] }
|
30
|
-
webpack
|
31
|
-
|
38
|
+
webpack temporary_file(content),
|
39
|
+
cli: self.class.default_options.merge(options.cli || {})
|
32
40
|
end
|
33
41
|
|
34
42
|
private
|
35
43
|
|
36
|
-
def webpack(file,
|
44
|
+
def webpack(file, cli:)
|
37
45
|
sh "node",
|
38
46
|
"./node_modules/webpack/bin/webpack.js",
|
39
47
|
"--entry", File.join(Dir.getwd, item.attributes[:content_filename]),
|
40
48
|
"--output-path", File.dirname(file.path),
|
41
49
|
"--output-filename", File.basename(file.path),
|
42
|
-
*webpack_args(
|
50
|
+
*webpack_args(cli)
|
43
51
|
if $?.success?
|
44
52
|
File.read(file.path).tap { file.tap(&:unlink).close }
|
45
53
|
else
|
@@ -59,7 +67,7 @@ class Nanoc::Webpack::Filter < Nanoc::Filter
|
|
59
67
|
end
|
60
68
|
end
|
61
69
|
|
62
|
-
def
|
70
|
+
def temporary_file(content)
|
63
71
|
dir = File.join(Dir.getwd, "tmp", "nanoc-webpack.rb")
|
64
72
|
mkdir_p(dir) unless Dir.exist?(dir)
|
65
73
|
file = Tempfile.new(File.basename(@item.identifier.to_s), dir)
|
data/nanoc-webpack.rb.gemspec
CHANGED
@@ -12,7 +12,7 @@ Gem::Specification.new do |gem|
|
|
12
12
|
gem.require_paths = ["lib"]
|
13
13
|
gem.summary = "nanoc-webpack.rb integrates webpack into nanoc."
|
14
14
|
gem.description = gem.summary
|
15
|
-
gem.add_runtime_dependency "ryo.rb", "~> 0.
|
15
|
+
gem.add_runtime_dependency "ryo.rb", "~> 0.5"
|
16
16
|
gem.add_development_dependency "yard", "~> 0.9"
|
17
17
|
gem.add_development_dependency "redcarpet", "~> 3.5"
|
18
18
|
gem.add_development_dependency "rspec", "~> 3.10"
|
data/spec/filter_spec.rb
CHANGED
@@ -146,7 +146,7 @@ RSpec.describe Nanoc::Webpack::Filter do
|
|
146
146
|
|
147
147
|
it "executes nodejs with an argument" do
|
148
148
|
expect(filter).to receive(:system).with(*cmdline)
|
149
|
-
filter.run(item,
|
149
|
+
filter.run(item, cli: {"--no-cache" => true})
|
150
150
|
end
|
151
151
|
end
|
152
152
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nanoc-webpack.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- '0x1eef'
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ryo.rb
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.5'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
26
|
+
version: '0.5'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: yard
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|