11const fs = require ( 'fs' ) ;
22const path = require ( 'path' ) ;
33
4+ const filenameTailwind = 'tailwind.config.js' ;
5+
46function loadModule ( src , filename ) {
57 var Module = module . constructor ;
68 var m = new Module ( ) ;
@@ -35,7 +37,19 @@ function generateConfig(option) {
3537 }
3638 const { spawnSync } = require ( 'child_process' ) ;
3739 const tailwind = path . resolve ( './node_modules/.bin/tailwind' ) ;
38- spawnSync ( tailwind , args , { shell : process . platform === 'win32' } ) ;
40+ spawnSync ( tailwind , args , { shell : process . platform === 'win32' } ) ;
41+ }
42+
43+ function injectPurgeConfig ( ctx ) {
44+ const configPath = path . join ( ctx , filenameTailwind ) ;
45+ const tailwindConfig = fs . readFileSync ( configPath , 'utf-8' ) ;
46+ fs . writeFileSync (
47+ configPath ,
48+ tailwindConfig . replace (
49+ 'purge: []' ,
50+ "purge: { content: ['./public/**/*.html', './src/**/*.vue'] }" ,
51+ ) ,
52+ ) ;
3953}
4054
4155module . exports = ( api , options ) => {
@@ -44,7 +58,6 @@ module.exports = (api, options) => {
4458 postcss : {
4559 plugins : {
4660 tailwindcss : { } ,
47- 'vue-cli-plugin-tailwind/purgecss' : { } ,
4861 autoprefixer : { } ,
4962 } ,
5063 } ,
@@ -58,9 +71,8 @@ module.exports = (api, options) => {
5871 api . render ( './template' ) ;
5972
6073 if ( options . replaceConfig ) {
61- const filename = 'tailwind.config.js' ;
62- delete api . generator . files [ filename ] ;
63- const configPath = path . join ( api . generator . context , filename ) ;
74+ delete api . generator . files [ filenameTailwind ] ;
75+ const configPath = path . join ( api . generator . context , filenameTailwind ) ;
6476 try {
6577 fs . unlinkSync ( configPath ) ;
6678 } catch ( error ) {
@@ -71,6 +83,7 @@ module.exports = (api, options) => {
7183 if ( options . initConfig && options . replaceConfig !== false ) {
7284 api . onCreateComplete ( ( ) => {
7385 generateConfig ( options . initConfig ) ;
86+ injectPurgeConfig ( api . generator . context ) ;
7487 } ) ;
7588 }
7689} ;
0 commit comments