TailwindCSS / PurgeCSS whitelist not working - javascript

I can't seem to get PurgeCSS to whitelist classes I use dynamically in the CMS.
Here are my config files:
/* postcss.config.js */
const purgecss = require('#fullhuman/postcss-purgecss')
module.exports = {
plugins: [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
require('postcss-nested'), // or require('postcss-nesting')
purgecss({
content: [
'**/*.twig',
],
defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || [],
options: {
whitelist: [
'md:w-1/3',
],
},
})
]
}
/* tailwind.config.js */
const plugin = require('tailwindcss/plugin')
module.exports = {
theme: {
container: {
center: true,
},
extend: {
fontSize: {
'9xl': '10rem',
},
fontFamily: {
'sans': ['Roboto', 'system-ui'],
},
lineHeight: {
'11': '2.75rem',
'12': '3rem',
'14': '3.5rem',
}
},
},
variants: {
extend: {
borderColor: ['focus-visible'],
opacity: ['disabled'],
}
},
}
Tried various solutions I found, but nothing seem to do the trick, it keeps purging the classes I add to the whitelist. Any suggestions anyone?

I was using the wrong option name, it had to be safelist instead of whitelist.

As of today, I had to use the following code to safelist specific classes:
I used safelist on multiple classes I was using with random heights passed through React components as props.
module.exports = {
content: ['./src/**/*.{js,jsx,ts,tsx}'],
safelist: [
{
pattern:
/h-(1|2|3|4)/,
},
{
pattern:
/w-(1|2|3|4)/,
},
],
theme: {},
plugins: [],
};

Related

firebase ESLINT questions

I am having some small issues with ESlint
here is the code snip:
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
quotes: ["error", "double"],
},
parserOptions: {
ecmaVersion: 8, // or 2017
},
};
questions::
I have a max of 80 characters per line, how do I remove this?
I can't use let to run a for loop, it always changes to const
for ( let userData in chatUsersData) {
if ( userData["userId"]!=senderUserId) {
receiverUserId = userData["userId"];
}
}

Nuxt/ESLint - Parsing error: Must use import to load ES Module

I am using Nuxt 2.15.7 in VS Code, using Node version 14.17.1 and the eslint extension.
The problem
I started seeing a red squiggly line under the 1st character of every file. When hovering over it, this is the error I see:
require() of ES modules is not supported.
require() of C:\Users\SR Gears\Documents\work\my-website\node_modules\eslint\node_modules\eslint-scope\lib\definition.js
from C:\Users\SR Gears\Documents\work\my-website\node_modules\babel-eslint\lib\require-from-eslint.js
is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename definition.js to end in .cjs,
change the requiring code to use import(),
or remove "type": "module" from
C:\Users\SR Gears\Documents\work\my-website\node_modules\eslint\node_modules\eslint-scope\package.json.eslint
What I have tried so far
First, I tried renaming the appropriate files as listed above in the error, and restarting the eslint server, but the error remains.
So, I went over to the eslint extension in VS Code and read the following:
The approval flow to allow the execution of a ESLint library got reworked. Its initial experience is now as follows:
- no modal dialog is shown when the ESLint extension tries to load an ESLint library for the first time and an approval is necessary. Instead the ESLint status bar item changes to ESLint status icon indicating that the execution is currently block.
- if the active text editor content would be validated using ESLint, a problem at the top of the file is shown in addition.
The execution of the ESLint library can be denied or approved using the following gestures:
- clicking on the status bar icon
- using the quick fix for the corresponding ESLint problem
- executing the command ESLint: Manage Library Execution from the command palette
Okay, so I tried the above suggestions:
clicking on the status bar icon (it isn't there in my status bar)
using the quick fix for the corresponding ESLint problem (shows no quick fix available)
executing the command ESLint: Manage Library Execution from the command palette (I get a message that this request is unknown)
Potential Fix with error
So, I navigated over to eslintrc.js I hovered over module.exports = { on line 1, and got the lightbulb icon show. The Quick Fix says Convert to ES6 module. When I click this, the file is updated. All variable keys within the options are updated to have export in front of them. This does remove the error line at the top of the files, but gives a new error for export const extends: [] variable:
'extends' is not allowed as a variable declaration name.. My eslintrc.js file (before updating to ES6 module) is here:
eslintrc.js
module.exports = {
root: true,
env: {
browser: true,
node: true
},
parserOptions: {
parser: 'babel-eslint'
},
extends: [
'plugin:nuxt/recommended',
'plugin:vue/recommended',
'eslint:recommended',
// 'prettier/vue',
'plugin:prettier/recommended'
],
globals: {
$nuxt: true,
page: true,
browser: true,
context: true,
jestPuppeteer: true
},
plugins: ['nuxt', 'vue', 'prettier'],
rules: {
'new-cap': 'off',
'no-console': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
'vue/component-name-in-template-casing': ['off', 'PascalCase'],
'vue/attribute-hyphenation': ['warn'],
'vue/no-unused-components': ['warn'],
'vue/html-self-closing': [
'error',
{
html: {
void: 'any',
normal: 'always',
component: 'always'
},
svg: 'always',
math: 'always'
}
],
'vue/max-attributes-per-line': 'off',
'vue/no-v-html': 'off',
'no-unused-vars': ['warn'],
eqeqeq: ['warn'],
'no-lonely-if': ['warn'],
'require-await': ['warn'],
'handle-callback-err': ['warn'],
'space-before-function-paren': 0
}
}
One other potential fix - but not for me
For anyone else with the same errors, there is a fix here, (that also worked for me): ESlint - Error: Must use import to load ES Module `
I cannot use this fix though, as my team suggested that adjusting babel settings can create errors elsewhere.
As that cannot be my solution, would anyone else know how to manage this error? Here is my nuxt.config file. If you need to see something else, I can update it here too.
nuxt.config
import { storyblokConfig, localeMessages } from './config'
export default {
// Target: https://go.nuxtjs.dev/config-target
target: 'server',
ssr: true,
dev: false,
// Global page headers: https://go.nuxtjs.dev/config-head
head: {
title: '',
htmlAttrs: {
lang: 'en'
},
meta: [
{ charset: 'utf-8' },
{ name: 'viewport', content: 'width=device-width, initial-scale=1' },
{ hid: 'description', name: 'description', content: '' }
],
link: [
{
rel: 'icon',
sizes: '192x192',
href: '/favicon/android-chrome-192x192.png'
},
{
rel: 'icon',
sizes: '512x512',
href: '/favicon/android-chrome-512x512.png'
},
{
rel: 'apple-touch-icon',
sizes: '180x180',
href: '/favicon/apple-touch-icon.png'
},
{ rel: 'icon', sizes: '16x16', href: '/favicon/favicon-16x16.png' },
{ rel: 'icon', sizes: '32x32', href: '/favicon/favicon-32x32.png' },
{ rel: 'icon', type: 'image/x-icon', href: '/favicon/favicon.ico' },
{ rel: 'manifest', href: '/favicon/site.webmanifest' }
]
},
// Global CSS: https://go.nuxtjs.dev/config-css
css: [
'~assets/styles/main.css',
'~assets/fonts/fabrikat/stylesheet.css',
'~assets/fonts/pangram/stylesheet.css'
],
// Plugins to run before rendering page: https://go.nuxtjs.dev/config-plugins
plugins: [
{ src: '~/plugins/logger.js' },
{ src: '~/plugins/nujek-ui.js' },
{ src: '~/plugins/validation.js' },
{ src: '~/plugins/utils.js' },
{ src: '~/plugins/vue-tailwind.js' },
{ src: '~/plugins/rich-text-renderer.js' },
{ src: '~/plugins/defaultButton.js' }
],
// Auto import components: https://go.nuxtjs.dev/config-components
components: [{ path: '~/components', pathPrefix: false, prefix: '' }],
// Modules for dev and build (recommended): https://go.nuxtjs.dev/config-modules
buildModules: [
// https://go.nuxtjs.dev/eslint
'#nuxtjs/eslint-module',
// https://go.nuxtjs.dev/tailwindcss
'#nuxtjs/tailwindcss',
'#nuxtjs/composition-api/module',
'#nuxtjs/tailwindcss',
[
'#nujek/ui',
{
withConsole: true,
storeTemplates: {
nav: true
}
}
],
['#nujek/storyblok']
],
nujekStoryblok: {
storyblokConfig,
withConsole: false,
debug: true
},
// Modules: https://go.nuxtjs.dev/config-modules
modules: ['nuxt-i18n', '~/modules/nuxt-storyblok-queries/lib/module.js'],
storyblokQueries: storyblokConfig,
i18n: {
locales: [
{
code: 'en',
iso: 'en-US'
},
{
code: 'de',
iso: 'de-DE'
}
],
defaultLocale: 'de',
strategy: 'prefix_except_default',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
redirectOn: 'root'
},
vueI18n: {
fallbackLocale: 'de',
silentTranslationWarn: true,
messages: localeMessages
},
vuex: {
syncLocale: true,
syncMessages: true
}
},
// publicRuntimeConfig: {
// accessToken: process.env.SB_CLIENT_ACCESS_TOKEN
// },
// Build Configuration: https://go.nuxtjs.dev/config-build
build: {
transpile: ['vee-validate', '#marvr/storyblok-rich-text-vue-renderer']
}
}
c:/users/user/AppData/Roaming/Code/User/settings.json
{
"workbench.colorTheme": "Default Dark+",
"terminal.integrated.defaultProfile.windows": "Git Bash",
"editor.wordWrap": "on",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
},
"eslint.validate": ["javascript"]
}
I met this error today on a fresh installation of nuxt.
It would npm run dev fine on the first time, but whenever I changed a file, the hot reloading would give an eslint error, as if trying to lint my eslint files.
I solved it by updating Nodejs and npm to their latest version and creating a new nuxt app.
It's probably not the answer you've been looking for, but maybe it will help others.

Problem with sitemap generation in Gatsby js

I'm having a problem with creating a sitemap for my website.
this is gatsby-config.js content :
module.exports = {
siteMetadata: {
siteUrl: `https://www.mywebsite.com`,
},
plugins: [
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images/`,
},
},
{
resolve: 'gatsby-plugin-sitemap',
options: {
excludes: [],
query: `
{
site {
siteMetadata {
siteUrl
}
}
allSitePage {
nodes {
path
}
}
}`,
serialize : ({site,allSitePage}) =>
allSitePage.nodes.map(node => { // this is line 32
return {
url: `${site.siteMetadata.siteUrl}${node.path}`,
changefreq: `never`,
priority: 0.5,
}
})
},
},
'gatsby-plugin-react-helmet',
`gatsby-plugin-image`,
`gatsby-plugin-sharp`,
],
}
I get this error when I want to build the project :
note: when I don't add options like this:
module.exports = {
siteMetadata: {
siteUrl: `https://www.mywebsite.com`,
},
plugins: [
{
resolve: `gatsby-source-filesystem`,
options: {
name: `images`,
path: `${__dirname}/src/images/`,
},
},
'gatsby-plugin-sitemap',
'gatsby-plugin-react-helmet',
`gatsby-plugin-image`,
`gatsby-plugin-sharp`,
],
}
everything works fine but it does not meet my needs (all pages have the same priority 0.7)
Solved! this code does not work with versions above 3.3.0 so I downgraded the sitemap plugin from 4.9.0 to 3.3.0 and now works like a charm.
For those who may be facing the issue: It as been solved by downgrading the plugin to the 3.3.0 version prior to the 4.9.0 (the one causing the issue).
https://www.npmjs.com/package/gatsby-plugin-sitemap/v/3.3.0

vuepress additionalPages added to sidebar

I'm trying to create an AdditionalPage and add it inside the navbar.
I cannot find out how to make it happen:
This is my plugin:
async additionalPages() {
...
errorsPages.push({
path: '/errors',
content: '## Errors',
frontmatter: {
sidebar: true,
},
})
return errorsPages
When I only do this, of course no sidebar are present. This is because I did not add my /errors page inside the navbar.
When I try to add it to
config.js in the sidebar option:
'sidebar': {
'/references/': [
{
title: '📒 API References',
path: '/references/',
collapsable: false,
children: [
'/references/indexes',
'/references/keys',
{
title: 'Errors',
path: '/errors/',
collapsable: false,
},
]
}
]
}
Then the build failes.
Any idea how to add my additionalpages inside my sidebar ?
For add groups in sidebar, try this code:
sidebar: {
'/guide/': [
{
title: 'Group Guide',
children: ['', 'introduction-guide', 'details-guide'],
},
],
'/api/': [
{
title: 'Group API',
children: ['', 'introduction-api', 'details-api'],
},
],
},
The introduction-guide and details-guide are files presents in guide directory.
The introduction-api and details-api are files presents in api directory.
For more details: https://vuepress.vuejs.org/theme/default-theme-config.html#sidebar-groups

Why is my ES6 having different exports (exports || exports.default + named) depending on the scope of the import?

I have this in a yargs script:
const pkg = require(join(argv.path, 'package.json'));
const exported = require(join(argv.path, pkg.main));
console.log(exported);
If i try to read this source within the yargs script package pkg.main:
import SiteService, { SiteFunction } from 'site-service';
export const siteService = new SiteService('management', {
id: 1000,
othersIds: 1000,
});
export const siteFunction = new SiteFunction(siteService, {
id: 1000,
othersIds: 1000,
});
export default siteService;
The the value of exported is :
{ siteService:
SiteService {
name: 'management',
config: { id: 1000, othersIds: 1000 },
siteFunctionList: [] },
siteFunction:
SiteFunction {
siteService:
SiteService {
name: 'management',
config: [Object],
siteFunctionList: [] },
config: { id: 1000, othersIds: 1000 } },
default:
SiteService {
name: 'management',
config: { id: 1000, othersIds: 1000 },
siteFunctionList: [] } }
If i read the pkg.main of a different module with this content:
import React from 'react';
import Resource from 'ra-core/lib/Resource';
import Route from 'react-router-dom/Route';
import SiteService, { SiteFunction } from 'site-service';
const siteService = new SiteService('management', {
id: 1000,
otherIds: [1, 2],
});
import {
UsersList,
UsersCreate,
UsersEdit,
UsersShow,
} from './resources/users';
export const siteFunction = new SiteFunction(siteService, ({ pages, roles, permissions }) => [
<Resource
name="users"
list={UsersList}
edit={UsersEdit}
create={UsersCreate}
show={UsersShow}
/>,
], ({ pages, roles }) => [
], ({ pages, roles }) => [
{
name: 'management',
redirect: true,
from: '/management',
to: '/',
description: 'management',
},
]);
export default siteFunction;
I have the following output
SiteFunction {
siteService:
SiteService {
name: 'management',
config: { id: 1000, otherIds: [Array] },
siteFunctionList: [] },
config: [Function] }
Both project babel configuration in babel.config.js:
{
only: [
'src',
'styleguide',
],
comments: false,
presets: [
[
'#babel/preset-env',
{
modules: false,
},
],
'#babel/preset-react',
],
plugins: [
'babel-plugin-array-includes',
'#babel/plugin-transform-runtime',
'#babel/plugin-transform-async-to-generator',
'#babel/plugin-proposal-class-properties',
'#babel/plugin-syntax-dynamic-import',
'#babel/plugin-syntax-import-meta',
'#babel/plugin-proposal-json-strings',
[
'#babel/plugin-proposal-decorators',
{
legacy: true,
},
],
],
env: {
production: {
plugins: [
'babel-plugin-add-module-exports',
'#babel/plugin-transform-modules-commonjs',
],
},
test: {
plugins: [
'#babel/plugin-transform-modules-commonjs',
'babel-plugin-dynamic-import-node',
],
},
},
}
In both case, the pkg.main imported was in ES6 syntax, while the yargs script run was a ES5 transpiled file.
I believe this is not good, am I correct?
Where does the bug happen? Both projects have the same babel configuration.
Within my script, should I assume both cases can happen and should I support both?

Categories