Nuxt.js应用部署到Heroku仅在小屏幕分辨率下具有TailwindCSS的样式。

huangapple go评论68阅读模式
英文:

Nuxt.js app deployed to Heroku only has TailwindCSS's styles for < SM breakpoint

问题

我将我的第一个Nuxt.js应用部署到Heroku... 一切都很顺利,但当我打开应用程序时,我意识到每个.vue文件/组件在SM断点之前都具有TailwindCSS样式。 移动视图很好,但大于SM断点的任何内容都不适用。 我还使用了Purgecss来删除未使用的样式,但不确定是否会导致问题... 有关如何修复这个问题的任何想法吗?

英文:

I deployed my 1st Nuxt.js app to Heroku...Everything went smooth but when I opened the app I realised that every .vue file/component has TailwindCSS styles up untill SM breakpoint. Mobile view is fine, but anything bigger than SM breakpoint is not apllied. I also used Purgecss to remove unused styles but not sure if that can cause the problems... Any ideas on how to fix this?

答案1

得分: 0

我通过找到这个链接 https://github.com/nuxt/nuxt.js/issues/2262 来解决了我的问题。

我创建了 modules 文件夹并添加了 import-tailwind-config.js 文件,其中包含以下代码:

module.exports = function () {
  const tailwindConfig = require('@nuxtjs/tailwindcss')
  this.options.env.tailwind = tailwindConfig
}

nuxt.config.js 中,我在 module.exports 之外添加了以下代码:

const PurgecssPlugin = require('purgecss-webpack-plugin')
const glob = require('glob-all')
const path = require('path')

class TailwindExtractor {
  static extract (content) {
    return content.match(/[A-z0-9-:/]+/g) || []
  }
}

以及在 module.exports 内部添加的这段代码:

build: {
  extend (config, ctx) {
    config.plugins.push(
      new PurgecssPlugin({
        whitelist: ['html', 'body'],
        paths: glob.sync([
          path.join(__dirname, 'components/**/*.vue'),
          path.join(__dirname, 'layouts/**/*.vue'),
          path.join(__dirname, 'pages/**/*.vue'),
          path.join(__dirname, 'plugins/**/*.vue')
        ]),
        extractors: [{
          extractor: TailwindExtractor,
          extensions: ['html', 'js', 'vue']
        }]
      })
    )
  }
}
modules: [
  '~modules/import-tailwind-config'
]
英文:

I fixed my problem just by finding this https://github.com/nuxt/nuxt.js/issues/2262

I created modules folder and added import-tailwind-config.js with the code:

module.exports = function () {
  const tailwindConfig = require(&#39;@nuxtjs/tailwindcss&#39;)
  this.options.env.tailwind = tailwindConfig
}

And inside nuxt.config.js, outside of module.exports I added

const PurgecssPlugin = require(&#39;purgecss-webpack-plugin&#39;)
const glob = require(&#39;glob-all&#39;)
const path = require(&#39;path&#39;)

class TailwindExtractor {
  static extract (content) {
    return content.match(/[A-z0-9-:/]+/g) || []
  }
}

As well as this code inside of module.exports

build: {
    extend (config, ctx) {
      config.plugins.push(
        new PurgecssPlugin({
          whitelist: [&#39;html&#39;, &#39;body&#39;],
          paths: glob.sync([
            path.join(__dirname, &#39;components/**/*.vue&#39;),
            path.join(__dirname, &#39;layouts/**/*.vue&#39;),
            path.join(__dirname, &#39;pages/**/*.vue&#39;),
            path.join(__dirname, &#39;plugins/**/*.vue&#39;)
          ]),
          extractors: [{
            extractor: TailwindExtractor,
            extensions: [&#39;html&#39;, &#39;js&#39;, &#39;vue&#39;]
          }]
        })
      )
    }
  } 
  modules: [
    &#39;~modules/import-tailwind-config&#39;
  ] 

huangapple
  • 本文由 发表于 2020年1月6日 22:02:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/59613477.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定