webpack_native 0.3.9 → 0.4.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 898bb9c4f771b2ab8cd955eb1fb4905dae5390fcbb99e4fffc2ff8aa87da841d
4
- data.tar.gz: 9fff199c9312a34abfc2bb9fb762ac3870a657ebeab9b1f7d558abf581654c7e
3
+ metadata.gz: 74b744bdc5f7b9675d782b511e60e8630865466b94fb20d885a9228d425c60f9
4
+ data.tar.gz: 754022a887f2a5381f47d3494f5e81e79dd93ebb624cef512eca3f659eeafc63
5
5
  SHA512:
6
- metadata.gz: dfd7c8b1a9915002b2c837422f78c7985b21775a527ecddc33be4395ffdefbc47f7278f1b2819996a897f396e5302af11b7b3dace092a89a1f4fb513e0dbc472
7
- data.tar.gz: d29a2de898cba30e1e9c3769e57986c7115999a632631a6bb6a3b06cf1da5e779b705ed1831910b25da06c8ade19048d2f12cb02837a63d3b1f95305b241d639
6
+ metadata.gz: eb9ff0c576ae30ea0d83a0abff8ff1d01f4c8fb2272d5ca8f42ee983358dc6262b3194db90651e90dceea1c88ae43f265f37b731013552e58f733a4f85fdf0e9
7
+ data.tar.gz: a46151740f88360538521531b9a434bef767faff6b14605ee36f4d666625651dece5cf3f43467e301167932e8e3ee02c5e04d867860032ef7c4ee3bfa79dd77d
@@ -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 = "<%= webpack_stylesheet_url 'application', media: 'all', 'data-turbolinks-track': 'reload' %>"
22
+ stylesheets_tag = "<%= webpack_stylesheet_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>"
23
23
 
24
- javascripts_tag = "<%= webpack_javascript_url 'application', 'data-turbolinks-track': 'reload' %>"
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: devMode ? '[name].js' : '[name]-[contenthash].js',
28
+ filename: '[name]-[contenthash].js',
27
29
  path: path.resolve(__dirname, '../../public/webpack_native')
28
30
  },
29
31
  module: {
@@ -60,8 +62,8 @@ module.exports = (env, options) => {
60
62
  {
61
63
  loader: 'url-loader',
62
64
  options: {
63
- limit: 8192,
64
- name: devMode ? '[name].[ext]' : '[name]-[hash:7].[ext]'
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: devMode ? '[name].css' : '[name]-[contenthash].css',
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: [
@@ -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
 
@@ -17,14 +18,26 @@ class WebpackNative::Railtie < ::Rails::Railtie
17
18
 
18
19
  initializer "webpack_native_set_manifest" do
19
20
  if Rails.env.production?
20
- manifest_path = "#{Rails.root}/public/webpack_native/manifest.json"
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
+
21
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
22
- if !File.file?(manifest_path)
23
- #FileUtils.touch
31
+
32
+ manifest_path = "#{Rails.root}/public/webpack_native/manifest.json"
33
+
34
+ unless File.file?(manifest_path)
35
+ FileUtils.touch manifest_path
24
36
  File.write manifest_path, "{}"
25
37
  end
26
38
  require_relative 'webpack_native_helper'
27
39
  Rails.configuration.x.webpack_native.webpack_manifest_file = WebpackNative::WebpackNativeHelper.load_webpack_manifest
40
+
28
41
  end
29
42
  end
30
43
 
@@ -1,3 +1,3 @@
1
1
  module WebpackNative
2
- VERSION = "0.3.9"
2
+ VERSION = "0.4.9"
3
3
  end
@@ -1,28 +1,55 @@
1
1
  module WebpackNative::WebpackNativeHelper
2
2
 
3
- def webpack_stylesheet_url(asset, **html_options)
3
+ def webpack_stylesheet_tag(asset, **html_options)
4
4
  html_options = html_options.merge(
5
- href: "/webpack_native/#{webpack_manifest_file.fetch("#{asset}.css")}",
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 webpack_javascript_url(asset, **html_options)
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: "/webpack_native/#{webpack_manifest_file.fetch("#{asset}.js")}"
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 webpack_image_url(file_name, **options)
21
- image_tag("/webpack_native/#{file_name}", **options)
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.3.9
4
+ version: 0.4.9
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-08 00:00:00.000000000 Z
11
+ date: 2020-11-20 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!