Tailwind CSS
@nativescript/tailwind
|
It Makes using Tailwind CSS in NativeScript a lot easier!
<label
text="Tailwind CSS is awesome!"
class="px-2 py-1 text-center text-blue-600 bg-blue-200 rounded-full"
/>

Usage
This guide assumes you are using |
Install @nativescript/tailwind
and tailwindcss
npm install --save @nativescript/tailwind tailwindcss
Generate a tailwind.config.js
with
npx tailwindcss init
Adjust content
, darkMode
, corePlugins
plus any other settings you need, here are the values we recommend:
// tailwind.config.js
module.exports = {
content: ['./app/**/*.{css,xml,html,vue,svelte,ts,tsx}'],
// use .dark to toggle dark mode - since 'media' (default) does not work in NativeScript
darkMode: 'class',
theme: {
extend: {}
},
plugins: [],
corePlugins: {
preflight: false // disables browser-specific resets
}
}
Change your app.css
or app.scss
to include the tailwind utilities
@tailwind base;
@tailwind components;
@tailwind utilities;
Start using tailwind in your app.
Using a custom PostCSS config
In case you need to customize the postcss configuration, you can create a postcss.config.js
(other formats are supported, see https://github.com/webpack-contrib/postcss-loader#config-files) file and add any customizations, for example:
// postcss.config.js
module.exports = {
plugins: [
['tailwindcss', { config: './tailwind.config.custom.js' }],
'@nativescript/tailwind'
]
}
if you want to apply customizations to
This is required only if you make changes to either of the 2 plugins - because by default |
Usage with older @nativescript/webpack versions
Details
npm install --save-dev @nativescript/tailwind tailwindcss postcss postcss-loader
Create postcss.config.js
with the following:
module.exports = {
plugins: [require('tailwindcss'), require('nativescript-tailwind')]
}
Generate a tailwind.config.js
with
npx tailwindcss init
Adjust content, darkMode
, corePlugins
plus any other settings you need; here are the values we recommend:
// tailwind.config.js
module.exports = {
content: ['./app/**/*.{css,xml,html,vue,svelte,ts,tsx}'],
// use .dark to toggle dark mode - since 'media' (default) does not work in NativeScript
darkMode: 'class',
theme: {
extend: {}
},
plugins: [],
corePlugins: {
preflight: false // disables browser-specific resets
}
}
Change your app.css
or app.scss
to include the tailwind utilities
@tailwind base;
@tailwind components;
@tailwind utilities;
Update webpack.config.js
to use PostCSS
Find the section of the config that defines the rules/loaders for different file types. To quickly find this block - search for rules: [.
For every css/scss block, append the postcss-loader
to the list of loaders, for example:
{
test: /[\/|\\]app\.css$/,
use: [
'nativescript-dev-webpack/style-hot-loader',
{
loader: "nativescript-dev-webpack/css2json-loader",
options: { useForImports: true }
},
+ 'postcss-loader',
],
}
Make sure you append postcss-loader
to all css/scss rules in the config.