Skip to content

Commit 3901c90

Browse files
authored
Merge pull request #5 from forsartis/next
1.0.0
2 parents 41a8364 + d3b20ad commit 3901c90

File tree

6 files changed

+111
-87
lines changed

6 files changed

+111
-87
lines changed

README.md

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,66 @@
22
[![Tailwind CSS](https://img.shields.io/npm/dependency-version/vue-cli-plugin-tailwind/tailwindcss.svg)](https://tailwindcss.com/)
33
[![License](https://img.shields.io/npm/l/vue-cli-plugin-tailwind.svg)](https://github.com/forsartis/vue-cli-plugin-tailwind/blob/master/LICENSE)
44

5+
A plugin that adds Tailwind CSS and Purgecss to your vue-cli project.
56

67
## Getting started
7-
88
Inside your vue-cli project folder add the plugin via:
99
```
1010
vue add tailwind
1111
```
12+
Choose what Tailwind config you want to generate:
13+
* **none** - Won't create a config file. Useful if you already have a config or you don't need to change Tailwinds default styles.
14+
* **minimal** *(default)* - Will create a minimal `tailwind.config.js` file where you can define your customizations.
15+
* **full** - Will generate a `tailwind.config.js` file containing the entire default configuration.
1216

13-
:warning: Check the plugins order in your PostCSS config (autoprefixer should run after tailwindcss).
17+
See [Tailwinds configuration guide](https://next.tailwindcss.com/docs/configuration) for more info.
1418

15-
## License
19+
## PostCSS Configuration
20+
Tailwind CSS and Purgecss will be added as plugins in your PostCSS config.
21+
```javascript
22+
// postcss.config.js
23+
module.exports = {
24+
plugins: {
25+
tailwindcss: {},
26+
'vue-cli-plugin-tailwind/purgecss': {},
27+
autoprefixer: {},
28+
},
29+
};
30+
```
31+
### Custom Tailwind config file name
32+
If you use a name other than `tailwind.config.js` for the Tailwind config file, you will need to specify it in your PostCSS configuration.
33+
```javascript
34+
// postcss.config.js
35+
module.exports = {
36+
plugins: {
37+
tailwindcss: 'custom-name.js',
38+
//...
39+
},
40+
};
41+
```
42+
### Configure Purgecss
43+
By default Purgecss will look for css selectors in your `.html` files inside the `./public` directory and `.vue` files inside the `./src` directory.
44+
```javascript
45+
let config = {
46+
content: ['./public/**/*.html', './src/**/*.vue'],
47+
defaultExtractor: content =>
48+
content.match(/[A-Za-z0-9-_/:]*[A-Za-z0-9-_/]+/g) || [],
49+
};
50+
```
51+
You can extend/override the default config in your PostCSS configuration.
52+
```javascript
53+
// postcss.config.js
54+
module.exports = {
55+
plugins: {
56+
tailwindcss: {},
57+
'vue-cli-plugin-tailwind/purgecss': {
58+
whitelist: ['foo', 'bar'],
59+
},
60+
autoprefixer: {},
61+
},
62+
};
63+
```
64+
Check [https://www.purgecss.com/configuration#options](https://www.purgecss.com/configuration#options) for a list of available options.
1665

66+
## License
1767
[MIT](https://github.com/forsartis/vue-cli-plugin-tailwind/blob/master/LICENSE)

generator/index.js

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,21 @@ function readPostcssConfig(generator) {
2828
return {};
2929
}
3030

31+
function generateConfig(option) {
32+
const args = ['init'];
33+
if (option === 'full') {
34+
args.push('--full');
35+
}
36+
const { spawnSync } = require('child_process');
37+
spawnSync('./node_modules/.bin/tailwind', args);
38+
}
39+
3140
module.exports = (api, options) => {
3241
const postcss = readPostcssConfig(api.generator);
3342
const configs = {
3443
postcss: {
3544
plugins: {
36-
tailwindcss: './tailwind.config.js',
45+
tailwindcss: {},
3746
'vue-cli-plugin-tailwind/purgecss': {},
3847
},
3948
},
@@ -46,8 +55,20 @@ module.exports = (api, options) => {
4655
api.injectImports(api.entryFile, `import './assets/tailwind.css'`);
4756
api.render('./template');
4857

49-
api.onCreateComplete(() => {
50-
const { spawnSync } = require('child_process');
51-
spawnSync('./node_modules/.bin/tailwind', ['init', 'tailwind.config.js']);
52-
});
58+
if (options.replaceConfig) {
59+
const filename = 'tailwind.config.js';
60+
delete api.generator.files[filename];
61+
const configPath = path.join(api.generator.context, filename);
62+
try {
63+
fs.unlinkSync(configPath);
64+
} catch (error) {
65+
throw new Error(error);
66+
}
67+
}
68+
69+
if (options.initConfig && options.replaceConfig !== false) {
70+
api.onCreateComplete(() => {
71+
generateConfig(options.initConfig);
72+
});
73+
}
5374
};
Lines changed: 1 addition & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,5 @@
1-
/**
2-
* This injects Tailwind's base styles, which is a combination of
3-
* Normalize.css and some additional base styles.
4-
*
5-
* You can see the styles here:
6-
* https://github.com/tailwindcss/tailwindcss/blob/master/css/preflight.css
7-
*
8-
* If using `postcss-import`, use this import instead:
9-
*
10-
* @import "tailwindcss/preflight";
11-
*/
12-
@tailwind preflight;
1+
@tailwind base;
132

14-
/**
15-
* This injects any component classes registered by plugins.
16-
*
17-
* If using `postcss-import`, use this import instead:
18-
*
19-
* @import "tailwindcss/components";
20-
*/
213
@tailwind components;
224

23-
/**
24-
* Here you would add any of your custom component classes; stuff that you'd
25-
* want loaded *before* the utilities so that the utilities could still
26-
* override them.
27-
*
28-
* Example:
29-
*
30-
* .btn { ... }
31-
* .form-input { ... }
32-
*
33-
* Or if using a preprocessor or `postcss-import`:
34-
*
35-
* @import "components/buttons";
36-
* @import "components/forms";
37-
*/
38-
39-
/**
40-
* This injects all of Tailwind's utility classes, generated based on your
41-
* config file.
42-
*
43-
* If using `postcss-import`, use this import instead:
44-
*
45-
* @import "tailwindcss/utilities";
46-
*/
475
@tailwind utilities;
48-
49-
/**
50-
* Here you would add any custom utilities you need that don't come out of the
51-
* box with Tailwind.
52-
*
53-
* Example :
54-
*
55-
* .bg-pattern-graph-paper { ... }
56-
* .skew-45 { ... }
57-
*
58-
* Or if using a preprocessor or `postcss-import`:
59-
*
60-
* @import "utilities/background-patterns";
61-
* @import "utilities/skew-transforms";
62-
*/

package.json

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-cli-plugin-tailwind",
3-
"version": "0.4.3",
3+
"version": "1.0.0",
44
"description": "vue-cli plugin for Tailwind CSS",
55
"author": "Jens Eggerstedt <j.eggerstedt@kaibatech.de>",
66
"license": "MIT",
@@ -18,10 +18,7 @@
1818
"purgecss"
1919
],
2020
"dependencies": {
21-
"@fullhuman/postcss-purgecss": "^1.1.0",
22-
"tailwindcss": "^0.7.4"
23-
},
24-
"peerDependencies": {
25-
"@vue/cli-shared-utils": "^3.0.0"
21+
"@fullhuman/postcss-purgecss": "^1.2.0",
22+
"tailwindcss": "^1.0.0"
2623
}
2724
}

prompts.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const fs = require('fs');
2+
3+
module.exports = [
4+
{
5+
type: 'list',
6+
name: 'initConfig',
7+
message: 'Generate tailwind.config.js',
8+
choices: [
9+
{ name: 'none', value: false },
10+
{ name: 'minimal', value: 'minimal' },
11+
{ name: 'full', value: 'full' },
12+
],
13+
default: 1,
14+
},
15+
{
16+
name: 'replaceConfig',
17+
type: 'confirm',
18+
message: 'tailwind.config.js already exists! Do you want to replace it?',
19+
default: false,
20+
when: answers => {
21+
return answers.initConfig && fs.existsSync('./tailwind.config.js');
22+
},
23+
},
24+
];

purgecss/index.js

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,13 @@
1-
const isHotReloaded = process.argv.includes('serve');
21
const postcss = require('postcss');
32

4-
class TailwindExtractor {
5-
static extract(content) {
6-
return content.match(/[A-Za-z0-9-_:\/]+/g) || [];
7-
}
8-
}
9-
103
let config = {
11-
content: ['./public/index.html', './src/**/*.vue'],
12-
extractors: [
13-
{
14-
extractor: TailwindExtractor,
15-
extensions: ['html', 'vue'],
16-
},
17-
],
4+
content: ['./public/**/*.html', './src/**/*.vue'],
5+
defaultExtractor: content =>
6+
content.match(/[A-Za-z0-9-_/:]*[A-Za-z0-9-_/]+/g) || [],
187
};
198

209
module.exports = postcss.plugin('tailwind-purgecss', function(opts) {
21-
if (isHotReloaded) return () => {};
10+
if (process.env.NODE_ENV !== 'production') return () => {};
2211
const purgecss = require('@fullhuman/postcss-purgecss');
2312
return purgecss(Object.assign(config, opts));
2413
});

0 commit comments

Comments
 (0)