Created
April 20, 2020 06:43
-
-
Save julienbourdeau/a7e0c8be740d57c705b75b5dd6d53f2f to your computer and use it in GitHub Desktop.
Laravel Mix with multiple Tailwind config and PurgeCSS (separate Admin dashboard and Front app)
This file contains hidden or 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 mix = require('laravel-mix'); | |
const tailwindcss = require('tailwindcss'); | |
const rootPath = Mix.paths.root.bind(Mix.paths); | |
const tailwindPlugins = function(configFile, paths) { | |
const pluginList = [tailwindcss(configFile)]; | |
if (mix.inProduction()) { | |
pluginList.push(require('@fullhuman/postcss-purgecss')({ | |
content: paths.map((path) => rootPath(path)), | |
defaultExtractor: content => content.match(/[A-Za-z0-9-_:/]+/g) || [], | |
whitelistPatterns: [/-active$/, /-enter$/, /-leave-to$/] | |
})) | |
} | |
return pluginList; | |
} | |
mix | |
.js('resources/js/front/front.js', 'public/js/') | |
.sass( | |
'resources/css/front.scss', | |
'public/css/', | |
{}, | |
tailwindPlugins( | |
'resources/css/tailwind.front.config.js', | |
[ | |
'resources/views/front/**/*.html', | |
'resources/views/front/**/*.php', | |
'resources/js/front/**/*.vue', | |
] | |
) | |
) | |
.sass( | |
'resources/css/admin.scss', | |
'public/css/admin/', | |
{}, | |
tailwindPlugins( | |
'resources/css/tailwind.admin.config.js', | |
[ | |
'resources/views/components/admin/**/*.php', | |
'resources/views/admin/**/*.html', | |
'resources/views/admin/**/*.php', | |
'resources/views/auth/**/*.html', | |
'resources/views/auth/**/*.php', | |
'resources/js/admin/**/*.vue', | |
] | |
) | |
) | |
.options({ | |
processCssUrls: false, | |
}) | |
.browserSync('boucherie.test'); | |
if (mix.inProduction()) { | |
mix.version(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you're looking for a simple way