webpack_native 0.3.7 → 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/webpack_native/dev_generator.rb +2 -0
- data/lib/generators/webpack_native/install_generator.rb +2 -2
- data/lib/generators/webpack_native/prod_generator.rb +1 -0
- data/lib/generators/webpack_native/templates/webpack_native/webpack.config.js +1 -1
- data/lib/webpack_native/railtie.rb +24 -3
- data/lib/webpack_native/version.rb +1 -1
- data/lib/webpack_native/webpack_native_helper.rb +33 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 80686b5e334f35311ea0c314897a32d9827ce0a431614abefe97508dbe9f7b21
|
4
|
+
data.tar.gz: 11fc48dca370fb6e185ca1addf6bbe7df0d0248719ab86746ee4c908e9c2564a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7a60e3289035818851216ac3c019bb732e3490c6b59a5d72d26f5bad176db90e04a96818df8042c352513a82d8e26e24ccdc09218a5b4f7e2723f4aafa29480e
|
7
|
+
data.tar.gz: 9605224ecf3d0bde417c28670636021d78b58372bb5120e8241ffcf3b1079afb6f2fd5efa7dd61180df5952d86fdba2ac35820afa774ca1b7daab38db600078c
|
@@ -6,6 +6,8 @@ class WebpackNative::DevGenerator < Rails::Generators::Base
|
|
6
6
|
|
7
7
|
Mutex.new.synchronize do
|
8
8
|
Dir.chdir "#{Rails.root}/app/webpack_native" do
|
9
|
+
Dir.mkdir('src/images') unless Dir.exist?('src/images')
|
10
|
+
%x{ yarn install }
|
9
11
|
result = %x{ npm run build:dev }
|
10
12
|
puts "\n"
|
11
13
|
puts result
|
@@ -19,9 +19,9 @@ class WebpackNative::InstallGenerator < Rails::Generators::Base
|
|
19
19
|
def inject_stylesheets_and_javascript_tags
|
20
20
|
application_layout = "#{Rails.root}/app/views/layouts/application.html.erb"
|
21
21
|
|
22
|
-
stylesheets_tag = "<%=
|
22
|
+
stylesheets_tag = "<%= webpack_stylesheet_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>"
|
23
23
|
|
24
|
-
javascripts_tag = "<%=
|
24
|
+
javascripts_tag = "<%= webpack_javascript_tag 'application', 'data-turbolinks-track': 'reload' %>"
|
25
25
|
|
26
26
|
inject_into_file application_layout, "\n\t\t#{stylesheets_tag}\n\t\t#{javascripts_tag}\n", :before => '</head>'
|
27
27
|
end
|
@@ -6,6 +6,7 @@ class WebpackNative::ProdGenerator < Rails::Generators::Base
|
|
6
6
|
|
7
7
|
Mutex.new.synchronize do
|
8
8
|
Dir.chdir "#{Rails.root}/app/webpack_native" do
|
9
|
+
Dir.mkdir('src/images') unless Dir.exist?('src/images')
|
9
10
|
%x{ yarn install }
|
10
11
|
result = %x{ npm run build:prod }
|
11
12
|
puts "\n"
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'rails'
|
2
2
|
require "open3"
|
3
|
+
require "fileutils"
|
3
4
|
|
4
5
|
class WebpackNative::Railtie < ::Rails::Railtie
|
5
6
|
|
@@ -7,16 +8,36 @@ class WebpackNative::Railtie < ::Rails::Railtie
|
|
7
8
|
WebpackNative.logger = ActiveSupport::Logger.new(STDOUT)
|
8
9
|
end
|
9
10
|
|
11
|
+
# Zeitwerk raise an error: set_autoloads_in_dir': wrong constant name Path-dirname inferred by Module from directory (Zeitwerk::NameError) ---> app/webpack_native/node_modules/path-dirname
|
12
|
+
# to prevent Zeitwerk from eager loading webpack_native folder we use this:
|
13
|
+
initializer "zeitwerk_prevent_loading_webpack_native" do
|
14
|
+
if Rails.autoloaders.zeitwerk_enabled?
|
15
|
+
Rails.autoloaders.main.ignore(Rails.root.join('app/webpack_native'))
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
10
19
|
initializer "webpack_native_set_manifest" do
|
11
20
|
if Rails.env.production?
|
12
|
-
|
21
|
+
|
22
|
+
# create public/webpack_native if it doesn't exist:
|
23
|
+
|
24
|
+
webpack_native_folder = "#{Rails.root}/public/webpack_native"
|
25
|
+
|
26
|
+
unless File.directory?(webpack_native_folder)
|
27
|
+
FileUtils.mkdir_p(webpack_native_folder)
|
28
|
+
end
|
29
|
+
|
13
30
|
# create manifest.json file if it doesn't exist with an empty json {} to prevent raising error in WebpackNativeHelper.load_webpack_manifest if a restart of a service happen (i.e delayed_job restart) that causes rails to load
|
14
|
-
|
15
|
-
|
31
|
+
|
32
|
+
manifest_path = "#{Rails.root}/public/webpack_native/manifest.json"
|
33
|
+
|
34
|
+
unless File.file?(manifest_path)
|
35
|
+
FileUtils.touch manifest_path
|
16
36
|
File.write manifest_path, "{}"
|
17
37
|
end
|
18
38
|
require_relative 'webpack_native_helper'
|
19
39
|
Rails.configuration.x.webpack_native.webpack_manifest_file = WebpackNative::WebpackNativeHelper.load_webpack_manifest
|
40
|
+
|
20
41
|
end
|
21
42
|
end
|
22
43
|
|
@@ -1,28 +1,55 @@
|
|
1
1
|
module WebpackNative::WebpackNativeHelper
|
2
2
|
|
3
|
-
def
|
3
|
+
def webpack_stylesheet_tag(asset, **html_options)
|
4
4
|
html_options = html_options.merge(
|
5
|
-
href:
|
5
|
+
href: webpack_stylesheet_path(asset),
|
6
6
|
rel: "stylesheet"
|
7
7
|
)
|
8
8
|
tag.link(html_options).html_safe
|
9
9
|
end
|
10
10
|
|
11
|
-
def
|
11
|
+
def webpack_stylesheet_path(asset, **options)
|
12
|
+
path_to_asset(webpack_native_lookup("#{asset.gsub('.css', '')}.css"), options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def webpack_stylesheet_url(asset, **options)
|
16
|
+
url_to_asset(webpack_native_lookup("#{asset.gsub('.css', '')}.css"), options)
|
17
|
+
end
|
18
|
+
|
19
|
+
def webpack_javascript_tag(asset, **html_options)
|
12
20
|
html_options = html_options.merge(
|
13
21
|
type: "text/javascript",
|
14
|
-
src:
|
22
|
+
src: webpack_javascript_path(asset)
|
15
23
|
)
|
16
24
|
content_tag("script".freeze, nil, html_options).html_safe
|
17
25
|
# or tag.script(html_options).html_safe
|
18
26
|
end
|
19
27
|
|
20
|
-
def
|
21
|
-
|
28
|
+
def webpack_javascript_url(asset, **options)
|
29
|
+
url_to_asset(webpack_native_lookup("#{asset.gsub('.js', '')}.js"), options)
|
30
|
+
end
|
31
|
+
def webpack_javascript_path(asset, **options)
|
32
|
+
path_to_asset(webpack_native_lookup("#{asset.gsub('.js', '')}.js"), options)
|
33
|
+
end
|
34
|
+
|
35
|
+
def webpack_image_tag(image, **options)
|
36
|
+
image_tag(webpack_native_lookup(image), **options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def webpack_image_url(image, **options)
|
40
|
+
image_url(webpack_native_lookup(image), **options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def webpack_image_path(image, **options)
|
44
|
+
image_path(webpack_native_lookup(image), **options)
|
22
45
|
end
|
23
46
|
|
24
47
|
private
|
25
48
|
|
49
|
+
def webpack_native_lookup(file)
|
50
|
+
"/webpack_native/#{webpack_manifest_file.fetch("#{file}")}"
|
51
|
+
end
|
52
|
+
|
26
53
|
def webpack_manifest_file
|
27
54
|
# in production, webpack_manifest_file is initialized in railtie.rb file to load one time only, while in development we call load_webpack_manifest on each new request
|
28
55
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: webpack_native
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- scratchoo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Use vanilla webpack to manage your assets efficiently, no webpacker or
|
14
14
|
asset pipeline anymore!
|