-
-
Save tomasnorre/8b76a9852d571056b078a6a329995262 to your computer and use it in GitHub Desktop.
Tailwind CSS in a Symfony Project with Webpack Encore and Purge CSS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Encore = require('@symfony/webpack-encore'); | |
const tailwindcss = require('tailwindcss'); | |
const autoprefixer = require('autoprefixer'); | |
const purgecss = require('@fullhuman/postcss-purgecss')({ | |
content: [ | |
'./templates/**/*.twig', | |
'./assets/js/**/*.vue', | |
'./assets/js/**/*.js', | |
], | |
defaultExtractor: content => content.match(/[\w-/:]+(?<!:)/g) || [], | |
}); | |
Encore | |
.setOutputPath('public/build/') | |
.setPublicPath('/build') | |
.addEntry('js/app.js', './assets/js/app.js') | |
.addStyleEntry('css/app.css', './assets/css/app.scss') | |
.enableSingleRuntimeChunk() | |
.cleanupOutputBeforeBuild() | |
.enableSourceMaps(!Encore.isProduction()) | |
.enableVersioning(Encore.isProduction()) | |
.configureBabel(() => { | |
}, { | |
useBuiltIns: 'usage', | |
corejs: 3 | |
}) | |
.enableSassLoader(sassOptions => { | |
}, { | |
resolveUrlLoader: false | |
}) | |
.enablePostCssLoader(options => { | |
options.plugins = [ | |
tailwindcss, | |
autoprefixer, | |
]; | |
if (Encore.isProduction()) { | |
options.plugins.push(purgecss); | |
} | |
}) | |
.enableVueLoader() | |
; | |
module.exports = Encore.getWebpackConfig(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment