Skip to content

Commit

Permalink
feat(tailwind): add simple purge option
Browse files Browse the repository at this point in the history
* copy webpack.config.file with options
  • Loading branch information
marcjulian committed Dec 9, 2020
1 parent 338ea0d commit a6e309b
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 46 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
src/**/*.js
src/**/*.js.map
src/**/*.d.ts
!src/**/templates/**/*.js
!src/**/files/**/*.js

# IDEs
.idea/
Expand Down
2 changes: 1 addition & 1 deletion angular-workspace/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module.exports = {
purge: ['src/app/**/*.html'],
purge: ['./src/**/*.{html,ts}'],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
Expand Down
11 changes: 11 additions & 0 deletions src/ng-add/files/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
purge: ['./src/**/*.{html,ts}'],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ module.exports = {
module: {
rules: [
{
test: /\.css$/,
test: /\.<%= cssFormat %>$/,
loader: 'postcss-loader',
options: {
postcssOptions: {
ident: 'postcss',
syntax: 'postcss',
syntax: 'postcss<%if (cssFormat === 'scss') { %>-scss<% } %>',
plugins: [
require('postcss-import'),
require('tailwindcss'),
Expand Down
35 changes: 14 additions & 21 deletions src/ng-add/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { strings } from '@angular-devkit/core';
import {
Rule,
SchematicContext,
Expand All @@ -7,17 +8,15 @@ import {
url,
apply,
mergeWith,
template,
} from '@angular-devkit/schematics';
import { Schema } from './schema';
import {
getProjectFromWorkspace,
getProjectStyleFile,
getTargetsByBuilderName,
} from '@angular/cdk/schematics';
import {
NodePackageInstallTask,
RunSchematicTask,
} from '@angular-devkit/schematics/tasks';
import { NodePackageInstallTask } from '@angular-devkit/schematics/tasks';
import {
addPackageJsonDependency,
NodeDependencyType,
Expand Down Expand Up @@ -56,10 +55,9 @@ export function ngAdd(_options: Schema): Rule {
addDependencies(_options),
addNpmScripts(_options),
updateStyles(_options),
addWebpackConfig(_options),
generateConfigs(_options),
updateAngularJSON(_options),
install(),
tailwindInit(_options),
]);
};
}
Expand Down Expand Up @@ -140,22 +138,17 @@ function getTailwindImports(): string {
@import 'tailwindcss/utilities';\n`;
}

function tailwindInit(_options: Schema): Rule {
return (_tree: Tree, context: SchematicContext) => {
if (!_options.skipTailwindInit) {
const packageInstall = context.addTask(new NodePackageInstallTask());
context.addTask(new RunSchematicTask('tailwind-init', {}), [
packageInstall,
]);
}
return _tree;
};
}

function addWebpackConfig(options: Schema): Rule {
/**
* Generate webpack and tailwind config.
*
* @param options
*/
function generateConfigs(options: Schema): Rule {
return async (_host: Tree) => {
const sourceTemplates = url(`./templates/webpack/${options.cssFormat}`);
const sourceParametrizedTemplates = apply(sourceTemplates, []);
const sourceTemplates = url(`./files`);
const sourceParametrizedTemplates = apply(sourceTemplates, [
template({ ...options, ...strings }),
]);
return mergeWith(sourceParametrizedTemplates);
};
}
Expand Down
21 changes: 0 additions & 21 deletions src/ng-add/templates/webpack/scss/webpack.config.js

This file was deleted.

0 comments on commit a6e309b

Please sign in to comment.