Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tailwind Config #2

Closed
1 task done
joshuapease opened this issue May 9, 2024 · 1 comment
Closed
1 task done

Tailwind Config #2

joshuapease opened this issue May 9, 2024 · 1 comment

Comments

@joshuapease
Copy link
Contributor

joshuapease commented May 9, 2024

@maxfenton
Copy link
Contributor

maxfenton commented May 10, 2024

Do we have a vite.php and craft-vite plugin in this?

Parallel development on the Ad Council craft-starter has these:

tailwind.config.mjs

// const defaultTheme = require("tailwindcss/defaultTheme");

module.exports = {
  content: [
    "./templates/**/*.twig",
    "./src/js/**/*.js"
  ],
  theme: {
    extend: {},
  },
}

vite.config.js

import ViteRestart from "vite-plugin-restart";
import ViteHmrPublicCopy from "vite-plugin-hmr-public-copy"; // Note: this is not yet updated for Vite 5
// See: https://github.com/davidwebca/vite-plugin-hmr-public-copy/pull/2

export default ({command}) => ({
  base: command === 'serve' ? '' : '/dist/',
  build: {
    manifest: true,
    outDir: './web/dist/',
    rollupOptions: {
      input: {
        app: './src/js/app.js',
        css: './src/css/app.css'
      },
      output: {
        sourcemap: false
      }
    }
  },
  plugins: [
    ViteRestart({
      reload: [
        './templates/**/*'
      ]
    }),
    ViteHmrPublicCopy({
      copy: true,
      copyAtStart: true
    }),
  ],
  publicDir: 'src/public',
  server: {
    fs: {
      strict: false
    },
    host: '0.0.0.0',
    origin: 'http://localhost:3000',
    port: 3000,
    strictPort: true,
  }
});

postcss.config.mjs

module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
    'postcss-pxtorem': {
      rootValue: 16,
      unitPrecision: 5,
      propList: [
        'font', 'font-size', 'line-height', 'letter-spacing',
        'border*',
        'background*',
        'grid*',
        'top', 'left', 'bottom', 'right', 'inset',
        'width', 'height',
        'margin*', 'padding*', 'max-*', 'min-*', 'gap*'
      ],
      selectorBlackList: [],
      replace: true,
      mediaQuery: true,
      minPixelValue: 0,
      exclude: /node_modules/i
    }, // Converts units to rems (defaults to only font properties @ 16px base size)
    ...(process.env.NODE_ENV === 'production' ? {cssnano: {}} : {})
  },
}

config/vite.php

<?php

use craft\helpers\App;

$host = Craft::$app->getRequest()->getIsConsoleRequest() === false
    ? Craft::$app->getRequest()->getHostInfo()
    : App::env('PRIMARY_SITE_URL');

$isHttps = parse_url($host)['scheme'] === 'https';
$httpPort = '3000'; // Note: changing this to 3001 results in unstyled contents
$httpsPort = '3000'; // Note: changing this to 3001 causes `ERR_SSL_PROTOCOL_ERROR`

return [
    'useDevServer' => App::env('ENVIRONMENT') === 'dev' || App::env('CRAFT_ENVIRONMENT') === 'dev',
    'manifestPath' => '@webroot/dist/manifest.json',
    'devServerPublic' => $host . ':' . ($isHttps ? $httpsPort : $httpPort),
    'serverPublic' => '/dist/', // App::env('PRIMARY_SITE_URL') . '/dist/' can conflict with multisite
    'errorEntry' => '',
    'cacheKeySuffix' => '',
    'devServerInternal' => "http://localhost:{$httpPort}",
    'checkDevServer' => true,
    'includeReactRefreshShim' => false,
    'includeModulePreloadShim' => false,
];

config/blitz.php

<?php
/**
 * @copyright Copyright (c) PutYourLightsOn
 */

/**
 * Blitz config.php
 *
 * v4 reference:
 * https://github.com/putyourlightson/craft-blitz/blob/v4/src/config.php
 */

use craft\helpers\App;

return [
    '*' => [
        'debug' => false,

        // Cache if devMode is not enabled
        'cachingEnabled' => !App::devMode(),

        // Automatically expire cache entries when elements are updated in Craft
        'clearCacheAutomatically' => true,

        // Determines when and how the cache should be refreshed.
        // - `0`: Expire the cache, regenerate manually
        // - `1`: Clear the cache, regenerate manually or organically
        // - `2`: Expire the cache and regenerate in a queue job
        // - `3`: Clear the cache and regenerate in a queue job
        'refreshMode' => 1, // 1 or 3 work best, depending on the size of the site

        // Does the site have a search page?
        // Do not cache URLs with query strings
        // Alternatively: set this to `1` and exclude the search results page from `includedUriPatterns`
        'queryStringCaching' => 0,

        // Cache all pages by default
        'includedUriPatterns' => [
            [
                'siteId' => '',
                'uriPattern' => '.*',
            ],
        ],

        // Hide hints by default
        'hintsEnabled' => false,

        // Append "cached on" comment only
        // Note: Cloudflare optimization removes HTML comments
        'outputComments' => 2,
        'sendPoweredByHeader' => true,

        // Default to FileStorage
        'cacheStorageType' => 'putyourlightson\blitz\drivers\storage\FileStorage',

        // Set the default `cacheGeneratorType` for public sites without htaccess auth:
        'cacheGeneratorType' => 'putyourlightson\blitz\drivers\generators\HttpGenerator',

        // Does the site have SEOmatic?
        'integrations' => [
            'putyourlightson\blitz\drivers\integrations\SeomaticIntegration',
        ],
    ],
    'dev' => [
        // Change to true to cache locally to `storage/cache/blitz`
        // 'cachingEnabled' => false,
        'debug' => true,

        'hintsEnabled' => true,

        // `cacheGeneratorType` for local site that cannot be accessed publicly
        'cacheGeneratorType' => 'putyourlightson\blitz\drivers\generators\LocalGenerator',

        // Optional additional control and testing
        //  'cacheStorageSettings' => [
        //      'folderPath' => '@storage/cache/blitz',
        //      'compressCachedValues' => false,
        //      'countCachedFiles' => true,
        //  ],
    ],
    'staging' => [
        'debug' => true,

        // Does the site have htaccess auth?
        // 'cacheGeneratorType' => 'putyourlightson\blitz\drivers\generators\LocalGenerator', // Because site cannot be accessed publicly
    ],
    'production' => [
        // Does the site have htaccess auth?
        // 'cacheGeneratorType' => 'putyourlightson\blitz\drivers\generators\LocalGenerator', // Because site cannot be accessed publicly
    ],
];

@maxfenton maxfenton mentioned this issue May 10, 2024
8 tasks
joshuapease added a commit that referenced this issue May 15, 2024
joshuapease added a commit that referenced this issue May 15, 2024
joshuapease added a commit that referenced this issue May 15, 2024
joshuapease added a commit that referenced this issue May 16, 2024
* [#2] Install Tailwind / PostCSS

* [#2] Add `postcss-pxtorem`

* [#2] Add `cssnano` for production builds

* [#2] Feedback: Wrap all css in `@layer base`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants