Tailwind CSS styles not applied on deployed NextJs app on Vercel - deployment

All tailwind styles are broken on the deployed version
Localhost
Deployed version
MY tailwind config :
module.exports = {
mode: "jit",
purge: [
"./pages/**/*.{js, ts, jsx, tsx}",
"./components/**/*.{js,ts,jsx,tsx}"
],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [
require("#tailwindcss/forms"),
require("tailwind-scrollbar"),
require("tailwind-scrollbar-hide"),
],
};

Try disabling the JIT mode. Not sure how you are adding classes to tags, but if its dynamic JIT doesn't work properly. I faced similar issue during my recent development.
module.exports = {
purge: [
"./pages/**/*.{js, ts, jsx, tsx}",
"./components/**/*.{js,ts,jsx,tsx}"
],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [
require("#tailwindcss/forms"),
require("tailwind-scrollbar"),
require("tailwind-scrollbar-hide"),
],
};

Related

Cannot purge tailwind

I am trying to purge tailwind with ejs. But when I tried to purge, I got this Error: Could not resolve entry module (index.html) ..
Here is my tailwind config.js:
module.exports = {
purge: ["./**/*.ejs"],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
container: {
center: true,
},
},
},
variants: {
extend: {},
},
plugins: [],
}
My postcss config.js file:
module.exports = {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
Inside my app.js
app.set('view engine', "ejs");
app.use(express.static('public'));
Inside my package.json, I have this script:
"scripts": {
"build:tailwinds": "tailwind build -i src/style.css -o public/css/style.css",
"start": "nodemon app.js",
"dev": "vite",
"build": "vite build"
},
My folder structure:
See how my files are organized
How can i purge tailwind with ejs file. In ejs there are no index.html, so how can I solve the error? What I am missing out?
Is your tailwind version updated to the latest?
Take a look at my set up, tweak things up to see if purge works for you with ejs.
tailwind.config.js
module.exports = {
mode: "jit",
purge: [
"./src/pages/**/*.{js,ts,jsx,tsx}",
"./src/components/**/*.{js,ts,jsx,tsx}",
],
package.json
"tw:build": "tailwindcss build ./src/styles/global.css -o ./public/styles/global.css",
"tw:prod": "cross-env NODE_ENV=production postcss build ./src/styles/global.css -o ./public/styles/global.css",
"tw:watch": "onchange \"tailwind.config.js\" \"src/**/*.css\" -- npm run tw:build"
You can also use cssnano it's an awsome extension for purging tailwind css
postcss.config.js
const cssnano = require("cssnano");
module.exports = {
plugins: [
require("tailwindcss"),
cssnano({
preset: "default",
}),
require("autoprefixer"),
],
};
In case you use Tailwind v3:
Since Tailwind no longer uses PurgeCSS under the hood, we’ve renamed
the purge option to content to better reflect what it’s for:
tailwind.config.js
module.exports = {
content: [
'./public/**/*.html',
'./src/**/*.{js,jsx,ts,tsx,vue}',
],
}

regenerator.mark is not a function svelte + rollup + babel

I am getting the error Uncaught TypeError: regenerator.mark is not a function
I checked bundle generated regenerator is { __esModule: true }
seems #babel/plugin-transform-runtime, it's not able to inject runtime.js in a bundle.
here's Rollup config:-
export default {
input: 'src/main.js',
output: {
sourcemap: true,
format: 'iife',
name: 'app',
file: `public/build/${bundleName}`,
},
plugins: [
svelte({
compilerOptions: {
// enable run-time checks when not in production
dev: !production,
},
preprocess: preprocess(),
}),
babel({
extensions: ['.js', '.mjs', '.html', '.svelte'],
runtimeHelpers: true,
exclude: 'node_modules/core-js/**',
presets: [
[
'#babel/preset-env',
{
// debug: true,
useBuiltIns: 'entry',
corejs: '3',
targets: {
browsers: ['safari >= 5', 'ie >= 11', 'not dead'],
},
},
],
],
plugins: [
'#babel/plugin-syntax-dynamic-import',
[
'#babel/plugin-transform-runtime',
{
useESModules: false,
},
],
],
}),
resolve({
browser: true,
dedupe: ['svelte'],
}),
commonjs(),
includePaths(includePathOptions),
production && terser(),
production && gzipPlugin(),
],
};

multiple entries + preserveModules with rollup and rollup-plugin-babel - why are all helpers not included in _rollupPluginBabelHelpers.js?

So I have a library of JSX that I am transpiling for inclusion in a React project.
Configs
rollup.config.js: -
import babel from "rollup-plugin-babel"
import pkg from "./package.json"
const externals = Object.keys(pkg.peerDependencies || {})
export default [
{
input: __dirname + "/src/File1.js",
output: {
dir: __dirname + "/lib/",
format: "esm",
},
plugins: [
babel({}),
],
preserveModules: true,
external: externals
},
{
input: __dirname + "/src/File2.js",
output: {
dir: __dirname + "/lib/",
format: "esm",
},
plugins: [
babel({})
],
preserveModules: true,
external: externals
},
...
]
.babelrc (inside /src): -
{
"presets": [
["#babel/preset-env", {"modules": false}],
"#babel/preset-react"
],
"plugins": [
[
"#babel/plugin-proposal-class-properties"
],
[
"babel-plugin-styled-components"
]
]
}
The problem
When I include the code in my webpack compiler, I get errors like these: -
WARNING in ./lib/File1.js 29:146-161 "export 'defineProperty' (imported as '_defineProperty') was not found in './_virtual/_rollupPluginBabelHelpers.js'
WARNING in ./lib/File2.js 45:11-25 "export 'objectSpread2' (imported as '_objectSpread2') was not found in './_virtual/_rollupPluginBabelHelpers.js'
It seems that providing an array of multiple entries results in a _rollupPluginBabelHelpers.js populated with only the helpers required for the final entry in the array.
Can anyone help me with this? I have read all the documentation I can find and googled and I can't find an answer to this. Thanks.
Issue has been resolved on github with the following config: -
export default {
input: [__dirname + "/src/File1.js", __dirname + "/src/File2.js"],
output: {
dir: __dirname + "/lib/",
format: "esm",
},
plugins: [
babel({}),
],
external: externals
}

unexpected token import using karma with webpack and babel

I'm trying to run karma tests using karma, webpack and babel. I feel like I've configured properly but it seems that the test files are not being transpiled.
karma.conf:
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['mocha', 'chai'],
files: [
{pattern: 'src/**/*-test.js', watched: false}
],
exclude: [
],
preprocessors: {
'src/**/*-test.js': ['webpack']
},
webpack: require("./webpack.config.js"),
webpackMiddleware: {
stats: 'errors-only'
},
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false,
concurrency: Infinity
})
}
webpack.config:
module.exports = {
entry: [
'react-hot-loader/patch',
'webpack/hot/only-dev-server',
path.resolve(__dirname, 'src/index.js')
],
output: {
filename: 'bundle.js'
},
module: {
rules: [
{ test: /\.(js|jsx)$/, exclude: /(\/node_modules\/|test\.js$)/, use: 'babel-loader'},
{ test: /\.css$/, use: ['style-loader', 'css-loader'] },
{ test: /\.less$/, use: ['style-loader', 'css-loader', 'less-loader'] },
{ test: /\.(png|woff|woff2|eot|ttf|svg)$/, use: 'url-loader?limit=100000' }
]
},
resolve: {
extensions: ['.js', '.jsx']
}
};
My test file uses import syntax to import expect from chai and runs a simple test taht expects true is equal true but when I run the karma I'm getting
uncaught syntaxerror: unexpected token import
I've had a look at similar question:
Karma + Webpack (babel-loader) + ES6 "Unexpected token import"
but no luck. I'm sure it's something simple in my configs. Has anyone seen similar?
this is a new project so using latest packages, webpack2 etc.
Any ideas greatly appreciated
C

How to get Browserify, Babel, and Coverage working together in Karma?

I'm growing weary of trying to get node libraries to work properly together, but it's part of the job, so here goes.
I have an ES6 application intended for a browser. I have a set of unit tests for my files that I'm bringing up from when my application was written in ES5. I use Browserify to handle importing/exporting modules and bundling my distro. This works fine when running the application in the browser. I can successfully Browserify the source and spec files and run the tests, and the tests pass. I'm very close to getting this working.
The only issue is the coverage. The closest I've come is showing coverage on the karma-browserify generated files, which each look like this:
require('/absolute/path/to/the/corresponding/file.js');
And the coverage obviously shows as 100% for all files, because each one is just one line.
This is my karma.conf.js:
import babelify from 'babelify';
import isparta from 'isparta';
import paths from './paths';
var normalizeBrowserName = (browser) => browser.toLowerCase().split(/[ /-]/)[0];
export default function(config) {
config.set({
basePath: '..',
browsers: ['PhantomJS'],
frameworks: ['browserify', 'jasmine'],
files: paths.test.files,
preprocessors: {
'app/**/*.js': ['browserify', 'sourcemap', 'coverage'],
[paths.test.testFiles]: ['babel'],
},
plugins: [
'karma-babel-preprocessor',
'karma-browserify',
'karma-coverage',
'karma-jasmine',
'karma-junit-reporter',
'karma-phantomjs-launcher',
'karma-sourcemap-loader',
],
autoWatch: false,
colors: false,
loggers: [{ type: 'console' }],
port: 9876,
reporters: ['progress', 'dots', 'junit', 'coverage'],
junitReporter: {
outputFile: paths.test.resultsOut,
suite: '',
},
browserify: {
debug: true,
noParse: paths.js.noparse(),
configure: (bundle) => {
bundle.once('prebundle', () => bundle.transform(babelify.configure({ ignore: 'lib/!**!/!*' })));
},
},
coverageReporter: {
instrumenters: { isparta },
instrumenter: {
[paths.test.cover]: 'isparta',
},
reporters: [
{ type: 'text', },
{ type: 'html', dir: paths.test.coverageOut, subdir: normalizeBrowserName },
{ type: 'cobertura', dir: paths.test.coverageOut, subdir: '.', file: 'coverage.xml' },
],
},
logLevel: config.LOG_DEBUG,
});
};
I really have no idea how any of these libraries work, so I don't know where to start in debugging this. I understand that the ordering of the preprocessors matters, so that Browserify runs on the source files, feeds the resulting link files into the source map generator, then the source map generator feeds the resulting whatever into karma-coverage. But there's some loss of communication between Browserify and whatever handles the coverage. Isparta (which uses istanbul behind the scenes) has no idea that browserify is running, and I don't know what it sees.
If anyone has any experience with testing modularized ES6 WITH proper code coverage, please let me know if I'm on the right track or if I should try something else.
This is the configuration that worked for me, note that I am using browserify-istanbul rather than isparata.
var istanbul = require('browserify-istanbul');
module.exports = function(config) {
config.set({
basePath: '',
frameworks: ['browserify', 'mocha'],
files: [
'test/**/*Spec.js'
],
exclude: [
'**/*.sw?'
],
preprocessors: {
'test/**/*Spec.js': ['browserify', 'coverage']
},
browserify: {
debug: true,
transform: [
['babelify', {
ignore: /node_modules/
}],
istanbul({
ignore: ['test/**', '**/node_modules/**']
})
],
extensions: ['.jsx']
},
babelPreprocessor: {
options: {
sourceMap: 'inline'
},
sourceFileName: function(file) {
return file.originalPath;
}
},
coverageReporter: {
dir: 'coverage/',
reporters: [
{ type: 'text-summary' }
]
},
browserNoActivityTimeout: 180000,
reporters: ['coverage', 'progress'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};
it was a massive pain to get working.
hope that helps
HOW TO: Karma + Babel + React + Browserify + Istanbul
I THINK I GOT IT.
If I don't, ping me gus+overflow#mythril.co
Not sure if the previous answer not working has to do with using jasmine instead of mocha but I got it working with these settings.
Required Packages: apart from the obvious (React, Karma, Jasmine, Browserify)
isparta - an Istanbul instrumenter for ES6
browserify-istanbul - a browserify transform
babelify - another browserify transform
babel - JS compiler
babel-preset-2015 - ES6 compile preset
babel-preset-react - React compile preset
Create a .babelrc file in your root dir.
I was very confused as to where to place babel options within the tools, but most (and these) babel tools will look for a .babelrc
{
"presets": ["es2015", "react"],
"sourceMap": "inline"
}
karma.config.js:
const isparta = require('isparta');
const istanbul = require('browserify-istanbul');
module.exports = function (config) {
config.set({
basePath: '',
browsers: ['Firefox', 'Chrome', 'PhantomJS', 'Safari'],
captureConsole: true,
clearContext: true,
colors: true,
files: [
// you need this for Phantom
'node_modules/phantomjs-polyfill/bind-polyfill.js',
// import any third party libs, we bundle them in another gulp task
'./build/libs/vendor-bundle.js',
// glob for spec files
'__PATH_TO_SPEC_FILES_/*.spec.js'
],
frameworks: ['jasmine', 'browserify'],
logLevel: config.LOG_INFO,
preprocessors: {
// I had to NOT include coverage, the browserify transform will handle it
'__PATH_TO_SPEC_FILES_/*.spec.js': 'browserify'
},
port: 9876,
reporters: ['progress', 'coverage'],
browserify: {
// we still use jQuery for some things :(
// I don't think most people will need this configure section
configure: function (bundle) {
bundle.on('prebundle', function () {
bundle.external(['jquery']);
});
},
transform: [
// this will transform your ES6 and/or JSX
['babelify'],
// (I think) returns files readable by the reporters
istanbul({
instrumenter: isparta, // <--module capable of reading babelified code
ignore: ['**/node_modules/**', '**/client-libs/**']
})
],
// our spec files use jsx and so .js will need to be compiled too
extensions: ['.js', '.jsx'],
// paths that we can `require()` from
paths: [
'./node_modules',
'./client-libs',
'./universal'
],
debug: true
},
coverageReporter: {
reporters: [
{ type: 'html', dir: 'coverage/Client' },
{ type: 'text-summary' }
]
}
});
};
With Karma, I think it would look something like this(?):
// Karma configuration
'use strict';
let babelify = require( 'babelify' );
let browserify = require('browserify');
let browserifyBabalIstanbul = require('browserify-babel-istanbul');
let isparta = require('isparta');
browserify: {
debug: true,
transform: [
browserifyBabalIstanbul({
instrumenter: isparta,
instrumenterConfig: { babel: { presets: ["es2015"] } },
ignore: ['**/node_modules/**', '**/unitest/**']
}),
[ babelify, { presets: ["es2015"] } ]
]
},
see the following link : Find a good way to get a coverage report with karma?