1

我有一个使用 webpacker 和 tailwind 的 rails 6.1 应用程序。我的页面加载速度测试显示加载速度不佳,并建议“减少未使用的 JavaScript”。旁注:它还建议“减少未使用的 CSS”。所以清除似乎不起作用。但是在我执行页面加载速度测试的页面上,甚至没有使用chartkick/chart.js。所以看起来它正在加载每个 JS 库,尽管它甚至没有在页面上使用。

这是我的 packs/application.js 文件:

// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.

import Rails from "@rails/ujs"
import Turbolinks from "turbolinks"
import * as ActiveStorage from "@rails/activestorage"
import "channels"
import "chartkick/chart.js"
import ahoy from "ahoy.js"
import { initMapbox } from '../packs/init_mapbox'

require("stylesheets/application.scss")
require("../stylesheets/components/pagination.scss")
require("../stylesheets/components/vacancy_description.scss")


Rails.start()
Turbolinks.start()
ActiveStorage.start()

document.addEventListener('turbolinks:load', () => {
  initMapbox();
})

这是我的 tailwind.config.js 文件:

const colors = require('tailwindcss/colors')

module.exports = {
  purge: {
    enabled: process.env.NODE_ENV === "production"
    content: ['./app/views/**/*.html.erb', './app/javascript/**/*.js',],
  },

  darkMode: false, // or 'media' or 'class'
  theme: {
    colors: {
      transparent: 'transparent',
      current: 'currentColor',
      black: colors.black,
      white: colors.white,
      gray: colors.trueGray,
      indigo: colors.indigo,
      red: colors.rose,
      yellow: colors.amber,
      green: colors.emerald
    },
    extend: {},
  },
  variants: {
    extend: {},
  },
  plugins: [],
}

希望有人能帮忙!

4

0 回答 0