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

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

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 文件,其中包含以下代码:

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

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

  1. const PurgecssPlugin = require('purgecss-webpack-plugin')
  2. const glob = require('glob-all')
  3. const path = require('path')
  4. class TailwindExtractor {
  5. static extract (content) {
  6. return content.match(/[A-z0-9-:/]+/g) || []
  7. }
  8. }

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

  1. build: {
  2. extend (config, ctx) {
  3. config.plugins.push(
  4. new PurgecssPlugin({
  5. whitelist: ['html', 'body'],
  6. paths: glob.sync([
  7. path.join(__dirname, 'components/**/*.vue'),
  8. path.join(__dirname, 'layouts/**/*.vue'),
  9. path.join(__dirname, 'pages/**/*.vue'),
  10. path.join(__dirname, 'plugins/**/*.vue')
  11. ]),
  12. extractors: [{
  13. extractor: TailwindExtractor,
  14. extensions: ['html', 'js', 'vue']
  15. }]
  16. })
  17. )
  18. }
  19. }
  20. modules: [
  21. '~modules/import-tailwind-config'
  22. ]
英文:

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:

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

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

  1. const PurgecssPlugin = require(&#39;purgecss-webpack-plugin&#39;)
  2. const glob = require(&#39;glob-all&#39;)
  3. const path = require(&#39;path&#39;)
  4. class TailwindExtractor {
  5. static extract (content) {
  6. return content.match(/[A-z0-9-:/]+/g) || []
  7. }
  8. }

As well as this code inside of module.exports

  1. build: {
  2. extend (config, ctx) {
  3. config.plugins.push(
  4. new PurgecssPlugin({
  5. whitelist: [&#39;html&#39;, &#39;body&#39;],
  6. paths: glob.sync([
  7. path.join(__dirname, &#39;components/**/*.vue&#39;),
  8. path.join(__dirname, &#39;layouts/**/*.vue&#39;),
  9. path.join(__dirname, &#39;pages/**/*.vue&#39;),
  10. path.join(__dirname, &#39;plugins/**/*.vue&#39;)
  11. ]),
  12. extractors: [{
  13. extractor: TailwindExtractor,
  14. extensions: [&#39;html&#39;, &#39;js&#39;, &#39;vue&#39;]
  15. }]
  16. })
  17. )
  18. }
  19. }
  20. modules: [
  21. &#39;~modules/import-tailwind-config&#39;
  22. ]

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:

确定