This repository has been archived on 2025-01-19. You can view files and clone it, but cannot push or open issues or pull requests.
oliverdavies.uk-old-sculpin/webpack.config.js
2018-01-31 01:12:34 +00:00

47 lines
1.2 KiB
JavaScript

var Encore = require('@symfony/webpack-encore');
var glob = require('glob-all');
var path = require('path');
var PurgecssPlugin = require('purgecss-webpack-plugin');
/**
* Custom PurgeCSS Extractor
* https://github.com/FullHuman/purgecss
* https://github.com/FullHuman/purgecss-webpack-plugin
*/
class TailwindExtractor {
static extract(content) {
return content.match(/[A-z0-9-:\/]+/g);
}
}
Encore.cleanupOutputBeforeBuild()
.setOutputPath('source/build/')
.setPublicPath('/build')
.enableLessLoader()
.addEntry('js/site', './assets/js/main.js')
.addStyleEntry('css/site', './assets/less/main.less')
.enablePostCssLoader(function(options) {
options.config = {
path: 'postcss.config.js'
};
})
.enableSourceMaps(!Encore.isProduction());
if (Encore.isProduction()) {
Encore.addPlugin(
new PurgecssPlugin({
paths: glob.sync([
path.join(__dirname, "output_*/**/*.html"),
]),
extractors: [
{
extractor: TailwindExtractor,
extensions: ['twig', 'html', 'md']
}
]
})
);
}
module.exports = Encore.getWebpackConfig();