Last active
February 26, 2018 01:11
-
-
Save niallobrien/b2cce08f6d60335171392801b5224a5a to your computer and use it in GitHub Desktop.
Laravel Mix +TailwindCSS + PurgeCSS Asset Pipeline Config for AdonisJS
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
var mix = require('laravel-mix'); | |
var glob = require("glob-all"); | |
var PurgecssPlugin = require("purgecss-webpack-plugin"); | |
isProduction = (process.env.NODE_ENV === 'production' || process.argv.includes('-p')); | |
class TailwindExtractor { | |
static extract(content) { | |
return content.match(/[A-z0-9-:\/]+/g); | |
} | |
} | |
mix | |
.options({ processCssUrls: false, publicPath: 'public' }) | |
.autoload({ | |
jquery: ['$', 'window.jQuery', 'jQuery', 'jquery'] | |
}) | |
.js('resources/assets/scripts/app.js', 'public/assets/scripts') | |
.extract(['jquery'], 'public/assets/scripts/vendor.js') | |
.postCss('resources/assets/styles/app.css', 'public/assets/styles', [ | |
require('postcss-import')(), | |
require('tailwindcss')('./tailwind.js'), | |
require('postcss-cssnext')({ | |
features: { | |
autoprefixer: false | |
}, | |
}) | |
]) | |
.webpackConfig({ | |
plugins: [ | |
new PurgecssPlugin({ | |
paths: glob.sync([ | |
path.join(__dirname, 'resources', 'views', '/**/*.edge'), // pretty much the same as Laravel blade templates | |
path.join(__dirname, 'resources', 'assets', 'scripts', '/**/*.js') | |
]), | |
extractors: [ | |
{ | |
extractor: TailwindExtractor, | |
extensions: ["html", "js", "edge"] | |
} | |
] | |
}) | |
] | |
}) | |
if (isProduction) mix.version() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment