TailwindCSS nesting not working with postCSS config - nested

I am trying to scope tailwind styles and I am using this postcss config from Tailwind docs:
module.exports = {
plugins: {
'postcss-import': {},
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {},
}
}
and here is my css
.app-wrapper {
#tailwind base;
#tailwind components;
#tailwind utilities;
}
with this config the nesting is working fine but not all the tailwindCSS classes working as expected.
but when I change the config to the following
module.exports = {
plugins: [
require('postcss-import'),
require('tailwindcss/nesting'),
require('tailwindcss'),
require('autoprefixer'),
]
};
the classes works fine but the nesting throw the following error
Nested #tailwind rules were detected, but are not supported.
any idea how I can get the tailwind to work as expected with the nesting enabled?

If you wish to add parent selector for every compiled utility, add important: '.app-wrapper', into your tailwind config and do not wrap #tailwind directives
// postcss.config.js
module.exports = {
plugins: {
'postcss-import': {},
'tailwindcss/nesting': {},
tailwindcss: {},
autoprefixer: {},
}
}
#tailwind base;
#tailwind components;
#tailwind utilities;
// tailwind.config.js
module.exports = {
important: '.app-wrapper',
// ...
};
This called selector strategy. This way text-red-500 utility will be compiled as
.app-wrapper .text-red-500 {
--tw-text-opacity: 1;
color: rgb(239 68 68 / var(--tw-text-opacity));
}
Please note: if you set darkMode as class strategy in your config
module.exports = {
darkMode: 'class',
important: '.app-wrapper',
// ...
};
utility dark:text-white (and every other dark utility) will be compiled as
.app-wrapper .dark .dark\:text-white {
--tw-text-opacity: 1;
color: rgb(255 255 255 / var(--tw-text-opacity));
}
So if both dark and app-wrapper classes will be placed on the SAME element (e.g. html or body) dark mode would not work. That may explain why some classes are not working when using nesting

Related

How to disable webpack dev server auto reload for neutrino project?

