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