webpack_native 0.4.2 → 0.5.2
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/install_generator.rb +2 -2
- data/lib/generators/webpack_native/templates/webpack_native/package.json +2 -0
- data/lib/generators/webpack_native/templates/webpack_native/webpack.config.js +35 -9
- data/lib/webpack_native/railtie.rb +3 -1
- data/lib/webpack_native/version.rb +1 -1
- data/lib/webpack_native/webpack_native_helper.rb +94 -7
- 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: c43ea964f3ee6c2e1bf0d48cf266d9fd06c066ab7e61d9a07f1178d5eb177398
|
4
|
+
data.tar.gz: e7c249c8851f04ee278540b4db1a53b3ecf87ef242578b38c12dfd1a0477f7f9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bde4f040a35fafe117007e4dc40aa5fdf5497ba4fe3afb19922f5c617d6fc17aec3c4b168e35d3c7956ecdd223503e379d10d3ff2b37ff0ee5a43cf3edd86b9c
|
7
|
+
data.tar.gz: b08b606119d3578cdabc440385bc7ab1be58c67a796a5fe9335c95625734dbec6c1e996453c984bb51bd3fed13a3f03dd41bbd5966b57d10400ad30cde6be312
|
@@ -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
|
@@ -15,7 +15,9 @@
|
|
15
15
|
"@babel/preset-env": "^7.11.5",
|
16
16
|
"autoprefixer": "^10.0.0",
|
17
17
|
"babel-loader": "^8.1.0",
|
18
|
+
"@gfx/zopfli": "^1.0.15",
|
18
19
|
"clean-webpack-plugin": "^3.0.0",
|
20
|
+
"compression-webpack-plugin": "^6.0.3",
|
19
21
|
"css-loader": "^4.3.0",
|
20
22
|
"file-loader": "^6.1.0",
|
21
23
|
"mini-css-extract-plugin": "^0.11.2",
|
@@ -3,6 +3,8 @@ const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
|
3
3
|
const OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin');
|
4
4
|
const TerserJSPlugin = require('terser-webpack-plugin');
|
5
5
|
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
|
6
|
+
const CompressionPlugin = require('compression-webpack-plugin');
|
7
|
+
const zopfli = require('@gfx/zopfli');
|
6
8
|
const WebpackManifestPlugin = require('webpack-manifest-plugin');
|
7
9
|
const webpack = require('webpack');
|
8
10
|
|
@@ -12,7 +14,7 @@ module.exports = (env, options) => {
|
|
12
14
|
|
13
15
|
return {
|
14
16
|
|
15
|
-
devtool: "cheap-module-eval-source-map",
|
17
|
+
devtool: devMode ? "cheap-module-eval-source-map" : undefined,
|
16
18
|
optimization: {
|
17
19
|
minimizer: [
|
18
20
|
new TerserJSPlugin({}),
|
@@ -23,7 +25,7 @@ module.exports = (env, options) => {
|
|
23
25
|
application: "./src/javascripts/application.js"
|
24
26
|
},
|
25
27
|
output: {
|
26
|
-
filename:
|
28
|
+
filename: '[name]-[contenthash].js',
|
27
29
|
path: path.resolve(__dirname, '../../public/webpack_native')
|
28
30
|
},
|
29
31
|
module: {
|
@@ -55,13 +57,13 @@ module.exports = (env, options) => {
|
|
55
57
|
],
|
56
58
|
},
|
57
59
|
{
|
58
|
-
test: /\.(png|jpg|gif|svg)$/i,
|
60
|
+
test: /\.(png|jpg|jpeg|gif|svg|ttf|woff2|woff|eot|webmanifest)$/i,
|
59
61
|
use: [
|
60
62
|
{
|
61
63
|
loader: 'url-loader',
|
62
64
|
options: {
|
63
|
-
limit:
|
64
|
-
name:
|
65
|
+
limit: false,
|
66
|
+
name: '[name]-[hash:7].[ext]'
|
65
67
|
},
|
66
68
|
},
|
67
69
|
// { loader: 'image-webpack-loader' }
|
@@ -77,9 +79,33 @@ module.exports = (env, options) => {
|
|
77
79
|
new WebpackManifestPlugin(),
|
78
80
|
new CleanWebpackPlugin(),
|
79
81
|
new MiniCssExtractPlugin({
|
80
|
-
filename:
|
82
|
+
filename: '[name]-[contenthash].css',
|
83
|
+
}),
|
84
|
+
// In production, compress static files to .gz (using zopfli) and .br (using brotli) format
|
85
|
+
!devMode && new CompressionPlugin({
|
86
|
+
filename: '[path][base].gz[query]',
|
87
|
+
compressionOptions: {
|
88
|
+
numiterations: 15
|
89
|
+
},
|
90
|
+
algorithm(input, compressionOptions, callback) {
|
91
|
+
return zopfli.gzip(input, compressionOptions, callback);
|
92
|
+
},
|
93
|
+
test: /\.(js|css|html|svg|ico|eot|ttf|otf|map)$/,
|
94
|
+
threshold: 10240,
|
95
|
+
minRatio: 0.8,
|
96
|
+
deleteOriginalAssets: false
|
97
|
+
}),
|
98
|
+
!devMode && new CompressionPlugin({
|
99
|
+
filename: '[path][base].br',
|
100
|
+
algorithm: 'brotliCompress',
|
101
|
+
test: /\.(js|css|html|svg|ico|eot|ttf|otf|map)$/,
|
102
|
+
compressionOptions: {
|
103
|
+
level: 11,
|
104
|
+
},
|
105
|
+
threshold: 10240,
|
106
|
+
minRatio: 0.8,
|
81
107
|
})
|
82
|
-
],
|
108
|
+
].filter(Boolean), // filter(Boolean) to prevent false values when it's devMode
|
83
109
|
// resolve: {
|
84
110
|
// alias: {},
|
85
111
|
// modules: [
|
@@ -89,6 +115,6 @@ module.exports = (env, options) => {
|
|
89
115
|
// ]
|
90
116
|
// }
|
91
117
|
|
92
|
-
}
|
118
|
+
};
|
93
119
|
|
94
|
-
}
|
120
|
+
};
|
@@ -17,7 +17,8 @@ class WebpackNative::Railtie < ::Rails::Railtie
|
|
17
17
|
end
|
18
18
|
|
19
19
|
initializer "webpack_native_set_manifest" do
|
20
|
-
|
20
|
+
|
21
|
+
if Rails.env.production? # on production only
|
21
22
|
|
22
23
|
# create public/webpack_native if it doesn't exist:
|
23
24
|
|
@@ -39,6 +40,7 @@ class WebpackNative::Railtie < ::Rails::Railtie
|
|
39
40
|
Rails.configuration.x.webpack_native.webpack_manifest_file = WebpackNative::WebpackNativeHelper.load_webpack_manifest
|
40
41
|
|
41
42
|
end
|
43
|
+
|
42
44
|
end
|
43
45
|
|
44
46
|
def start_webpack
|
@@ -1,28 +1,115 @@
|
|
1
1
|
module WebpackNative::WebpackNativeHelper
|
2
|
-
|
3
|
-
def
|
2
|
+
|
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)
|
22
37
|
end
|
23
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)
|
45
|
+
end
|
46
|
+
|
47
|
+
# ====== Favicon helpers ======
|
48
|
+
# usage:
|
49
|
+
# <%= webpack_favicons('apple-touch-icon.png', 'favicon-32x32.png', 'favicon-16x16.png') %>
|
50
|
+
# <%= webpack_webmanifest('manifest.webmanifest') %>
|
51
|
+
|
52
|
+
# result:
|
53
|
+
#<link rel="apple-touch-icon" sizes="180x180" href="/webpack_native/apple-touch-icon.png">
|
54
|
+
#<link rel="icon" type="image/png" sizes="32x32" href="/webpack_native/favicon-32x32.png">
|
55
|
+
#<link rel="icon" type="image/png" sizes="16x16" href="/webpack_native/favicon-16x16.png">
|
56
|
+
#<link rel="manifest" href="/webpack_native/site.webmanifest">
|
57
|
+
|
58
|
+
def webpack_favicons(*args)
|
59
|
+
tags = []
|
60
|
+
args.each do |favicon|
|
61
|
+
|
62
|
+
filename = File.basename(favicon, ".*") # exclude the extension
|
63
|
+
ext = File.extname(favicon)
|
64
|
+
|
65
|
+
if ext == '.webmanifest'
|
66
|
+
manifest = favicon
|
67
|
+
html_options = {
|
68
|
+
rel: 'manifest',
|
69
|
+
href: webpack_native_lookup(manifest)
|
70
|
+
}
|
71
|
+
|
72
|
+
else
|
73
|
+
mimetypes = {
|
74
|
+
'.png' => 'image/png',
|
75
|
+
'.jpg' => 'image/jpg',
|
76
|
+
'.jpeg' => 'image/jpeg',
|
77
|
+
'.webp' => 'image/webp',
|
78
|
+
'.tiff' => 'image/tiff',
|
79
|
+
'.svg' => 'image/svg+xml',
|
80
|
+
'.ico' => 'image/x-icon'
|
81
|
+
}
|
82
|
+
|
83
|
+
html_options = {
|
84
|
+
rel: filename == 'apple-touch-icon' ? 'apple-touch-icon' : 'icon',
|
85
|
+
type: mimetypes[ext],
|
86
|
+
href: webpack_native_lookup(favicon)
|
87
|
+
}
|
88
|
+
|
89
|
+
sizes = filename[/(.+)?([0-9]{2,3}x[0-9]{2,3})(.+)?/, 2]
|
90
|
+
|
91
|
+
sizes = '180×180' if filename == 'apple-touch-icon'
|
92
|
+
|
93
|
+
html_options = html_options.merge({sizes: sizes}) unless sizes.nil?
|
94
|
+
|
95
|
+
end
|
96
|
+
|
97
|
+
tags << tag.link(html_options)
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
return tags.join.html_safe
|
102
|
+
|
103
|
+
end
|
104
|
+
|
105
|
+
# ====== End favicon helpers ======
|
106
|
+
|
24
107
|
private
|
25
108
|
|
109
|
+
def webpack_native_lookup(file)
|
110
|
+
"/webpack_native/#{webpack_manifest_file.fetch("#{file}")}"
|
111
|
+
end
|
112
|
+
|
26
113
|
def webpack_manifest_file
|
27
114
|
# 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
115
|
|
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.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- scratchoo
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-13 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!
|