webpack_native 0.4.7 → 0.5.4
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 +1 -0
- data/lib/generators/webpack_native/templates/webpack_native/package.json +2 -0
- data/lib/generators/webpack_native/templates/webpack_native/src/javascripts/application.js +1 -0
- data/lib/generators/webpack_native/templates/webpack_native/webpack.config.js +55 -8
- data/lib/webpack_native/railtie.rb +3 -1
- data/lib/webpack_native/version.rb +1 -1
- data/lib/webpack_native/webpack_native_helper.rb +61 -1
- 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: d3502e8e87605dd20dea5b8c8509eb8ed95269e5bb0bee23f74c16b0500b988c
|
4
|
+
data.tar.gz: 9586d22e15d5e78f695df50da43c12d6849459e26cc1ead5e1eabfa86f07ef54
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b4b7aa7fe8d78cd9968ae67080e9ec5063b54a6f4edde532d673a5cc8d84ec1cc3508874f0fa145d7852e5db6f81aead923bbcbf15e9f258afc2fd20f189b1c1
|
7
|
+
data.tar.gz: 013a76ebae4470190a87d83c864bdb646f1dcc490527c50249a5695f8f6c33d010a6ec8803c236ff3b53b712cfc15b90ad0f1dcca398bfbca5898b2bf53b67eb
|
@@ -7,6 +7,7 @@ class WebpackNative::DevGenerator < Rails::Generators::Base
|
|
7
7
|
Mutex.new.synchronize do
|
8
8
|
Dir.chdir "#{Rails.root}/app/webpack_native" do
|
9
9
|
Dir.mkdir('src/images') unless Dir.exist?('src/images')
|
10
|
+
Dir.mkdir('src/favicons') unless Dir.exist?('src/favicons')
|
10
11
|
%x{ yarn install }
|
11
12
|
result = %x{ npm run build:dev }
|
12
13
|
puts "\n"
|
@@ -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",
|
@@ -2,6 +2,7 @@
|
|
2
2
|
import '../stylesheets/application.scss';
|
3
3
|
// the following line requires that images folder exists
|
4
4
|
require.context('../images', true, /\.(gif|jpeg|jpg|png|svg)$/i);
|
5
|
+
require.context('../favicons', true);
|
5
6
|
|
6
7
|
require("@rails/ujs").start();
|
7
8
|
require("turbolinks").start();
|
@@ -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,34 @@ 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)$/i,
|
61
|
+
exclude: [
|
62
|
+
path.resolve(__dirname, "src/favicons")
|
63
|
+
],
|
59
64
|
use: [
|
60
65
|
{
|
61
66
|
loader: 'url-loader',
|
62
67
|
options: {
|
63
68
|
limit: false,
|
64
|
-
name:
|
69
|
+
name: '[name]-[hash:7].[ext]'
|
70
|
+
},
|
71
|
+
},
|
72
|
+
// { loader: 'image-webpack-loader' }
|
73
|
+
],
|
74
|
+
},
|
75
|
+
{
|
76
|
+
test: /\.(png|jpg|jpeg|svg|ttf|ico|webmanifest)$/i,
|
77
|
+
exclude: [
|
78
|
+
path.resolve(__dirname, "src/images"),
|
79
|
+
path.resolve(__dirname, 'node_modules')
|
80
|
+
],
|
81
|
+
use: [
|
82
|
+
{
|
83
|
+
loader: 'url-loader',
|
84
|
+
options: {
|
85
|
+
limit: false, //8192,
|
86
|
+
name: '[name].[ext]',
|
87
|
+
outputPath: '../../public'
|
65
88
|
},
|
66
89
|
},
|
67
90
|
// { loader: 'image-webpack-loader' }
|
@@ -77,9 +100,33 @@ module.exports = (env, options) => {
|
|
77
100
|
new WebpackManifestPlugin(),
|
78
101
|
new CleanWebpackPlugin(),
|
79
102
|
new MiniCssExtractPlugin({
|
80
|
-
filename:
|
103
|
+
filename: '[name]-[contenthash].css',
|
104
|
+
}),
|
105
|
+
// In production, compress static files to .gz (using zopfli) and .br (using brotli) format
|
106
|
+
!devMode && new CompressionPlugin({
|
107
|
+
filename: '[path][base].gz[query]',
|
108
|
+
compressionOptions: {
|
109
|
+
numiterations: 15
|
110
|
+
},
|
111
|
+
algorithm(input, compressionOptions, callback) {
|
112
|
+
return zopfli.gzip(input, compressionOptions, callback);
|
113
|
+
},
|
114
|
+
test: /\.(js|css|html|svg|ico|eot|ttf|otf|map)$/,
|
115
|
+
threshold: 10240,
|
116
|
+
minRatio: 0.8,
|
117
|
+
deleteOriginalAssets: false
|
118
|
+
}),
|
119
|
+
!devMode && new CompressionPlugin({
|
120
|
+
filename: '[path][base].br',
|
121
|
+
algorithm: 'brotliCompress',
|
122
|
+
test: /\.(js|css|html|svg|ico|eot|ttf|otf|map)$/,
|
123
|
+
compressionOptions: {
|
124
|
+
level: 11,
|
125
|
+
},
|
126
|
+
threshold: 10240,
|
127
|
+
minRatio: 0.8,
|
81
128
|
})
|
82
|
-
],
|
129
|
+
].filter(Boolean), // filter(Boolean) to prevent false values when it's devMode
|
83
130
|
// resolve: {
|
84
131
|
// alias: {},
|
85
132
|
// modules: [
|
@@ -89,6 +136,6 @@ module.exports = (env, options) => {
|
|
89
136
|
// ]
|
90
137
|
// }
|
91
138
|
|
92
|
-
}
|
139
|
+
};
|
93
140
|
|
94
|
-
}
|
141
|
+
};
|
@@ -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,5 +1,5 @@
|
|
1
1
|
module WebpackNative::WebpackNativeHelper
|
2
|
-
|
2
|
+
|
3
3
|
def webpack_stylesheet_tag(asset, **html_options)
|
4
4
|
html_options = html_options.merge(
|
5
5
|
href: webpack_stylesheet_path(asset),
|
@@ -43,6 +43,66 @@ module WebpackNative::WebpackNativeHelper
|
|
43
43
|
def webpack_image_path(image, **options)
|
44
44
|
image_path(webpack_native_lookup(image), **options)
|
45
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="/apple-touch-icon.png">
|
54
|
+
#<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
|
55
|
+
#<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
|
56
|
+
#<link rel="manifest" href="/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: 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: 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 ======
|
46
106
|
|
47
107
|
private
|
48
108
|
|
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
|
4
|
+
version: 0.5.4
|
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!
|