Professional Documents
Culture Documents
Brent Vanwildemeersch
Posted on 13 oct 2020
• Updated on 13 nov 2020
Quick summary on how to configure Angular (8+) to use TailwindCSS as the CSS Framework in your project for
building responsive designs.
Install TailwindCSS
As stated in the TailwindCSS documentation, we can easily install Tailwind using the following command
# Using npm
# Using Yarn
#using npm
https://dev.to/vanwildemeerschbrent/how-to-use-tailwindcss-in-angular-4o2e 1/6
3/9/22, 12:39 How to use TailwindCSS in Angular - DEV Community 👩💻👨💻
#using Yarn
#using npm
#using Yarn
Create webpack.config.js
Create a webpack.config.js file in the root of project. Once created we can setup the webpack configuration.
module.exports = {
module: {
rules: [
test: /\.scss$/,
loader: 'postcss-loader',
options: {
ident: 'postcss',
syntax: 'postcss-scss',
plugins: () => [
require('postcss-import'),
require('tailwindcss'),
require('autoprefixer'),
}
https://dev.to/vanwildemeerschbrent/how-to-use-tailwindcss-in-angular-4o2e 2/6
3/9/22, 12:39 How to use TailwindCSS in Angular - DEV Community 👩💻👨💻
}
};
As you can see in the webpack-config file above, we will process any .scss files in our project using or the installed
postCSS -packages and we require tailwindcss as a plugin in our config.
We will not adjust our angular.json file manually, but use the AngularCLI to make the changes
Change the webpack-builder to the installed @angular-builders/custom-webpack package for the ng build
command
ng config projects.<your-project>.architect.build.builder
@angular-builders/custom-webpack:browser
Change the webpack configuration to the newly created configuration file for the ng build command
ng config
projects.<your-project>.architect.build.options.customWebpackConfig.path webpack.config.js
When serving the project on a local dev-server, use the custom-webpack package
ng config projects.<your-project>.architect.serve.builder
@angular-builders/custom-webpack:dev-server
h h l ld
https://dev.to/vanwildemeerschbrent/how-to-use-tailwindcss-in-angular-4o2e h d fl 3/6
3/9/22, 12:39 How to use TailwindCSS in Angular - DEV Community 👩💻👨💻
When serving the project on a local dev-server, use the custom created webpack.config file
ng config projects.<your-project>.architect.serve.builder
@angular-builders/custom-webpack:dev-server
This will create a tailwind.config.js file in the root of your project that you can use to extend Tailwind
@import "tailwindcss/base";
@import "tailwindcss/components";
@import "tailwindcss/utilities";
All done
Everything should be configured correctly to make use of the Tailwind CSS-library in your Angular Project.
A simple addition of a TailwindCSS utility in your app.component.html should give you an indication if Tailwind is
working correctly in your project.
(It is useful to restart the local development-server ng serve to make sure that everything compiles correctly)
https://dev.to/vanwildemeerschbrent/how-to-use-tailwindcss-in-angular-4o2e 4/6
3/9/22, 12:39 How to use TailwindCSS in Angular - DEV Community 👩💻👨💻
Discussion (0)
Code of Conduct
•
Report abuse
Brent Vanwildemeersch
LOCATION
Belgium
WORK
Software Engineer
JOINED
3 ene 2020
https://dev.to/vanwildemeerschbrent/how-to-use-tailwindcss-in-angular-4o2e 6/6