Browser: Peruse
Type of project: SAFE network website
I need to turn it off because Peruse considers window.eval() to be a security issue and thus blocks it, which in turn stops my website from loading.
Peruse is the standard browser for Maidsafe as far as I know.
Both of my attempts to fix this have failed:
webpack.config.js
module.exports = {
devServer: {
hot: false,
inline: false
}
};
neutrinorc.js
module.exports = {
use: [
[
'#neutrinojs/vue',
{
html: {
title: 'SAFE Web App'
}
}
],
(neutrino) => {
neutrino.config.devServer
.hot(false)
.inline(false)
}
]
};
The error:
Uncaught Error: Sorry, peruse does not support window.eval().
at window.eval.global.eval (/opt/Maidsafe/Peruse/resources/app.asar/webPreload.js:9:82219)
at Object../node_modules/webpack-dev-server/client/index.js?http://localhost:5000 (http://localhost:5000/index.js:957:1)
at __webpack_require__ (http://localhost:5000/index.js:679:30)
at fn (http://localhost:5000/index.js:89:20)
at Object.0 (http://localhost:5000/index.js:1060:1)
at __webpack_require__ (http://localhost:5000/index.js:679:30)
at http://localhost:5000/index.js:725:37
at http://localhost:5000/index.js:728:10
package.json
...
"dependencies": {
"#babel/helper-module-imports": "^7.0.0-beta.44",
"vue": "^2.5.16"
},
"devDependencies": {
"#neutrinojs/vue": "^8.2.1",
"#vue/devtools": "^4.1.5",
"neutrino": "^8.2.1"
}
...
The eval() errror is not coming from webpack-dev-server.
It turns out that the the default source map mode used by #neutrinojs/web which #neutrinojs/web inherits from is cheap-module-eval-source-map and needs to be set to cheap-module-source-map.
Thus neutrinorc.js needs to be configured as such:
module.exports = {
use: [
['#neutrinojs/vue', {
// Existing options
}],
(neutrino) => {
if (process.env.NODE_ENV === 'development') {
// Override the default development source map of 'cheap-module-eval-source-map'
// to one that doesn't use `eval` (reduces incremental build performance).
neutrino.config.devtool('cheap-module-source-map');
}
}
]
};

grunt cssmin different target files for style.min.css and above-the-fold.min.css

In an older version of cssmin it was possible to create to different target files. I minified a style.min.css and an above-the-fold.min.css. Now I updated to a newer version of nodejs, npm, grunt and cssmin and it is not possible to minify to different outputfiles anymore. Since the update grunt only minifies the second task and skip the first task. Do you have a hint for me to minify both tasks?
cssmin: {
options: {
mergeIntoShorthands: false,
roundingPrecision: -1
},
target: {
files: {
'data/style.min.css': ['a.css', 'b.css', 'c.css', 'd.css', 'e.css', 'f.css', 'g.css']
}
}
},
penthouse: {
extract : {
outfile : 'data/above-the-fold.temp.css',
css : './data/style.min.css',
url : 'http://localhost/',
width : 1280,
height : 500
},
},
cssmin: {
options: {
mergeIntoShorthands: false,
roundingPrecision: -1
},
target: {
files: {
'data/above-the-fold.min.css': ['data/above-the-fold.temp.css']
}
}
}
grunt-contrib-cssmin will allow multiple Targets to be defined in a single Task. For example:
Gruntfile.js
module.exports = function (grunt) {
grunt.initConfig({
// ...
cssmin: { // <-- cssmin Task
options: {
mergeIntoShorthands: false,
roundingPrecision: -1
},
targetA: { // <-- First target
files: {
'data/style.min.css': ['a.css', 'b.css', 'c.css', 'd.css', 'e.css', 'f.css', 'g.css']
}
},
targetB: { // <-- Second target
files: {
'data/above-the-fold.min.css': ['data/above-the-fold.temp.css']
}
}
}
// ...
});
// ...
};
Each Target name should be unique within the cssmin Task. For example: targetA and targetB
As you've included the penthouse Task in your post, I guess that you need to run that after generating the style.min.css file, and before generating the above-the-fold.min.css. To do this you can register your Tasks as follows:
grunt.registerTask('default', ['cssmin:targetA', 'penthouse', 'cssmin:targetB',]);
Note: The use of the semi-colon notation, namely cssmin:targetA and cssmin:targetB. This simply ensures that targetA of the cssmin Task is run before the penthouse Task. Subsequently, (when the penthouse Task completes), targetB of the cssmin Task is run.

How to add AMD/legacy dependency (leaflet) with sub dependencies in requirejs

I installed a AMD module called leaflet and successfully using it as "L".
Next I need a plugin called leaflet.draw but I get confused about the dependencies. Consider the following code:
requirejs.config({
baseUrl: 'bower_components',
paths: {
leaflet: 'leaflet/dist/leaflet-src',
leafletdraw: 'leaflet-draw/dist/leaflet.draw-src'
...
requirejs(["leaflet", "leafletdraw"], function(L, leafletdraw) {
var map = new L.Map('map');
...
This gives a referenceError: L is not defined at Leaflet.draw.js:4. So I guess it needs the leaflet (L) as a dependency, right? I then tried to add it in the shim config:
shim: {
leafletdraw: {
deps: 'leaflet'
}
}
This results in a "Invalid require call". So my question is: How do I properly require a plugin with subdependencies?
The modules are installed with "bower install leaflet" and "bower
install leaflet-draw" respectivily. But im not sure if leaflet-draw
is AMD enabled. Why isnt that stated in repos docs? Can I assume it
is enabled by default?
This is what I try to achive:
http://codepen.io/osmbuildings/pen/LVJzWw, but with requirejs.
Solution: shim leaflet itself, and let it export 'L'. Then putting the deps in plugins will work. My full config:
requirejs.config({
baseUrl: 'bower_components',
paths: {
jquery: 'jquery/dist/jquery.min',
leaflet: 'http://cdn.leafletjs.com/leaflet-0.7.3/leaflet',
'leaflet-draw': 'http://cdn.osmbuildings.org/Leaflet.draw/0.2.0/leaflet.draw',
OSMBuildings: ['http://cdn.osmbuildings.org/OSMBuildings-Leaflet']
},
shim: {
leaflet: {
exports: 'L'
},
'leaflet-draw': {
deps: ['leaflet']
},
OSMBuildings: {
deps: ['leaflet'],
exports: 'OSMBuildings'
}
}
});
requirejs(["jquery", "leaflet", "leaflet-draw", "OSMBuildings"], function($, L, dummy, OSMBuildings) {
var map = new L.Map('map');

Loading hyperagent with require.js

I've used bower to install hyperagent, and it pulled down some dependencies, I'm just not sure how to properly initialise it now.
As far as I call tell, it doesn't support AMD loading, so I'm trying to use a shim config. I've tried a few things, looking something like this:
<script src="{{ path('root') }}bower/requirejs/require.js"></script>
<script>
require.config({
"baseUrl": "{{ url('root') }}/bower/",
paths: {
"vue": 'vue/dist/vue.min',
"hyperagent": 'hyperagent/dist/hyperagent',
"jquery": "jquery/jquery.min",
"uri": "uri.js/src/URI.min"
},
shim: {
'hyperagent': {
'deps': ['jquery', 'uri'],
'exports': 'Hyperagent'
}
}
});
</script>
When I later do
require(['vue', 'hyperagent'], function(Vue, Hyperagent) { ... });
Hyperagent is undefined.
Am I way off the mark? (Oh, and the mustaches are twig, this is a Symfony project)
Thanks to Ben Weiner for this one. Taken from here.
I installed hyperagent and URIjs via bower and for now I'm just setting window.URI as a global before requiring hyperagent. Here's the relevant part of my require.js config:
require.config({
paths: {
'hyperagent': '../bower_components/hyperagent/dist/amd/hyperagent',
'URIjs': '../bower_components/uri.js/src',
}
});
To use it I just define an amd module that returns a configured hyperagent eg configured_hyperagent.js:
define(function(require) {
window.URI = require('URIjs/URI');
window.URITemplate = require('URIjs/URITemplate');
Hyperagent = require('hyperagent');
// Hyperagent.configure() etc..
return Hyperagent;
});

Configure grunt watch to run Jasmine tests against an app using requirejs

In an attempt to level up my general coding skills... and to learn something new.
I've started attempting to wire up a front end only solution consisting of
Durandal
Jasmine - [added via npm]
Grunt Watch to monitor & run my tests as my code files change - [added via npm]
Feel free to correct me, as this is all based on my experimentation in the last 2 days. Most of this is new to me. My goal is to have something similar as to what angular has with karma.
Now I am aware that that the Durandal project (comes with a custom spec runner, as found in the github solution)
My setup:
gruntfile.js
module.exports = function(grunt) {
var appPath = 'App/viewmodels/*.js';
var testPath = 'Tests/**/*.js';
grunt.initConfig({
jasmine: {
pivotal: {
src: appPath,
options: {
specs: testPath,
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfigFile: 'SpecRunner.js'
}
}
}
},
jshint: {
all: [testPath, appPath],
options: {
curly: true
}
},
watch: {
files: [testPath, appPath],
tasks: ['jshint','jasmine']
}
});
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['jshint','jasmine']);
};
SpecRunner.js
require.config({
paths: {
jquery: 'Scripts/jquery-1.9.1',
knockout: 'Scripts/knockout-2.3.0'
},
shim: {
knockout: {
exports: "ko"
}
}
});
When I run grunt, I get a Illegal path or script error: ['plugins/http']
(I've sorted out the ko issue in the screenshot)
Question:
How would i go about setting up my gruntfile to require any dependencies. I'm quite new to require, and I'm not sure how to configure it to make my tests aware of where to find things like 3rd party libraries and other custom js files for that matter
SpecRunner require.config is missing Durandal specific path information. If you set the baseUrl to 'App' then the paths below matches the HTML samples or StarterKit layout. If your layout is different you'd have to adjust this accordingly.
requirejs.config({
paths: {
'text': '../lib/require/text',
'durandal':'../lib/durandal/js',
'plugins' : '../lib/durandal/js/plugins',
'transitions' : '../lib/durandal/js/transitions',
'knockout': '../lib/knockout/knockout-2.3.0',
'bootstrap': '../lib/bootstrap/js/bootstrap',
'jquery': '../lib/jquery/jquery-1.9.1'
}
});

Resources