Как визуализировать файлы JavaScript в конце тела в реагировать + веб-пакет? - PullRequest
0 голосов
/ 04 октября 2018

Я создал SPA по реактивам + веб-пакеты и протестировал его в «Google pagespeed insights».У меня есть только один файл main.js, и он отображается в начале. вот результат

как мне решить эту проблему?

это моя конфигурация webpack:

const HtmlWebPackPlugin = require("html-webpack-plugin");
const UglifyJsPlugin = require('uglifyjs-webpack-plugin');
module.exports = {
  optimization: {
    minimizer: [new UglifyJsPlugin({
      cache: true,
      parallel: true,
      // uglifyOptions: {
      //   compress: false,
      //   ecma: 6,
      //   mangle: true
      // },
    })]
  },
  module: {
    rules: [
      {
        test: /\.js$/,
        exclude: /node_modules/,
        use: {
          loader: "babel-loader?cacheDirectory=true"
        }
      },
      {
        test:/\.css$/,
        use:['style-loader','css-loader']
      },
      {
        test: /\.(ttf|eot|woff|woff2)$/,
        use: {
          loader: "file-loader",
        },
      },
      {
        test: /\.(png|jpg|svg)$/,  
        use: [{
            loader: 'file-loader',
            options: { 
                limit: 8000, // Convert images < 8kb to base64 strings
                name: 'static/[name].[ext]'
            } 
        }]
    },
      {
        test: /\.html$/,
        use: [
          {
            loader: "html-loader"
          }
        ]
      }
    ]
  },
  plugins: [
    new HtmlWebPackPlugin({
      template: "./src/index.html",
      filename: "./index.html"
    })
  ]
};

как я могу сказать webpack загрузитьфайл JS в конце тела?или любое другое решение, которое помогает решить эту проблему?

и мои файлы index.html и index.js настолько просты.

index.html:

<!DOCTYPE html>
<html lang="fa">
<head>
    <meta charset="utf-8">
    <meta
        name="viewport"
        content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no"
    />
    <link rel="shortcut icon" type="image/png" href="static/favicon.png"/>
    <title>آسان یادبگیر</title>
</head>
<body dir="rtl">
    <div id="mainDiv">
    </div>
</body>
</html>

index.js:

import React from "react";
import ReactDOM from "react-dom";
import Theme from './styles/theme';
import { MuiThemeProvider} from '@material-ui/core/styles';
import CssBaseline from '@material-ui/core/CssBaseline';
import './styles/style.css';
import RTL from './jss-rtl';
import './static/favicon.png'
import App from './app';

ReactDOM.render(
    <RTL>
        <MuiThemeProvider theme={Theme}>
        <React.Fragment>
            <CssBaseline/>
            <App/>
        </React.Fragment>
        </MuiThemeProvider>
    </RTL>,
    document.getElementById('mainDiv'));

здесь вопрос Google:

Eliminate render-blocking JavaScript and CSS in above-the-fold content: None of the above-the-fold content on your page could be rendered without waiting for the following resources to load. Try to defer or asynchronously load blocking resources, or inline the critical portions of those resources directly in the HTML.

Снять блокировку рендеринга JavaScript: https://asanyadbegir.com/main.js

1 Ответ

0 голосов
/ 05 октября 2018

Я добавил 'defer = "true"' в файл dist / index.html, и он стал лучше (на 50% лучше).затем с помощью React-Loadable я разделил мои файлы.теперь все дело в файле.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...