opal-webpack-loader 0.9.8 → 0.10.1
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 +215 -0
- data/bin/opal-webpack-compile-server +13 -10
- data/bin/owl-compiler +100 -0
- data/bin/owl-gen-loadpath-cache +0 -0
- data/bin/owl-install +0 -0
- data/lib/opal-webpack-loader.rb +7 -4
- data/lib/opal-webpack-loader/compile_server.rb +9 -5
- data/lib/opal-webpack-loader/compile_worker.rb +23 -7
- data/lib/opal-webpack-loader/templates/debug.js.erb +3 -3
- data/lib/opal-webpack-loader/templates/development.js.erb +3 -3
- data/lib/opal-webpack-loader/templates/initializer.rb.erb +3 -1
- data/lib/opal-webpack-loader/templates/package.json.erb +12 -12
- data/lib/opal-webpack-loader/templates/production.js.erb +6 -6
- data/lib/opal-webpack-loader/version.rb +3 -3
- metadata +47 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24026e9101614dd34aac0e20644a4a43797e4fc86e074f65a696f1de40b0a635
|
4
|
+
data.tar.gz: d73ecb64726d60ad88d6457f78e35174f4e03544817dba9532f707210ddd5eda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c0fabada2a69f8992d81d5f57416d83700dd5d4f32d042b156bd9b98ea808b29cd1c2c9c3f67b705e92b04d474d02757fccf55fb6ce6b828392efd65ccd2963a
|
7
|
+
data.tar.gz: b138f2e7c161c5ab0fee69949e6262c71f78fe0b8bebc1bf90113e2d14a1ca6780cdc91b7abb9f42fc8126daf345c83d2320388f7d2dcb95cad160900e76cac4
|
data/README.md
ADDED
@@ -0,0 +1,215 @@
|
|
1
|
+
<h1 align="center">
|
2
|
+
<img src="https://raw.githubusercontent.com/isomorfeus/opal-webpack-loader/master/docs/owl.png"
|
3
|
+
align="center" title="Opal logo by Elia Schito combined with Webpack Logo" width="111" height="125" />
|
4
|
+
<br/>
|
5
|
+
opal-webpack-loader<br/>
|
6
|
+
<img src="https://img.shields.io/badge/Opal-Ruby%20💛%20JavaScript%20💛%20Webpack-yellow.svg?logo=ruby&style=social&logoColor=777"/>
|
7
|
+
</h1>
|
8
|
+
|
9
|
+
Bundle assets with webpack, resolve and compile opal ruby files and import them in the bundle, without sprockets or the webpacker gem
|
10
|
+
(but can be used with both of them too).
|
11
|
+
Includes a loader and resolver plugin for webpack.
|
12
|
+
|
13
|
+
### Community and Support
|
14
|
+
At the [Isomorfeus Framework Project](http://isomorfeus.com)
|
15
|
+
|
16
|
+
### Tested
|
17
|
+
[TravisCI](https://travis-ci.org): [](https://travis-ci.org/isomorfeus/opal-webpack-loader)
|
18
|
+
|
19
|
+
### Features
|
20
|
+
- comes with a installer for rails and other frameworks
|
21
|
+
- webpack based build process
|
22
|
+
- very fast, asynchronous and parallel builds of opal code:
|
23
|
+
opal-webpack-loader-0.7.1 compiles all of opal, a bunch of gems and over 19000SLC on a
|
24
|
+
Intel® Core™ i7-7700HQ CPU @ 2.80GHz × 8, with 8 workers in around 1850ms
|
25
|
+
- support for memcached or redis as compiler cache
|
26
|
+
- parallel builds working on Windows too, but not as fast as on Linux
|
27
|
+
- opal modules are packaged as es6 modules
|
28
|
+
- support for rails with webpacker
|
29
|
+
- other webpack features become available, like:
|
30
|
+
- source maps
|
31
|
+
- multiple targets: web (for browsers), node (for server side rendering) and webworker (for Web Workers)
|
32
|
+
- hot module reloading for opal ruby code and stylesheets and html views
|
33
|
+
- tree shaking
|
34
|
+
- code splitting
|
35
|
+
- lazy loading
|
36
|
+
- everything else webpack can do, like loading stylesheets, etc.
|
37
|
+
|
38
|
+
### Requirements
|
39
|
+
- opal-webpack-loader consists of 2 parts, the npm package and the gem, both are required and must be the same version.
|
40
|
+
- webpack ^4.46
|
41
|
+
- webpack-dev-server ^3.11.0
|
42
|
+
- one of the ES6 modules branches of opal
|
43
|
+
- [PR#1973](https://github.com/opal/opal/pull/1973), (experimental) implementing ES6 modules and changes for 'strict' mode,
|
44
|
+
based on Opal master 1.0.0 using javascript string objects "mutable strings" by default for all strings
|
45
|
+
|
46
|
+
`gem 'opal', github: 'janbiedermann/opal', branch: 'es6_modules_string'`
|
47
|
+
|
48
|
+
- [PR#1976](https://github.com/opal/opal/pull/1976), (recommended) implementing ES6 modules and changes for 'strict' mode,
|
49
|
+
based on Opal master 1.1.0 using javascript string primitives and providing nice features like `require_lazy 'my_module'`
|
50
|
+
|
51
|
+
`gem 'opal', github: 'janbiedermann/opal', branch: 'es6_modules_1_1'`
|
52
|
+
|
53
|
+
- if you have the webpacker gem installed somewhere, it should be a version supporting webpack 4
|
54
|
+
- ruby, version 2.5 or higher recommended
|
55
|
+
- bundler, latest version recommended
|
56
|
+
|
57
|
+
### Installation
|
58
|
+
|
59
|
+
#### Using the installer
|
60
|
+
First install the gem:
|
61
|
+
```
|
62
|
+
gem install 'opal-webpack-loader'
|
63
|
+
```
|
64
|
+
|
65
|
+
Continue here:
|
66
|
+
- [Install for Rails like projects](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/installation_rails.md)
|
67
|
+
- [Install for Cuba, Roda, Sinatra and other projects with a flat structure](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/installation_flat.md)
|
68
|
+
- [Manual Installation](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/installation_manual.md)
|
69
|
+
|
70
|
+
### Example applications
|
71
|
+
- [Are here](https://github.com/isomorfeus/opal-webpack-loader/tree/master/example_apps/)
|
72
|
+
- A minimal webpack only example from @sunrick is [here](https://github.com/sunrick/opal-hello-world-webpack).
|
73
|
+
|
74
|
+
### General Usage without Webpacker
|
75
|
+
|
76
|
+
After installing owl with the installer, three scripts are provided in package.json:
|
77
|
+
- `development` - runs the webpack-dev-server, use for general development, provides fast reloads, entry is application.js
|
78
|
+
- `debug` - runs the webpack-dev-server, use for debugging, provides source maps, entry is application_debug.js. Additional debugging tools may be added there.
|
79
|
+
- `production_build` - runs webpack to build assets for production, entry is application.js
|
80
|
+
|
81
|
+
These scripts can for example be run with:
|
82
|
+
`yarn run debug` or `npm run debug`
|
83
|
+
|
84
|
+
The default config provides several targets and entries:
|
85
|
+
|
86
|
+
- **Browser**: the webpack target is 'web' and the javascript entry file for imports is `application.js` - general use for the application with all
|
87
|
+
browser features, the opal ruby entry file is `opal_loader.rb` in the opal or app/opal directory of the app.
|
88
|
+
- **Server Side Rendering**: the webpack target is `node` and the javascript entry file for imports is `application_ssr.js` - general use for the
|
89
|
+
application server side rendering, several Browser features are unavailable, no `window`, no `document`, some node features are available,
|
90
|
+
like `Buffer`, the opal ruby entry file is `opal_loader.rb` in the opal or app/opal directory of the app.
|
91
|
+
(meant to be used with isomorfeus-speednode, standard ExecJS limitations prevent certain webpack features)
|
92
|
+
- **Web Worker**: the webpack target is 'webworker' and the javascript entry file for imports is `application_webworker.js` - used to initialize Web
|
93
|
+
Workers in the browser, the opal ruby entry file is `opal_webworker_loader.rb` in the opal or app/opal directory of the app.
|
94
|
+
|
95
|
+
Only the browser target is build by default. To builds the other target, just add the needed targets to the last line of the webpack config,
|
96
|
+
for example to `development.js`:
|
97
|
+
default config:
|
98
|
+
```javascript
|
99
|
+
module.exports = [ browser ];
|
100
|
+
```
|
101
|
+
modified config with ssr and web_worker targets enabled:
|
102
|
+
```javascript
|
103
|
+
module.exports = [ browser, ssr, web_worker ];
|
104
|
+
```
|
105
|
+
Same works for the `debug.js` and `production.js` webpack config files.
|
106
|
+
|
107
|
+
Also a Procfile has been installed, for rails its easy to startup rails and webpack with foreman:
|
108
|
+
`foreman start` (`gem install foreman` if you dont have it already). It will start rails and webpack-dev-server with the development script.
|
109
|
+
|
110
|
+
For non rails installation check the Procfile and add a starter for your app.
|
111
|
+
|
112
|
+
#### Opal Ruby Application Files
|
113
|
+
For rails installations with the installer they all go into: `app/opal`, for flat installations in the `opal` directory.
|
114
|
+
In this directory there already is a `opal_loader.rb` which is the entry point for your app.
|
115
|
+
|
116
|
+
#### Stylesheets
|
117
|
+
Stylesheets are hot reloaded too with the default config installed by the installer. Also they are imported into application.js by default.
|
118
|
+
For rails like applications stylesheets are in `app/assets/stylesheets/application.css`, for flat applications they are in `styles/application.css`.
|
119
|
+
SCSS is supported too by the default config.
|
120
|
+
|
121
|
+
#### Views
|
122
|
+
For rails like applications a watcher for `app/views` is installed by default. The watcher will trigger a page reload when views are changed.
|
123
|
+
For flat applications nothing is configured by default, as there are to many ways to generate views, they are not even needed with
|
124
|
+
frameworks like isomorfeus. Instead the section for configuring a view watcher is included in the development.js and debug.js webpack
|
125
|
+
config, but it is commented out. Please see those files and adjust to your liking.
|
126
|
+
|
127
|
+
#### Parallel compilation for speed
|
128
|
+
|
129
|
+
Since version 0.8.0 the number of CPUs is automatically determined and a appropriate number of of compile server workers is started automatically.
|
130
|
+
|
131
|
+
### Source Maps
|
132
|
+
|
133
|
+
[Source Maps](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/source_maps.md)
|
134
|
+
|
135
|
+
### Hot Module Reloading
|
136
|
+
[Hot Module Reloading](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/hot_module_reloading.md)
|
137
|
+
|
138
|
+
### Opal Load Path
|
139
|
+
The projects directory for opal ruby files must be in the opal load path. This is done in the initializer for rails apps in
|
140
|
+
config/initializers/opal_webpack_loader.rb or in 'owl_init.rb' for non rails apps, for example:
|
141
|
+
```ruby
|
142
|
+
Opal.append_path(File.realdirpath('app/opal'))
|
143
|
+
```
|
144
|
+
|
145
|
+
### View Helper
|
146
|
+
In Rails or frameworks that support `javscript_include_tag`, add to the app/helpers/application_helper.rb
|
147
|
+
```ruby
|
148
|
+
module ApplicationHelper
|
149
|
+
include OpalWebpackLoader::RailsViewHelper
|
150
|
+
```
|
151
|
+
in other frameworks that dont have a `javascript_include_tag`:
|
152
|
+
```ruby
|
153
|
+
module MyProjectsViewThings
|
154
|
+
include OpalWebpackLoader::ViewHelper
|
155
|
+
```
|
156
|
+
|
157
|
+
Then you can use in your views:
|
158
|
+
```ruby
|
159
|
+
owl_script_tag('application.js')
|
160
|
+
```
|
161
|
+
#### Compile Server and app_loader.rb
|
162
|
+
For non rails projects, determining Opal load paths, for the resolver and compile server to work properly, may not be obvious. For these cases
|
163
|
+
a file `app_loader.rb` in the projects root can be created which just loads all requirements without starting anything.
|
164
|
+
Usually it would just setup bundler with the appropriate options, for example:
|
165
|
+
```ruby
|
166
|
+
require 'bundler/setup'
|
167
|
+
if ENV['RACK_ENV'] && ENV['RACK_ENV'] == 'test'
|
168
|
+
Bundler.require(:default, :test)
|
169
|
+
elsif ENV['RACK_ENV'] && ENV['RACK_ENV'] == 'production'
|
170
|
+
Bundler.require(:default, :production)
|
171
|
+
else
|
172
|
+
Bundler.require(:default, :development)
|
173
|
+
end
|
174
|
+
Opal.append_path(File.realdirpath('opal')) # this is a good place to add the directory with opal files to the opal load path
|
175
|
+
```
|
176
|
+
When this file exists, the compile server will load it and generate Opal load paths accordingly for the resolver.
|
177
|
+
|
178
|
+
#### Project configuration options for the view helper
|
179
|
+
These setting are in the initializer in config/initializers/opal_webpack_loader.rb for rails like apps, or owl_init.rb for others.
|
180
|
+
```ruby
|
181
|
+
OpalWebpackLoader.use_manifest = false
|
182
|
+
```
|
183
|
+
If the manifest file should be used, use_manifest should be true.
|
184
|
+
```ruby
|
185
|
+
OpalWebpackLoader.manifest_path = File.join(Dir.getwd, 'public', 'assets', 'manifest.json')
|
186
|
+
```
|
187
|
+
Sets the path to the webpack (with the [webpack-manifest-plugin](https://www.npmjs.com/package/webpack-manifest-plugin)) generated manifest.json to look up assets.
|
188
|
+
```ruby
|
189
|
+
OpalWebpackLoader.client_asset_path = 'http://localhost:3035/assets/'
|
190
|
+
```
|
191
|
+
The path to prepend to the assets as configured in the webpack config 'publicPath'.
|
192
|
+
In the config example below its `publicPath: 'http://localhost:3025/assets'` so
|
193
|
+
client_asset_path should be set to the same.
|
194
|
+
|
195
|
+
For **production** use with readily precompiled and compressed assets which contain a fingerprint in the name (webpacks [chunkhash]),
|
196
|
+
and if the path in the manifest is the full path to the asset as configured in webpack,
|
197
|
+
these settings would work:
|
198
|
+
```ruby
|
199
|
+
OpalWebpackLoader.use_manifest = true
|
200
|
+
OpalWebpackLoader.manifest_path = File.join(Dir.getwd, 'public', 'assets', 'manifest.json')
|
201
|
+
OpalWebpackLoader.client_asset_path = ''
|
202
|
+
```
|
203
|
+
|
204
|
+
For **development** use with webpack-dev-server, with no manifest, these settings would work:
|
205
|
+
```ruby
|
206
|
+
OpalWebpackLoader.use_manifest = false
|
207
|
+
OpalWebpackLoader.manifest_path = File.join(Dir.getwd, 'public', 'assets', 'manifest.json') # doesn't matter, not used
|
208
|
+
OpalWebpackLoader.client_asset_path = 'http://localhost:3035/assets/'
|
209
|
+
```
|
210
|
+
### Advanced Options
|
211
|
+
[Advanced Options](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/advanced_options.md)
|
212
|
+
### Tests
|
213
|
+
- clone the repo
|
214
|
+
- `bundle install`
|
215
|
+
- `bundle exec rspec`
|
@@ -1,5 +1,5 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
require '
|
2
|
+
require 'digest'
|
3
3
|
require 'oj'
|
4
4
|
require 'c_lexer'
|
5
5
|
require 'optparse'
|
@@ -44,6 +44,16 @@ OptionParser.new do |opts|
|
|
44
44
|
opts.on('-s', '--socket-path PATH', 'Path of the socket the compile server should create.') do |s|
|
45
45
|
compile_server_options[:socket_path] = s
|
46
46
|
end
|
47
|
+
|
48
|
+
opts.on('-m', '--memcached URL', 'URL of memcached server. Will enable use of memcached for caching compiler results.') do |m|
|
49
|
+
compile_server_options[:memcached] = m
|
50
|
+
require 'dalli'
|
51
|
+
end
|
52
|
+
|
53
|
+
opts.on('-e', '--redis URL', 'URL of redis server. Will enable use of redis for caching compiler results.') do |e|
|
54
|
+
compile_server_options[:redis] = e
|
55
|
+
require 'redis'
|
56
|
+
end
|
47
57
|
end.parse!
|
48
58
|
|
49
59
|
modules_to_require.each do |mod|
|
@@ -66,13 +76,6 @@ else
|
|
66
76
|
number_of_workers = ARGV[1].to_i
|
67
77
|
number_of_workers == 4 if number_of_workers == 0
|
68
78
|
number_of_workers == 16 if number_of_workers > 16
|
69
|
-
if ARGV[2] && ARGV[2].start_with?('webpack')
|
70
|
-
raise <<~MSG
|
71
|
-
Please change the scripts in package.json to only start webpack:\n
|
72
|
-
eg. from: "debug": "bundle exec opal-webpack-compile-server start 8 webpack --config=config/webpack/test.js"
|
73
|
-
to just: "debug": "webpack --config=config/webpack/test.js"
|
74
|
-
MSG
|
75
|
-
end
|
76
79
|
else
|
77
80
|
raise 'arguments must be either "stop" or "start number_of_workers"'
|
78
81
|
exit(1)
|
@@ -83,7 +86,7 @@ else
|
|
83
86
|
Opal.append_paths(*load_paths)
|
84
87
|
end
|
85
88
|
|
86
|
-
pid = fork { OpalWebpackLoader::CompileServer.new.start(number_of_workers, compiler_options
|
89
|
+
pid = fork { OpalWebpackLoader::CompileServer.new(compile_server_options).start(number_of_workers, compiler_options) }
|
87
90
|
|
88
91
|
have_socket = false
|
89
92
|
start_time = Time.now
|
@@ -117,4 +120,4 @@ else
|
|
117
120
|
exit 0
|
118
121
|
end
|
119
122
|
Process.kill("TERM", pid)
|
120
|
-
end
|
123
|
+
end
|
data/bin/owl-compiler
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'digest'
|
3
|
+
require 'oj'
|
4
|
+
require 'c_lexer'
|
5
|
+
require 'optparse'
|
6
|
+
require 'opal/paths'
|
7
|
+
require 'opal/source_map'
|
8
|
+
require 'opal/compiler'
|
9
|
+
require 'opal-webpack-loader/load_path_manager'
|
10
|
+
|
11
|
+
modules_to_require = []
|
12
|
+
compiler_options = {}
|
13
|
+
compile_server_options = {}
|
14
|
+
|
15
|
+
OptionParser.new do |opts|
|
16
|
+
opts.on('-r', '--require MODULE', 'Require the module before starting the compile server.') do |m|
|
17
|
+
modules_to_require << m
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on('-I', '--include DIR', 'Append a load path (may be used more than once)') do |i|
|
21
|
+
$:.unshift(File.expand_path(i))
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on('-d', '--dynamic-require-severity SEVERITY', 'Compiler option, one of: error, warning, ignore.') do |s|
|
25
|
+
if %w[error warning ignore].include?(s)
|
26
|
+
compiler_options[:dynamic_require_severity] = s.to_sym
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
opts.on('-t', '--true FLAG', 'Set compiler flag to true.' ) do |f|
|
31
|
+
compiler_options[f.to_sym] = true
|
32
|
+
end
|
33
|
+
|
34
|
+
opts.on('-f', '--false FLAG', 'Set compiler flag to false.' ) do |f|
|
35
|
+
compiler_options[f.to_sym] = false
|
36
|
+
end
|
37
|
+
|
38
|
+
opts.on('-l', '--load-paths-cache PATH', 'Path to load path cache json') do |l|
|
39
|
+
compile_server_options[:load_paths_cache] = l
|
40
|
+
end
|
41
|
+
|
42
|
+
opts.on('-s', '--source-file PATH', 'Path of the file to compile.') do |s|
|
43
|
+
compile_server_options[:source_file] = s
|
44
|
+
end
|
45
|
+
|
46
|
+
opts.on('-c', '--create-map', 'Create source map.') do
|
47
|
+
compiler_server_options[:source_map] = true
|
48
|
+
end
|
49
|
+
|
50
|
+
opts.on('-m', '--memcached URL', 'URL of memcached server. Will enable use of memcached for caching compiler results.') do |m|
|
51
|
+
require 'dalli'
|
52
|
+
compile_server_options[:memcached] = m
|
53
|
+
compile_server_options[:cache] = Dalli::Client.new(compile_server_options[:memchached])
|
54
|
+
end
|
55
|
+
|
56
|
+
opts.on('-e', '--redis URL', 'URL of redis server. Will enable use of redis for caching compiler results.') do |e|
|
57
|
+
require 'redis'
|
58
|
+
compile_server_options[:redis] = e
|
59
|
+
compile_server_options[:cache] = Redis.new(url: other_options[:redis])
|
60
|
+
end
|
61
|
+
end.parse!
|
62
|
+
|
63
|
+
modules_to_require.each do |mod|
|
64
|
+
require mod
|
65
|
+
end
|
66
|
+
|
67
|
+
load_paths = OpalWebpackLoader::LoadPathManager.read_load_paths_cache(compile_server_options[:load_paths_cache])
|
68
|
+
if load_paths
|
69
|
+
Opal.append_paths(*load_paths)
|
70
|
+
end
|
71
|
+
|
72
|
+
compile_source_map = compile_server_options[:source_map]
|
73
|
+
filename = compile_server_options[:source_file]
|
74
|
+
source = File.read(filename)
|
75
|
+
compiler_options.merge!(es6_modules: true)
|
76
|
+
compiler_options.merge!(file: filename)
|
77
|
+
|
78
|
+
begin
|
79
|
+
if compile_server_options[:cache]
|
80
|
+
source_digest = Digest::SHA1.hexdigest(source)
|
81
|
+
key = "owl_#{compiler_options_digest}_#{source_digest}_#{compile_source_map}"
|
82
|
+
result_json = compile_server_options[:cache].get(key)
|
83
|
+
STDOUT.puts result_json if result_json
|
84
|
+
end
|
85
|
+
c = Opal::Compiler.new(source, compiler_options)
|
86
|
+
result = { 'javascript' => c.compile }
|
87
|
+
if compile_source_map
|
88
|
+
result['source_map'] = c.source_map.as_json
|
89
|
+
result['source_map']['file'] = filename
|
90
|
+
end
|
91
|
+
result['required_trees'] = c.required_trees
|
92
|
+
result_json = Oj.dump(result, mode: :strict)
|
93
|
+
compile_server_options[:cache].set(key, result_json) if compile_server_options[:cache]
|
94
|
+
STDOUT.puts result_json
|
95
|
+
rescue Exception => e
|
96
|
+
STDOUT.puts Oj.dump({ 'error' => { 'name' => e.class.to_s, 'message' => e.message, 'backtrace' => e.backtrace.join("\n") } }, mode: :strict)
|
97
|
+
end
|
98
|
+
|
99
|
+
|
100
|
+
|
data/bin/owl-gen-loadpath-cache
CHANGED
File without changes
|
data/bin/owl-install
CHANGED
File without changes
|
data/lib/opal-webpack-loader.rb
CHANGED
@@ -39,10 +39,13 @@ OpalWebpackLoader.client_asset_path = 'http://localhost:3035/assets/'
|
|
39
39
|
OpalWebpackLoader.use_manifest = false
|
40
40
|
|
41
41
|
# TODO require yarn instead of npm
|
42
|
-
|
43
|
-
|
42
|
+
npm = if Gem.win_platform?
|
43
|
+
`where npm`.chop.lines.last
|
44
|
+
else
|
45
|
+
`which npm`.chop
|
46
|
+
end
|
44
47
|
|
45
|
-
if npm
|
48
|
+
if !npm.nil? && !npm.empty?
|
46
49
|
bin_dir = `npm bin`.chop
|
47
50
|
begin
|
48
51
|
owl_npm_version = `#{File.join(bin_dir, 'opal-webpack-loader-npm-version')}`.chop
|
@@ -58,4 +61,4 @@ if npm != ''
|
|
58
61
|
end
|
59
62
|
else
|
60
63
|
STDERR.puts "opal-webpack-loader: Unable to check npm package version. Please check your npm installation."
|
61
|
-
end
|
64
|
+
end
|
@@ -33,18 +33,22 @@ module OpalWebpackLoader
|
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
-
|
36
|
+
attr_reader :cache
|
37
|
+
|
38
|
+
def initialize(options)
|
37
39
|
@read_pipe, @write_pipe = IO.pipe
|
38
40
|
@workers = {}
|
39
41
|
@signal_queue = []
|
42
|
+
@socket_path = options[:socket_path]
|
43
|
+
@options = options
|
40
44
|
end
|
41
45
|
|
42
|
-
def start(number_of_workers = 4, compiler_options
|
46
|
+
def start(number_of_workers = 4, compiler_options)
|
43
47
|
$PROGRAM_NAME = 'owl compile server'
|
44
48
|
@number_of_workers = number_of_workers
|
45
49
|
@server_pid = Process.pid
|
46
50
|
$stderr.sync = $stdout.sync = true
|
47
|
-
@socket = UNIXServer.new(socket_path)
|
51
|
+
@socket = UNIXServer.new(@socket_path)
|
48
52
|
spawn_workers(compiler_options)
|
49
53
|
SIGNALS.each { |sig| trap_deferred(sig) }
|
50
54
|
trap('CHLD') { @write_pipe.write_nonblock('.') }
|
@@ -118,7 +122,7 @@ module OpalWebpackLoader
|
|
118
122
|
tempfile = Tempfile.new('')
|
119
123
|
tempfile.unlink
|
120
124
|
tempfile.sync = true
|
121
|
-
worker = OpalWebpackLoader::CompileWorker.new(@server_pid, @socket, tempfile, worker_number, compiler_options)
|
125
|
+
worker = OpalWebpackLoader::CompileWorker.new(@server_pid, @socket, tempfile, worker_number, compiler_options, @options)
|
122
126
|
pid = fork { init_worker(worker) }
|
123
127
|
@workers[pid] = worker
|
124
128
|
end
|
@@ -131,4 +135,4 @@ module OpalWebpackLoader
|
|
131
135
|
end
|
132
136
|
end
|
133
137
|
end
|
134
|
-
end
|
138
|
+
end
|
@@ -4,14 +4,22 @@ module OpalWebpackLoader
|
|
4
4
|
class CompileWorker
|
5
5
|
SIGNALS = %w[QUIT]
|
6
6
|
|
7
|
-
attr_reader :number, :tempfile
|
7
|
+
attr_reader :cache, :number, :compiler_options_digest, :tempfile
|
8
8
|
|
9
|
-
def initialize(master_pid, socket, tempfile, number, compiler_options)
|
9
|
+
def initialize(master_pid, socket, tempfile, number, compiler_options, other_options)
|
10
10
|
@master_pid = master_pid
|
11
11
|
@socket = socket
|
12
12
|
@tempfile = tempfile
|
13
13
|
@number = number
|
14
14
|
@compiler_options = compiler_options.merge(es6_modules: true)
|
15
|
+
if other_options[:memcached]
|
16
|
+
@cache = Dalli::Client.new(other_options[:memchached])
|
17
|
+
elsif other_options[:redis]
|
18
|
+
@cache = Redis.new(url: other_options[:redis])
|
19
|
+
else
|
20
|
+
@cache = false
|
21
|
+
end
|
22
|
+
@compiler_options_digest = Digest::SHA1.hexdigest(Oj.dump(@compiler_options, mode: :strict)) if cache
|
15
23
|
end
|
16
24
|
|
17
25
|
def ==(other_number)
|
@@ -57,9 +65,9 @@ module OpalWebpackLoader
|
|
57
65
|
end
|
58
66
|
tempfile.chmod(i += 1)
|
59
67
|
ret = begin
|
60
|
-
|
61
|
-
|
62
|
-
|
68
|
+
IO.select([@socket], nil, nil, OpalWebpackLoader::CompileServer::TIMEOUT / 2) || next
|
69
|
+
rescue Errno::EBADF
|
70
|
+
end
|
63
71
|
end
|
64
72
|
end
|
65
73
|
|
@@ -73,6 +81,12 @@ module OpalWebpackLoader
|
|
73
81
|
source = File.read(filename)
|
74
82
|
|
75
83
|
begin
|
84
|
+
if cache
|
85
|
+
source_digest = Digest::SHA1.hexdigest(source)
|
86
|
+
key = "owl_#{compiler_options_digest}_#{source_digest}_#{compile_source_map}"
|
87
|
+
result_json = cache.get(key)
|
88
|
+
return result_json if result_json
|
89
|
+
end
|
76
90
|
c = Opal::Compiler.new(source, @compiler_options.merge(file: filename))
|
77
91
|
result = { 'javascript' => c.compile }
|
78
92
|
if compile_source_map
|
@@ -80,9 +94,11 @@ module OpalWebpackLoader
|
|
80
94
|
result['source_map']['file'] = filename
|
81
95
|
end
|
82
96
|
result['required_trees'] = c.required_trees
|
83
|
-
Oj.dump(result, mode: :strict)
|
97
|
+
result_json = Oj.dump(result, mode: :strict)
|
98
|
+
cache.set(key, result_json) if cache
|
99
|
+
result_json
|
84
100
|
rescue Exception => e
|
85
|
-
Oj.dump({ 'error' => { 'name' => e.class, 'message' => e.message, 'backtrace' => e.backtrace.join("\n") } }, mode: :strict)
|
101
|
+
Oj.dump({ 'error' => { 'name' => e.class.to_s, 'message' => e.message, 'backtrace' => e.backtrace.join("\n") } }, mode: :strict)
|
86
102
|
end
|
87
103
|
end
|
88
104
|
end
|
@@ -48,7 +48,7 @@ const common_config = {
|
|
48
48
|
{
|
49
49
|
// loader for .scss files
|
50
50
|
// test means "test for for file endings"
|
51
|
-
test:
|
51
|
+
test: /\.s[ac]ss$/,
|
52
52
|
use: [
|
53
53
|
{ loader: "style-loader" },
|
54
54
|
{
|
@@ -66,7 +66,7 @@ const common_config = {
|
|
66
66
|
},
|
67
67
|
{
|
68
68
|
// loader for .css files
|
69
|
-
test:
|
69
|
+
test: /\.css$/,
|
70
70
|
use: [
|
71
71
|
{ loader: "style-loader" },
|
72
72
|
{
|
@@ -76,7 +76,7 @@ const common_config = {
|
|
76
76
|
]
|
77
77
|
},
|
78
78
|
{
|
79
|
-
test:
|
79
|
+
test: /\.(png|svg|jpg|gif|woff|woff2|eot|ttf|otf)$/,
|
80
80
|
use: [ "file-loader" ]
|
81
81
|
},
|
82
82
|
{
|
@@ -39,7 +39,7 @@ const common_config = {
|
|
39
39
|
{
|
40
40
|
// loader for .scss files
|
41
41
|
// test means "test for for file endings"
|
42
|
-
test:
|
42
|
+
test: /\.s[ac]ss$/,
|
43
43
|
use: [
|
44
44
|
{ loader: "style-loader" },
|
45
45
|
{ loader: "css-loader" },
|
@@ -54,14 +54,14 @@ const common_config = {
|
|
54
54
|
},
|
55
55
|
{
|
56
56
|
// loader for .css files
|
57
|
-
test:
|
57
|
+
test: /\.css$/,
|
58
58
|
use: [
|
59
59
|
{ loader: "style-loader" },
|
60
60
|
{ loader: "css-loader" }
|
61
61
|
]
|
62
62
|
},
|
63
63
|
{
|
64
|
-
test:
|
64
|
+
test: /\.(png|svg|jpg|gif|woff|woff2|eot|ttf|otf)$/,
|
65
65
|
use: [ "file-loader" ]
|
66
66
|
},
|
67
67
|
{
|
@@ -9,18 +9,18 @@
|
|
9
9
|
"production_build": "<%= production_script %>"
|
10
10
|
},
|
11
11
|
"devDependencies": {
|
12
|
-
"compression-webpack-plugin": "^
|
13
|
-
"css-loader": "^
|
12
|
+
"compression-webpack-plugin": "^5.0.2",
|
13
|
+
"css-loader": "^5.2.4",
|
14
14
|
"extra-watch-webpack-plugin": "^1.0.3",
|
15
|
-
"file-loader": "^
|
16
|
-
"node-sass": "^
|
17
|
-
"parallel-webpack": "^2.
|
18
|
-
"sass-loader": "^
|
19
|
-
"style-loader": "^
|
20
|
-
"terser-webpack-plugin": "^
|
21
|
-
"webpack": "^4.
|
22
|
-
"webpack-assets-manifest": "^
|
23
|
-
"webpack-cli": "^
|
24
|
-
"webpack-dev-server": "^3.
|
15
|
+
"file-loader": "^6.2.0",
|
16
|
+
"node-sass": "^6.0.0",
|
17
|
+
"parallel-webpack": "^2.6.0",
|
18
|
+
"sass-loader": "^10.0.5",
|
19
|
+
"style-loader": "^2.0.0",
|
20
|
+
"terser-webpack-plugin": "^4.2.3",
|
21
|
+
"webpack": "^4.46.0",
|
22
|
+
"webpack-assets-manifest": "^4.0.6",
|
23
|
+
"webpack-cli": "^4.7.0",
|
24
|
+
"webpack-dev-server": "^3.11.2"
|
25
25
|
}
|
26
26
|
}
|
@@ -9,7 +9,7 @@ const common_config = {
|
|
9
9
|
mode: "production",
|
10
10
|
optimization: {
|
11
11
|
minimize: true, // minimize
|
12
|
-
minimizer: [new TerserPlugin({ parallel: true
|
12
|
+
minimizer: [new TerserPlugin({ parallel: true })]
|
13
13
|
},
|
14
14
|
performance: {
|
15
15
|
maxAssetSize: 20000000,
|
@@ -26,13 +26,13 @@ const common_config = {
|
|
26
26
|
]
|
27
27
|
},
|
28
28
|
plugins: [
|
29
|
-
new CompressionPlugin({ test: /^((?!application_ssr).)
|
30
|
-
new WebpackAssetsManifest({ publicPath: true, merge: true }) // generate manifest
|
29
|
+
new CompressionPlugin({ test: /^((?!application_ssr).)*$/ }), // gzip compress, exclude application_ssr.js
|
30
|
+
new WebpackAssetsManifest({ publicPath: true, merge: true, output: 'manifest.json' }) // generate manifest
|
31
31
|
],
|
32
32
|
module: {
|
33
33
|
rules: [
|
34
34
|
{
|
35
|
-
test:
|
35
|
+
test: /\.s[ac]ss$/,
|
36
36
|
use: [
|
37
37
|
{ loader: "style-loader" },
|
38
38
|
{
|
@@ -53,11 +53,11 @@ const common_config = {
|
|
53
53
|
},
|
54
54
|
{
|
55
55
|
// loader for .css files
|
56
|
-
test:
|
56
|
+
test: /\.css$/,
|
57
57
|
use: [ "style-loader", "css-loader" ]
|
58
58
|
},
|
59
59
|
{
|
60
|
-
test:
|
60
|
+
test: /\.(png|svg|jpg|gif|woff|woff2|eot|ttf|otf)$/,
|
61
61
|
use: [ "file-loader" ]
|
62
62
|
},
|
63
63
|
{
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module OpalWebpackLoader
|
2
|
-
VERSION="0.
|
3
|
-
end
|
1
|
+
module OpalWebpackLoader
|
2
|
+
VERSION="0.10.1"
|
3
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opal-webpack-loader
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.10.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -38,20 +38,48 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: dalli
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.7.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.7.0
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: oj
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
44
58
|
requirements:
|
45
59
|
- - ">="
|
46
60
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.
|
61
|
+
version: 3.11.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 3.11.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redis
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 4.2.0
|
48
76
|
type: :runtime
|
49
77
|
prerelease: false
|
50
78
|
version_requirements: !ruby/object:Gem::Requirement
|
51
79
|
requirements:
|
52
80
|
- - ">="
|
53
81
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
82
|
+
version: 4.2.0
|
55
83
|
- !ruby/object:Gem::Dependency
|
56
84
|
name: thor
|
57
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -114,28 +142,28 @@ dependencies:
|
|
114
142
|
requirements:
|
115
143
|
- - "~>"
|
116
144
|
- !ruby/object:Gem::Version
|
117
|
-
version:
|
145
|
+
version: 6.1.0
|
118
146
|
type: :development
|
119
147
|
prerelease: false
|
120
148
|
version_requirements: !ruby/object:Gem::Requirement
|
121
149
|
requirements:
|
122
150
|
- - "~>"
|
123
151
|
- !ruby/object:Gem::Version
|
124
|
-
version:
|
152
|
+
version: 6.1.0
|
125
153
|
- !ruby/object:Gem::Dependency
|
126
154
|
name: roda
|
127
155
|
requirement: !ruby/object:Gem::Requirement
|
128
156
|
requirements:
|
129
157
|
- - "~>"
|
130
158
|
- !ruby/object:Gem::Version
|
131
|
-
version: 3.
|
159
|
+
version: 3.43.0
|
132
160
|
type: :development
|
133
161
|
prerelease: false
|
134
162
|
version_requirements: !ruby/object:Gem::Requirement
|
135
163
|
requirements:
|
136
164
|
- - "~>"
|
137
165
|
- !ruby/object:Gem::Version
|
138
|
-
version: 3.
|
166
|
+
version: 3.43.0
|
139
167
|
- !ruby/object:Gem::Dependency
|
140
168
|
name: rspec
|
141
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -156,14 +184,14 @@ dependencies:
|
|
156
184
|
requirements:
|
157
185
|
- - ">="
|
158
186
|
- !ruby/object:Gem::Version
|
159
|
-
version:
|
187
|
+
version: 5.3.0
|
160
188
|
type: :development
|
161
189
|
prerelease: false
|
162
190
|
version_requirements: !ruby/object:Gem::Requirement
|
163
191
|
requirements:
|
164
192
|
- - ">="
|
165
193
|
- !ruby/object:Gem::Version
|
166
|
-
version:
|
194
|
+
version: 5.3.0
|
167
195
|
description: "Bundle assets with webpack, resolve and compile opal ruby files\nand
|
168
196
|
import them in the bundle, without sprockets or the webpacker gem\n(but can be used
|
169
197
|
with both of them too). \nComes with a installer for rails and other frameworks.\n"
|
@@ -172,11 +200,14 @@ executables:
|
|
172
200
|
- opal-webpack-compile-server
|
173
201
|
- owl-install
|
174
202
|
- owl-gen-loadpath-cache
|
203
|
+
- owl-compiler
|
175
204
|
extensions: []
|
176
205
|
extra_rdoc_files: []
|
177
206
|
files:
|
178
207
|
- LICENSE
|
208
|
+
- README.md
|
179
209
|
- bin/opal-webpack-compile-server
|
210
|
+
- bin/owl-compiler
|
180
211
|
- bin/owl-gen-loadpath-cache
|
181
212
|
- bin/owl-install
|
182
213
|
- lib/opal-webpack-loader.rb
|
@@ -207,8 +238,9 @@ files:
|
|
207
238
|
homepage: http://isomorfeus.com
|
208
239
|
licenses:
|
209
240
|
- MIT
|
210
|
-
metadata:
|
211
|
-
|
241
|
+
metadata:
|
242
|
+
github_repo: ssh://github.com/isomorfeus/gems
|
243
|
+
post_install_message:
|
212
244
|
rdoc_options: []
|
213
245
|
require_paths:
|
214
246
|
- lib
|
@@ -223,8 +255,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
223
255
|
- !ruby/object:Gem::Version
|
224
256
|
version: '0'
|
225
257
|
requirements: []
|
226
|
-
rubygems_version: 3.
|
227
|
-
signing_key:
|
258
|
+
rubygems_version: 3.2.15
|
259
|
+
signing_key:
|
228
260
|
specification_version: 4
|
229
261
|
summary: Bundle assets with webpack, resolve and compile opal ruby files and import
|
230
262
|
them in the bundle.
|