opal-webpack-loader 0.7.3 → 0.7.4
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/lib/opal-webpack-loader/compile_server.rb +4 -9
- data/lib/opal-webpack-loader/compile_worker.rb +1 -1
- data/lib/opal-webpack-loader/installer_cli.rb +7 -21
- data/lib/opal-webpack-loader/templates/initializer.rb.erb +2 -2
- data/lib/opal-webpack-loader/version.rb +1 -1
- data/readme.md +31 -162
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6db01d779ed0f9e15291c68cf42b154f104467af55d65441fd1ff36423c28e2d
|
4
|
+
data.tar.gz: b6acd6bff5f734bb69992e6d63d8fc702d8bce65cf67032eb3678ee92a00cfc5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62c15a3c9d2f6b829b6337e3291c854ddd659fb54ae1f90fa4300be3ef16fccb477fcb3c3e02431f16d2288d006b323717a340e7627f5e5e3fe728bb66627c6c
|
7
|
+
data.tar.gz: 0fdd85e7a30c38b28b192d748861271b2989ec98279165018ed7b7b85f12531caa00b9a7ba80d877704e503b384b8a9c7b6d407c80465709d0939d101fba7919
|
@@ -1,11 +1,12 @@
|
|
1
1
|
require 'socket'
|
2
|
+
require 'tempfile'
|
2
3
|
|
3
4
|
module OpalWebpackLoader
|
4
5
|
class CompileServer
|
5
6
|
OWL_CACHE_DIR = File.join('.','.owl_cache/')
|
6
7
|
OWL_LP_CACHE = File.join(OWL_CACHE_DIR, 'load_paths.json')
|
7
8
|
OWCS_SOCKET_PATH = File.join(OWL_CACHE_DIR, 'owcs_socket')
|
8
|
-
SIGNALS = %w[QUIT INT TERM
|
9
|
+
SIGNALS = %w[QUIT INT TERM]
|
9
10
|
TIMEOUT = 15
|
10
11
|
|
11
12
|
def self.unlink_socket?
|
@@ -53,7 +54,8 @@ module OpalWebpackLoader
|
|
53
54
|
|
54
55
|
loop do
|
55
56
|
reap_workers
|
56
|
-
|
57
|
+
mode = @signal_queue.shift
|
58
|
+
case mode
|
57
59
|
when nil
|
58
60
|
kill_runaway_workers
|
59
61
|
spawn_workers
|
@@ -62,13 +64,6 @@ module OpalWebpackLoader
|
|
62
64
|
Process.kill('TERM', pid)
|
63
65
|
end
|
64
66
|
break
|
65
|
-
when 'TTIN'
|
66
|
-
@number_of_workers += 1
|
67
|
-
when 'TTOU'
|
68
|
-
unless @number_of_workers <= 0
|
69
|
-
Config.workers -= 1
|
70
|
-
kill_worker('QUIT', @workers.keys.max)
|
71
|
-
end
|
72
67
|
end
|
73
68
|
reap_workers
|
74
69
|
ready = IO.select([@read_pipe], nil, nil, 1) || next
|
@@ -41,13 +41,11 @@ module OpalWebpackLoader
|
|
41
41
|
@opal_directory = 'isomorfeus'
|
42
42
|
@styles_directory = File.join(@opal_directory, 'styles')
|
43
43
|
@webpack_config_directory = 'webpack'
|
44
|
-
|
45
|
-
|
44
|
+
create_directory(@webpack_config_directory)
|
45
|
+
create_directory(@asset_output_directory)
|
46
46
|
install_webpack_config
|
47
|
-
create_file_from_template('
|
48
|
-
create_file_from_template('initializer.rb.erb', File.join('config', 'owl_init.rb'), {})
|
47
|
+
create_file_from_template('initializer.rb.erb', File.join('owl_init.rb'), { opal_directory: @opal_directory })
|
49
48
|
add_gem
|
50
|
-
print_message
|
51
49
|
end
|
52
50
|
|
53
51
|
desc "flat", "Install owl configuration into a existing project with a flat structure, execute from the projects root directory."
|
@@ -80,7 +78,6 @@ module OpalWebpackLoader
|
|
80
78
|
@opal_directory = options[:opal_name]
|
81
79
|
@styles_directory = 'styles'
|
82
80
|
@webpack_config_directory = 'webpack'
|
83
|
-
create_directory(@styles_directory)
|
84
81
|
create_common_directories
|
85
82
|
install_common_things
|
86
83
|
create_file_from_template('application.css.erb', File.join('styles', 'application.css'), {})
|
@@ -125,7 +122,6 @@ module OpalWebpackLoader
|
|
125
122
|
@styles_directory = File.join('app', 'assets', 'stylesheets')
|
126
123
|
@webpack_config_directory = File.join('config', 'webpack')
|
127
124
|
create_directory('app')
|
128
|
-
create_directory(@styles_directory)
|
129
125
|
create_common_directories
|
130
126
|
install_common_things
|
131
127
|
create_file_from_template('initializer.rb.erb', File.join('config', 'initializers', 'opal_webpack_loader.rb'),
|
@@ -148,14 +144,7 @@ module OpalWebpackLoader
|
|
148
144
|
create_directory(@js_entrypoints_directory)
|
149
145
|
create_directory(@opal_directory)
|
150
146
|
create_directory(@asset_output_directory)
|
151
|
-
|
152
|
-
|
153
|
-
def create_isomorfeus_directories
|
154
|
-
create_directory(File.join('isomorfeus', 'components'))
|
155
|
-
create_directory(File.join('isomorfeus', 'models'))
|
156
|
-
create_directory(File.join('isomorfeus', 'operations'))
|
157
|
-
create_directory(File.join('isomorfeus', 'policies'))
|
158
|
-
create_directory(File.join('isomorfeus', 'styles'))
|
147
|
+
create_directory(@styles_directory)
|
159
148
|
end
|
160
149
|
|
161
150
|
def install_common_things
|
@@ -296,11 +285,8 @@ module OpalWebpackLoader
|
|
296
285
|
end
|
297
286
|
|
298
287
|
def add_gem
|
299
|
-
# TODO
|
300
|
-
#
|
301
|
-
# STDERR.puts OpalWebpackLoader::VERSION
|
302
|
-
# `bundle add opal-webpack-loader -v "#{OpalWebpackLoader::VERSION}" --skip-install`
|
303
|
-
# specifying a version results in a bundler printing a error and not adding the gem
|
288
|
+
# TODO specifying a version results in bundler printing a error and not adding the gem
|
289
|
+
# `bundle add opal-webpack-loader -v "#{OpalWebpackLoader::VERSION}" --skip-install`ß´
|
304
290
|
end
|
305
291
|
|
306
292
|
def print_message
|
@@ -308,7 +294,7 @@ module OpalWebpackLoader
|
|
308
294
|
|
309
295
|
Add the following lines to your Gemfile:
|
310
296
|
|
311
|
-
gem 'opal', github: 'janbiedermann/opal', branch: '
|
297
|
+
gem 'opal', github: 'janbiedermann/opal', branch: 'es6_modules'
|
312
298
|
gem 'opal-webpack-loader', '~> #{OpalWebpackLoader::VERSION}'
|
313
299
|
|
314
300
|
owl currently works only with above opal branch. If you have a existing "gem 'opal'", please replace it with above line.
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Opal.append_path(File.realdirpath('<%= opal_directory %>'))
|
2
2
|
|
3
|
-
env = defined?(Rails) ? Rails.env : '
|
4
|
-
|
3
|
+
env = defined?(Rails) ? Rails.env : ENV['OWL_ENV']
|
4
|
+
env = 'development' unless env
|
5
5
|
if env != 'development'
|
6
6
|
OpalWebpackLoader.client_asset_path = '' # the full path is in the manifest already, like: /assets/application-97fd9c2b7e7bdb112fc1.js
|
7
7
|
OpalWebpackLoader.manifest_path = 'public/assets/manifest.json'
|
data/readme.md
CHANGED
@@ -23,10 +23,25 @@ Intel® Core™ i7-7700HQ CPU @ 2.80GHz × 8, with 8 workers in around 1850ms
|
|
23
23
|
- everything else webpack can do, like loading stylesheets, etc.
|
24
24
|
|
25
25
|
### Requirements
|
26
|
+
- opal-webpack-loader consists of 2 parts, the npm package and the gem, both are required
|
26
27
|
- webpack 4.30
|
27
28
|
- webpack-dev-server 3.3.0
|
28
|
-
-
|
29
|
-
-
|
29
|
+
- one of the ES6 modules branches of opal
|
30
|
+
- [PR#1832](https://github.com/opal/opal/pull/1832), implementing ES6 modules, based on Opal 0.11.1.dev
|
31
|
+
|
32
|
+
`gem 'opal', github: 'janbiedermann/opal', branch: 'es6_import_export', ref: 'e3fdf16e8a657f7d9f9507207848a34953dced8d'`
|
33
|
+
|
34
|
+
- [PR#1970](https://github.com/opal/opal/pull/1969), implementing ES6 modules and changes for 'strict' mode,
|
35
|
+
based on Opal master 1.0.beta using javascript string primitives
|
36
|
+
|
37
|
+
`gem 'opal', github: 'janbiedermann/opal', branch: 'es6_modules'`
|
38
|
+
|
39
|
+
- [PR#1973](https://github.com/opal/opal/pull/1973), implementing ES6 modules and changes for 'strict' mode,
|
40
|
+
based on Opal master 1.0.beta using javascript string objects by default for all strings
|
41
|
+
|
42
|
+
`gem 'opal', github: 'janbiedermann/opal', branch: 'es6_modules_string'`
|
43
|
+
|
44
|
+
- if you have the webpacker gem installed somewhere, it should be a version supporting webpack 4
|
30
45
|
- ruby, version 2.5 or higher recommended
|
31
46
|
- bundler, latest version recommended
|
32
47
|
|
@@ -37,112 +52,14 @@ First install the gem:
|
|
37
52
|
```
|
38
53
|
gem install 'opal-webpack-loader'
|
39
54
|
```
|
40
|
-
##### Install for Rails like projects
|
41
|
-
If you start a new rails project, the following options are recommended for `rails new`: `--skip-sprockets --skip-javascript`
|
42
55
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
If you have the webpacker gem installed, you need to merge the configuration in the config/webpacker directory.
|
48
|
-
A example for config/webpack/development.js is in the
|
49
|
-
[templates](https://github.com/isomorfeus/opal-webpack-loader/blob/master/lib/opal-webpack-loader/templates/webpacker_development.js_example).
|
50
|
-
|
51
|
-
Please see the messages of owl-install. You may need to manually add the following gems to the projects Gemfile:
|
52
|
-
```ruby
|
53
|
-
gem 'opal', github: 'janbiedermann/opal', branch: 'es6_import_export'
|
54
|
-
gem 'opal-webpack-loader', '~> 0.6.2' # use the most recent released version here
|
55
|
-
```
|
56
|
-
|
57
|
-
Then:
|
58
|
-
```bash
|
59
|
-
yarn install
|
60
|
-
bundle install
|
61
|
-
```
|
62
|
-
Opal ruby files should then go in the newly created `app/opal` directory. With the option -o the directory can be named differently, for example:
|
63
|
-
```bash
|
64
|
-
owl-install rails -o hyperhyper
|
65
|
-
```
|
66
|
-
A directory `app/hyperhyper` will be created, opal files should then go there and will be properly resolved by webpack.
|
67
|
-
|
68
|
-
Complete set of directories and files created by the installer for projects with a rails like structure:
|
69
|
-
```
|
70
|
-
project_root
|
71
|
-
+- app
|
72
|
-
+- assets
|
73
|
-
+- javascripts # javascript entries directory
|
74
|
-
+- styles # directory for stylesheets
|
75
|
-
+- opal # directory for opal application files, can be changed with -o
|
76
|
-
+- config
|
77
|
-
+- webpack # directory for webpack configuration files
|
78
|
-
+- initializers
|
79
|
-
+- opal_webpack_loader.rb # initializer for owl
|
80
|
-
+- package.json # package config for npm/yarn and their scripts
|
81
|
-
+- public
|
82
|
-
+- assets # directory for compiled output files
|
83
|
-
+- Procfile # config file for foreman
|
84
|
-
```
|
85
|
-
|
86
|
-
##### Install for Cuba, Roda, Sinatra and others with a flat structure
|
87
|
-
```bash
|
88
|
-
owl-install flat
|
89
|
-
```
|
56
|
+
Continue here:
|
57
|
+
- [Install for Rails like projects](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/installation_rails.md)
|
58
|
+
- [Install for Cuba, Roda, Sinatra and others with a flat structure](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/installation_flat.md)
|
59
|
+
- [Manual Installation](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/installation_manual.md)
|
90
60
|
|
91
|
-
|
92
|
-
|
93
|
-
gem 'opal', github: 'janbiedermann/opal', branch: 'es6_import_export'
|
94
|
-
gem 'opal-webpack-loader', '~> 0.5.1'
|
95
|
-
```
|
96
|
-
|
97
|
-
Then:
|
98
|
-
```bash
|
99
|
-
yarn install
|
100
|
-
bundle install
|
101
|
-
```
|
102
|
-
The installer produces a `app_loader.rb` which `require './owl_init'`. `app_loader.rb` is used by the compile server to correctly determine opal load
|
103
|
-
paths. It should be required by `config.ru`.
|
104
|
-
Opal ruby files should then go in the newly created `opal` directory. With the option -o the directory can be named differently, for example:
|
105
|
-
```bash
|
106
|
-
owl-install rails -o supersuper
|
107
|
-
```
|
108
|
-
A directory `supersuper` will be created, opal files should then go there and will be properly resolved by webpack.
|
109
|
-
|
110
|
-
Complete set of directories and files created by the installer for projects with a flat structure:
|
111
|
-
```
|
112
|
-
project_root
|
113
|
-
+- owl_init.rb # initializer for owl
|
114
|
-
+- javascripts # javascript entries directory
|
115
|
-
+- opal # directory for opal application files, can be changed with -o
|
116
|
-
+- package.json # package config for npm/yarn and their scripts
|
117
|
-
+- public
|
118
|
-
+- assets # directory for compiled output files
|
119
|
-
+- styles # directory for stylesheets
|
120
|
-
+- webpack # directory for webpack configuration files
|
121
|
-
+- Procfile # config file for foreman
|
122
|
-
```
|
123
|
-
|
124
|
-
#### Manual Installation
|
125
|
-
##### Install the accompanying NPM package:
|
126
|
-
one of:
|
127
|
-
```bash
|
128
|
-
npm i opal-webpack-loader
|
129
|
-
yarn add opal-webpack-loader
|
130
|
-
```
|
131
|
-
##### Install the gems
|
132
|
-
```bash
|
133
|
-
gem install opal-webpack-loader
|
134
|
-
```
|
135
|
-
or add it to the Gemfile as below and `bundle install`
|
136
|
-
```ruby
|
137
|
-
source 'https://rubygems.org'
|
138
|
-
|
139
|
-
gem 'opal', github: 'janbiedermann/opal', branch: 'es6_import_export' # requires this branch
|
140
|
-
gem 'opal-autoloader' # recommended
|
141
|
-
gem 'opal-webpack-loader'
|
142
|
-
```
|
143
|
-
##### Install the configuration
|
144
|
-
See the [configuration templates](https://github.com/isomorfeus/opal-webpack-loader/tree/master/lib/opal-webpack-loader/templates)
|
145
|
-
and adjust to your preference.
|
61
|
+
### Example applications
|
62
|
+
[are here](https://github.com/isomorfeus/opal-webpack-loader/tree/master/example_apps/)
|
146
63
|
|
147
64
|
### General Usage
|
148
65
|
|
@@ -205,64 +122,13 @@ The compile server will start 4 workers for compiling opal files. The recommende
|
|
205
122
|
or equal to the number of cores, for machines with up to 12 cores. More than 12 can't be kept busy by webpack it seems, ymmv.
|
206
123
|
Example for 8 cores:
|
207
124
|
`"production_build": "bundle exec opal-webpack-compile-server start 8 webpack --config=config/webpack/production.js"`
|
208
|
-
### Source Maps
|
209
|
-
|
210
|
-
#### Source Map Demo
|
211
|
-
[](https://www.youtube.com/watch?v=SCmDYu_MLQU)
|
212
|
-
|
213
|
-
It shows a exception during a page load. In the console tab of the browsers developer tools, the error message is then expanded and just by clicking
|
214
|
-
on the shown file:line_numer link, the browser shows the ruby source code, where the exception occured.
|
215
|
-
|
216
|
-
#### Source Map Configuration
|
217
125
|
|
218
|
-
|
219
|
-
(These are options for the webpack config, not to be confused with the owl ruby project options further down below)
|
220
|
-
```javascript
|
221
|
-
loader: 'opal-webpack-loader',
|
222
|
-
options: {
|
223
|
-
sourceMap: true
|
224
|
-
}
|
225
|
-
```
|
126
|
+
### Source Maps
|
226
127
|
|
227
|
-
|
128
|
+
[Source Maps](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/source_maps.md)
|
228
129
|
|
229
|
-
Also source maps must be enabled in webpack. See [webpack devtool configuration](https://webpack.js.org/configuration/devtool).
|
230
130
|
### Hot Module Reloading
|
231
|
-
|
232
|
-
#### HMR Demo
|
233
|
-
|
234
|
-
[](https://www.youtube.com/watch?v=igF3cUsZrAQ)
|
235
|
-
|
236
|
-
(Recommended to watch in FullHD)
|
237
|
-
|
238
|
-
#### HMR and Ruby
|
239
|
-
|
240
|
-
When a module uses method aliasing and is reloaded, the aliases are applied again, which may lead to a endless recursion of method calls of
|
241
|
-
the aliased method once called after hot reloading.
|
242
|
-
To prevent that, the alias should be conditional, only be applied if the alias has not been applied before. Or alternatively the original
|
243
|
-
method must be restored before aliasing it again.
|
244
|
-
Because gems are not hot reloaded, this is not a issue for imported gems, but must be taken care of within the projects code.
|
245
|
-
|
246
|
-
Also it must be considered, that other code, which without hot reloading would only execute once during the programs life cycle, possibly will
|
247
|
-
execute many times when hot reloaded. "initialization code" should be guarded to prevent it from executing many times.
|
248
|
-
|
249
|
-
#### HMR Configuration
|
250
|
-
|
251
|
-
The opal-webpack-loader for webpack supports the following options to enable HMR:
|
252
|
-
(These are options for the webpack config, not to be confused with the owl ruby project options further down below)
|
253
|
-
```javascript
|
254
|
-
loader: 'opal-webpack-loader',
|
255
|
-
options: {
|
256
|
-
hmr: true,
|
257
|
-
hmrHook: 'global.Opal.ViewJS["$force_update!"]();'
|
258
|
-
}
|
259
|
-
```
|
260
|
-
|
261
|
-
- `hmr` : enable (`true`) or disable (`false`) hot module reloading. Optional, default: `false`
|
262
|
-
- `hmrHook` : A javascript expression as string which will be executed after the new code has been loaded.
|
263
|
-
Useful to trigger a render or update for React or ViewJS projects.
|
264
|
-
|
265
|
-
Note: HMR works only for files within the project tree. Files outside the project tree are not hot reloaded.
|
131
|
+
[Hot Module Reloading](https://github.com/isomorfeus/opal-webpack-loader/blob/master/docs/hot_module_reloading.md)
|
266
132
|
|
267
133
|
### Opal Load Path
|
268
134
|
The projects directory for opal ruby files must be in the opal load path. This is done in the initializer for rails apps in
|
@@ -336,5 +202,8 @@ OpalWebpackLoader.use_manifest = false
|
|
336
202
|
OpalWebpackLoader.manifest_path = File.join(Dir.getwd, 'public', 'assets', 'manifest.json') # doesn't matter, not used
|
337
203
|
OpalWebpackLoader.client_asset_path = 'http://localhost:3035/assets/'
|
338
204
|
```
|
339
|
-
|
340
|
-
|
205
|
+
|
206
|
+
### Tests
|
207
|
+
- clone the repo
|
208
|
+
- `bundle install`
|
209
|
+
- `bundle exec rspec`
|
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.7.
|
4
|
+
version: 0.7.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Biedermann
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: opal
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
33
|
+
version: 3.7.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 3.
|
40
|
+
version: 3.7.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: thor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,14 +86,14 @@ dependencies:
|
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version: 5.2.
|
89
|
+
version: 5.2.3
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version: 5.2.
|
96
|
+
version: 5.2.3
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: roda
|
99
99
|
requirement: !ruby/object:Gem::Requirement
|