opal-webpack-loader 0.9.7 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +214 -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 +5 -9
- data/lib/opal-webpack-loader/templates/development.js.erb +8 -9
- data/lib/opal-webpack-loader/templates/initializer.rb.erb +3 -1
- data/lib/opal-webpack-loader/templates/package.json.erb +12 -14
- data/lib/opal-webpack-loader/templates/production.js.erb +9 -11
- 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: 47e73212d646dde8e4fbad0d525e3146564bde7ca2e5518d644f972a5a908860
|
4
|
+
data.tar.gz: cb1243d2b4bf3158ec87c9815d07333ddeae470c1f838e6f51c5ee4df082f5d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22b303793fb6845b9277530f06d0f194975d2ca7475e7e6434efaebf9a990af904e2f7b1887d42a3fe7967ecfc615271b128a374e6d2b9043db7d2ed7e2dedee
|
7
|
+
data.tar.gz: 7232d4066bbd4ef90fdd852dfef6f08ad7fdbd8e139051a7a62e16b4b9345f06ecb38435ef19220e0657f4eb815bf232e530fe3b67ebcc72acf19d9bda3c441b
|
data/README.md
ADDED
@@ -0,0 +1,214 @@
|
|
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): [![Build Status](https://travis-ci.org/isomorfeus/opal-webpack-loader.svg?branch=master)](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
|
+
- opal modules are packaged as es6 modules
|
27
|
+
- support for rails with webpacker
|
28
|
+
- other webpack features become available, like:
|
29
|
+
- source maps
|
30
|
+
- multiple targets: web (for browsers), node (for server side rendering) and webworker (for Web Workers)
|
31
|
+
- hot module reloading for opal ruby code and stylesheets and html views
|
32
|
+
- tree shaking
|
33
|
+
- code splitting
|
34
|
+
- lazy loading
|
35
|
+
- everything else webpack can do, like loading stylesheets, etc.
|
36
|
+
|
37
|
+
### Requirements
|
38
|
+
- opal-webpack-loader consists of 2 parts, the npm package and the gem, both are required and must be the same version.
|
39
|
+
- webpack ^4.41
|
40
|
+
- webpack-dev-server ^3.9.0
|
41
|
+
- one of the ES6 modules branches of opal
|
42
|
+
- [PR#1973](https://github.com/opal/opal/pull/1973), (experimental) implementing ES6 modules and changes for 'strict' mode,
|
43
|
+
based on Opal master 1.0.0 using javascript string objects "mutable strings" by default for all strings
|
44
|
+
|
45
|
+
`gem 'opal', github: 'janbiedermann/opal', branch: 'es6_modules_string'`
|
46
|
+
|
47
|
+
- [PR#1976](https://github.com/opal/opal/pull/1976), (recommended) implementing ES6 modules and changes for 'strict' mode,
|
48
|
+
based on Opal master 1.1.0 using javascript string primitives and providing nice features like `require_lazy 'my_module'`
|
49
|
+
|
50
|
+
`gem 'opal', github: 'janbiedermann/opal', branch: 'es6_modules_1_1'`
|
51
|
+
|
52
|
+
- if you have the webpacker gem installed somewhere, it should be a version supporting webpack 4
|
53
|
+
- ruby, version 2.5 or higher recommended
|
54
|
+
- bundler, latest version recommended
|
55
|
+
|
56
|
+
### Installation
|
57
|
+
|
58
|
+
#### Using the installer
|
59
|
+
First install the gem:
|
60
|
+
```
|
61
|
+
gem install 'opal-webpack-loader'
|
62
|
+
```
|
63
|
+
|
64
|
+
Continue here:
|
65
|
+
- [Install for Rails like projects](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/installation_rails.md)
|
66
|
+
- [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)
|
67
|
+
- [Manual Installation](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/installation_manual.md)
|
68
|
+
|
69
|
+
### Example applications
|
70
|
+
- [Are here](https://github.com/isomorfeus/opal-webpack-loader/tree/master/example_apps/)
|
71
|
+
- A minimal webpack only example from @sunrick is [here](https://github.com/sunrick/opal-hello-world-webpack).
|
72
|
+
|
73
|
+
### General Usage without Webpacker
|
74
|
+
|
75
|
+
After installing owl with the installer, three scripts are provided in package.json:
|
76
|
+
- `development` - runs the webpack-dev-server, use for general development, provides fast reloads, entry is application.js
|
77
|
+
- `debug` - runs the webpack-dev-server, use for debugging, provides source maps, entry is application_debug.js. Additional debugging tools may be added there.
|
78
|
+
- `production_build` - runs webpack to build assets for production, entry is application.js
|
79
|
+
|
80
|
+
These scripts can for example be run with:
|
81
|
+
`yarn run debug` or `npm run debug`
|
82
|
+
|
83
|
+
The default config provides several targets and entries:
|
84
|
+
|
85
|
+
- **Browser**: the webpack target is 'web' and the javascript entry file for imports is `application.js` - general use for the application with all
|
86
|
+
browser features, the opal ruby entry file is `opal_loader.rb` in the opal or app/opal directory of the app.
|
87
|
+
- **Server Side Rendering**: the webpack target is `node` and the javascript entry file for imports is `application_ssr.js` - general use for the
|
88
|
+
application server side rendering, several Browser features are unavailable, no `window`, no `document`, some node features are available,
|
89
|
+
like `Buffer`, the opal ruby entry file is `opal_loader.rb` in the opal or app/opal directory of the app.
|
90
|
+
(meant to be used with isomorfeus-speednode, standard ExecJS limitations prevent certain webpack features)
|
91
|
+
- **Web Worker**: the webpack target is 'webworker' and the javascript entry file for imports is `application_webworker.js` - used to initialize Web
|
92
|
+
Workers in the browser, the opal ruby entry file is `opal_webworker_loader.rb` in the opal or app/opal directory of the app.
|
93
|
+
|
94
|
+
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,
|
95
|
+
for example to `development.js`:
|
96
|
+
default config:
|
97
|
+
```javascript
|
98
|
+
module.exports = [ browser ];
|
99
|
+
```
|
100
|
+
modified config with ssr and web_worker targets enabled:
|
101
|
+
```javascript
|
102
|
+
module.exports = [ browser, ssr, web_worker ];
|
103
|
+
```
|
104
|
+
Same works for the `debug.js` and `production.js` webpack config files.
|
105
|
+
|
106
|
+
Also a Procfile has been installed, for rails its easy to startup rails and webpack with foreman:
|
107
|
+
`foreman start` (`gem install foreman` if you dont have it already). It will start rails and webpack-dev-server with the development script.
|
108
|
+
|
109
|
+
For non rails installation check the Procfile and add a starter for your app.
|
110
|
+
|
111
|
+
#### Opal Ruby Application Files
|
112
|
+
For rails installations with the installer they all go into: `app/opal`, for flat installations in the `opal` directory.
|
113
|
+
In this directory there already is a `opal_loader.rb` which is the entry point for your app.
|
114
|
+
|
115
|
+
#### Stylesheets
|
116
|
+
Stylesheets are hot reloaded too with the default config installed by the installer. Also they are imported into application.js by default.
|
117
|
+
For rails like applications stylesheets are in `app/assets/stylesheets/application.css`, for flat applications they are in `styles/application.css`.
|
118
|
+
SCSS is supported too by the default config.
|
119
|
+
|
120
|
+
#### Views
|
121
|
+
For rails like applications a watcher for `app/views` is installed by default. The watcher will trigger a page reload when views are changed.
|
122
|
+
For flat applications nothing is configured by default, as there are to many ways to generate views, they are not even needed with
|
123
|
+
frameworks like isomorfeus. Instead the section for configuring a view watcher is included in the development.js and debug.js webpack
|
124
|
+
config, but it is commented out. Please see those files and adjust to your liking.
|
125
|
+
|
126
|
+
#### Parallel compilation for speed
|
127
|
+
|
128
|
+
Since version 0.8.0 the number of CPUs is automatically determined and a appropriate number of of compile server workers is started automatically.
|
129
|
+
|
130
|
+
### Source Maps
|
131
|
+
|
132
|
+
[Source Maps](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/source_maps.md)
|
133
|
+
|
134
|
+
### Hot Module Reloading
|
135
|
+
[Hot Module Reloading](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/hot_module_reloading.md)
|
136
|
+
|
137
|
+
### Opal Load Path
|
138
|
+
The projects directory for opal ruby files must be in the opal load path. This is done in the initializer for rails apps in
|
139
|
+
config/initializers/opal_webpack_loader.rb or in 'owl_init.rb' for non rails apps, for example:
|
140
|
+
```ruby
|
141
|
+
Opal.append_path(File.realdirpath('app/opal'))
|
142
|
+
```
|
143
|
+
|
144
|
+
### View Helper
|
145
|
+
In Rails or frameworks that support `javscript_include_tag`, add to the app/helpers/application_helper.rb
|
146
|
+
```ruby
|
147
|
+
module ApplicationHelper
|
148
|
+
include OpalWebpackLoader::RailsViewHelper
|
149
|
+
```
|
150
|
+
in other frameworks that dont have a `javascript_include_tag`:
|
151
|
+
```ruby
|
152
|
+
module MyProjectsViewThings
|
153
|
+
include OpalWebpackLoader::ViewHelper
|
154
|
+
```
|
155
|
+
|
156
|
+
Then you can use in your views:
|
157
|
+
```ruby
|
158
|
+
owl_script_tag('application.js')
|
159
|
+
```
|
160
|
+
#### Compile Server and app_loader.rb
|
161
|
+
For non rails projects, determining Opal load paths, for the resolver and compile server to work properly, may not be obvious. For these cases
|
162
|
+
a file `app_loader.rb` in the projects root can be created which just loads all requirements without starting anything.
|
163
|
+
Usually it would just setup bundler with the appropriate options, for example:
|
164
|
+
```ruby
|
165
|
+
require 'bundler/setup'
|
166
|
+
if ENV['RACK_ENV'] && ENV['RACK_ENV'] == 'test'
|
167
|
+
Bundler.require(:default, :test)
|
168
|
+
elsif ENV['RACK_ENV'] && ENV['RACK_ENV'] == 'production'
|
169
|
+
Bundler.require(:default, :production)
|
170
|
+
else
|
171
|
+
Bundler.require(:default, :development)
|
172
|
+
end
|
173
|
+
Opal.append_path(File.realdirpath('opal')) # this is a good place to add the directory with opal files to the opal load path
|
174
|
+
```
|
175
|
+
When this file exists, the compile server will load it and generate Opal load paths accordingly for the resolver.
|
176
|
+
|
177
|
+
#### Project configuration options for the view helper
|
178
|
+
These setting are in the initializer in config/initializers/opal_webpack_loader.rb for rails like apps, or owl_init.rb for others.
|
179
|
+
```ruby
|
180
|
+
OpalWebpackLoader.use_manifest = false
|
181
|
+
```
|
182
|
+
If the manifest file should be used, use_manifest should be true.
|
183
|
+
```ruby
|
184
|
+
OpalWebpackLoader.manifest_path = File.join(Dir.getwd, 'public', 'assets', 'manifest.json')
|
185
|
+
```
|
186
|
+
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.
|
187
|
+
```ruby
|
188
|
+
OpalWebpackLoader.client_asset_path = 'http://localhost:3035/assets/'
|
189
|
+
```
|
190
|
+
The path to prepend to the assets as configured in the webpack config 'publicPath'.
|
191
|
+
In the config example below its `publicPath: 'http://localhost:3025/assets'` so
|
192
|
+
client_asset_path should be set to the same.
|
193
|
+
|
194
|
+
For **production** use with readily precompiled and compressed assets which contain a fingerprint in the name (webpacks [chunkhash]),
|
195
|
+
and if the path in the manifest is the full path to the asset as configured in webpack,
|
196
|
+
these settings would work:
|
197
|
+
```ruby
|
198
|
+
OpalWebpackLoader.use_manifest = true
|
199
|
+
OpalWebpackLoader.manifest_path = File.join(Dir.getwd, 'public', 'assets', 'manifest.json')
|
200
|
+
OpalWebpackLoader.client_asset_path = ''
|
201
|
+
```
|
202
|
+
|
203
|
+
For **development** use with webpack-dev-server, with no manifest, these settings would work:
|
204
|
+
```ruby
|
205
|
+
OpalWebpackLoader.use_manifest = false
|
206
|
+
OpalWebpackLoader.manifest_path = File.join(Dir.getwd, 'public', 'assets', 'manifest.json') # doesn't matter, not used
|
207
|
+
OpalWebpackLoader.client_asset_path = 'http://localhost:3035/assets/'
|
208
|
+
```
|
209
|
+
### Advanced Options
|
210
|
+
[Advanced Options](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/advanced_options.md)
|
211
|
+
### Tests
|
212
|
+
- clone the repo
|
213
|
+
- `bundle install`
|
214
|
+
- `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
|
@@ -1,6 +1,5 @@
|
|
1
1
|
const path = require('path');
|
2
2
|
const webpack = require('webpack');
|
3
|
-
const chokidar = require('chokidar');
|
4
3
|
const OwlResolver = require('opal-webpack-loader/resolver'); // to resolve ruby files
|
5
4
|
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin'); // to watch for added ruby files
|
6
5
|
|
@@ -49,9 +48,8 @@ const common_config = {
|
|
49
48
|
{
|
50
49
|
// loader for .scss files
|
51
50
|
// test means "test for for file endings"
|
52
|
-
test:
|
51
|
+
test: /\.s[ac]ss$/,
|
53
52
|
use: [
|
54
|
-
{ loader: "cache-loader" },
|
55
53
|
{ loader: "style-loader" },
|
56
54
|
{
|
57
55
|
loader: "css-loader",
|
@@ -60,7 +58,7 @@ const common_config = {
|
|
60
58
|
{
|
61
59
|
loader: "sass-loader",
|
62
60
|
options: {
|
63
|
-
includePaths: [path.resolve(__dirname, '<%= stylesheets_directory %>')],
|
61
|
+
sassOptions: { includePaths: [path.resolve(__dirname, '<%= stylesheets_directory %>')] },
|
64
62
|
sourceMap: true // set to false to speed up hot reloads
|
65
63
|
}
|
66
64
|
}
|
@@ -68,9 +66,8 @@ const common_config = {
|
|
68
66
|
},
|
69
67
|
{
|
70
68
|
// loader for .css files
|
71
|
-
test:
|
69
|
+
test: /\.css$/,
|
72
70
|
use: [
|
73
|
-
{ loader: "cache-loader" },
|
74
71
|
{ loader: "style-loader" },
|
75
72
|
{
|
76
73
|
loader: "css-loader",
|
@@ -79,14 +76,13 @@ const common_config = {
|
|
79
76
|
]
|
80
77
|
},
|
81
78
|
{
|
82
|
-
test:
|
83
|
-
use: [ "
|
79
|
+
test: /\.(png|svg|jpg|gif|woff|woff2|eot|ttf|otf)$/,
|
80
|
+
use: [ "file-loader" ]
|
84
81
|
},
|
85
82
|
{
|
86
83
|
// opal-webpack-loader will compile and include ruby files in the pack
|
87
84
|
test: /(\.js)?\.rb$/,
|
88
85
|
use: [
|
89
|
-
{ loader: "cache-loader" },
|
90
86
|
{
|
91
87
|
loader: 'opal-webpack-loader',
|
92
88
|
options: {
|
@@ -1,6 +1,5 @@
|
|
1
1
|
const path = require('path');
|
2
2
|
const webpack = require('webpack');
|
3
|
-
const chokidar = require('chokidar');
|
4
3
|
const OwlResolver = require('opal-webpack-loader/resolver'); // to resolve ruby files
|
5
4
|
const ExtraWatchWebpackPlugin = require('extra-watch-webpack-plugin'); // to watch for added ruby files
|
6
5
|
|
@@ -40,35 +39,35 @@ const common_config = {
|
|
40
39
|
{
|
41
40
|
// loader for .scss files
|
42
41
|
// test means "test for for file endings"
|
43
|
-
test:
|
42
|
+
test: /\.s[ac]ss$/,
|
44
43
|
use: [
|
45
|
-
{ loader: "cache-loader" },
|
46
44
|
{ loader: "style-loader" },
|
47
45
|
{ loader: "css-loader" },
|
48
46
|
{
|
49
47
|
loader: "sass-loader",
|
50
|
-
options: {
|
48
|
+
options: {
|
49
|
+
sassOptions: { includePaths: [path.resolve(__dirname, '<%= stylesheets_directory %>')] },
|
50
|
+
sourceMap: false
|
51
|
+
}
|
51
52
|
}
|
52
53
|
]
|
53
54
|
},
|
54
55
|
{
|
55
56
|
// loader for .css files
|
56
|
-
test:
|
57
|
+
test: /\.css$/,
|
57
58
|
use: [
|
58
|
-
{ loader: "cache-loader" },
|
59
59
|
{ loader: "style-loader" },
|
60
60
|
{ loader: "css-loader" }
|
61
61
|
]
|
62
62
|
},
|
63
63
|
{
|
64
|
-
test:
|
65
|
-
use: [ "
|
64
|
+
test: /\.(png|svg|jpg|gif|woff|woff2|eot|ttf|otf)$/,
|
65
|
+
use: [ "file-loader" ]
|
66
66
|
},
|
67
67
|
{
|
68
68
|
// opal-webpack-loader will compile and include ruby files in the pack
|
69
69
|
test: /(\.js)?\.rb$/,
|
70
70
|
use: [
|
71
|
-
{ loader: "cache-loader" },
|
72
71
|
{
|
73
72
|
loader: 'opal-webpack-loader',
|
74
73
|
options: {
|
@@ -9,20 +9,18 @@
|
|
9
9
|
"production_build": "<%= production_script %>"
|
10
10
|
},
|
11
11
|
"devDependencies": {
|
12
|
-
"
|
13
|
-
"
|
14
|
-
"compression-webpack-plugin": "^3.0.0",
|
15
|
-
"css-loader": "^3.2.0",
|
12
|
+
"compression-webpack-plugin": "^5.0.2",
|
13
|
+
"css-loader": "^5.2.4",
|
16
14
|
"extra-watch-webpack-plugin": "^1.0.3",
|
17
|
-
"file-loader": "^
|
18
|
-
"node-sass": "^
|
19
|
-
"parallel-webpack": "^2.
|
20
|
-
"sass-loader": "^
|
21
|
-
"style-loader": "^
|
22
|
-
"terser-webpack-plugin": "^
|
23
|
-
"webpack": "^4.
|
24
|
-
"webpack-assets-manifest": "^
|
25
|
-
"webpack-cli": "^
|
26
|
-
"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"
|
27
25
|
}
|
28
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,15 +26,14 @@ 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
|
-
{ loader: "cache-loader" },
|
38
37
|
{ loader: "style-loader" },
|
39
38
|
{
|
40
39
|
loader: "css-loader",
|
@@ -46,7 +45,7 @@ const common_config = {
|
|
46
45
|
{
|
47
46
|
loader: "sass-loader",
|
48
47
|
options: {
|
49
|
-
includePath: [path.resolve(__dirname, '<%= stylesheets_directory %>')],
|
48
|
+
sassOptions: { includePath: [path.resolve(__dirname, '<%= stylesheets_directory %>')] },
|
50
49
|
sourceMap: false // set to false to speed up hot reloads
|
51
50
|
}
|
52
51
|
}
|
@@ -54,18 +53,17 @@ const common_config = {
|
|
54
53
|
},
|
55
54
|
{
|
56
55
|
// loader for .css files
|
57
|
-
test:
|
58
|
-
use: [ "
|
56
|
+
test: /\.css$/,
|
57
|
+
use: [ "style-loader", "css-loader" ]
|
59
58
|
},
|
60
59
|
{
|
61
|
-
test:
|
62
|
-
use: [ "
|
60
|
+
test: /\.(png|svg|jpg|gif|woff|woff2|eot|ttf|otf)$/,
|
61
|
+
use: [ "file-loader" ]
|
63
62
|
},
|
64
63
|
{
|
65
64
|
// opal-webpack-loader will compile and include ruby files in the pack
|
66
65
|
test: /(\.js)?\.rb$/,
|
67
66
|
use: [
|
68
|
-
{ loader: "cache-loader" },
|
69
67
|
{
|
70
68
|
loader: 'opal-webpack-loader',
|
71
69
|
options: {
|
@@ -1,3 +1,3 @@
|
|
1
|
-
module OpalWebpackLoader
|
2
|
-
VERSION="0.
|
3
|
-
end
|
1
|
+
module OpalWebpackLoader
|
2
|
+
VERSION="0.10.0"
|
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.0
|
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.
|