This commit is contained in:
Adam Wathan 2020-11-18 12:42:00 -05:00
parent fadd4c89a0
commit 83b16e5359
4 changed files with 210 additions and 19 deletions

View file

@ -51,10 +51,6 @@
"prettier": "^2.1.2",
"rimraf": "^3.0.0"
},
"peerDependencies": {
"autoprefixer": "^10.0.2",
"postcss": "^8.0.9"
},
"dependencies": {
"@fullhuman/postcss-purgecss": "^3.0.0",
"bytes": "^3.0.0",
@ -69,13 +65,15 @@
"node-emoji": "^1.8.1",
"object-hash": "^2.0.3",
"postcss-functions": "^3",
"postcss-js": "^3.0.3",
"postcss-nested": "^5.0.1",
"postcss-js": "^2",
"postcss-nested": "^4",
"postcss-selector-parser": "^6.0.4",
"postcss-value-parser": "^4.1.0",
"pretty-hrtime": "^1.0.3",
"reduce-css-calc": "^2.1.6",
"resolve": "^1.19.0"
"resolve": "^1.19.0",
"autoprefixer": "^9",
"postcss": "^7"
},
"browserslist": [
"> 1%",
@ -109,4 +107,4 @@
"engines": {
"node": ">=12.13.0"
}
}
}

112
package.postcss8.json Normal file
View file

@ -0,0 +1,112 @@
{
"name": "tailwindcss",
"version": "2.0.0",
"description": "A utility-first CSS framework for rapidly building custom user interfaces.",
"license": "MIT",
"main": "lib/index.js",
"style": "dist/tailwind.css",
"repository": "https://github.com/tailwindlabs/tailwindcss.git",
"bugs": "https://github.com/tailwindlabs/tailwindcss/issues",
"homepage": "https://tailwindcss.com",
"bin": {
"tailwind": "lib/cli.js",
"tailwindcss": "lib/cli.js"
},
"contributors": [
"Adam Wathan <adam.wathan@gmail.com>",
"Jonathan Reinink <jonathan@reinink.ca>",
"David Hemphill <davidlee.hemphill@gmail.com>"
],
"scripts": {
"prebabelify": "rimraf lib",
"babelify": "babel src --out-dir lib --copy-files",
"rebuild-fixtures": "npm run babelify && babel-node scripts/rebuildFixtures.js",
"prepublishOnly": "npm run babelify && babel-node scripts/build.js",
"style": "eslint .",
"test": "jest && eslint .",
"compat": "node scripts/compat.js --prepare",
"compat:restore": "node scripts/compat.js --restore"
},
"files": [
"dist/*.css",
"lib/*",
"scripts/*.js",
"stubs/*.stub.js",
"*.css",
"*.js"
],
"devDependencies": {
"@babel/cli": "^7.11.6",
"@babel/core": "^7.12.3",
"@babel/node": "^7.0.0",
"@babel/preset-env": "^7.0.0",
"autoprefixer": "^10.0.2",
"babel-jest": "^26.6.3",
"clean-css": "^4.1.9",
"eslint": "^7.12.1",
"eslint-config-prettier": "^6.15.0",
"eslint-plugin-prettier": "^3.1.4",
"jest": "^26.6.3",
"postcss": "^8.0.9",
"prettier": "^2.1.2",
"rimraf": "^3.0.0"
},
"peerDependencies": {
"autoprefixer": "^10.0.2",
"postcss": "^8.0.9"
},
"dependencies": {
"@fullhuman/postcss-purgecss": "^3.0.0",
"bytes": "^3.0.0",
"chalk": "^4.1.0",
"color": "^3.1.3",
"detective": "^5.2.0",
"didyoumean": "^1.2.1",
"fs-extra": "^9.0.1",
"html-tags": "^3.1.0",
"lodash": "^4.17.20",
"modern-normalize": "^1.0.0",
"node-emoji": "^1.8.1",
"object-hash": "^2.0.3",
"postcss-functions": "^3",
"postcss-js": "^3.0.3",
"postcss-nested": "^5.0.1",
"postcss-selector-parser": "^6.0.4",
"postcss-value-parser": "^4.1.0",
"pretty-hrtime": "^1.0.3",
"reduce-css-calc": "^2.1.6",
"resolve": "^1.19.0"
},
"browserslist": [
"> 1%",
"not edge <= 18",
"not ie 11",
"not op_mini all"
],
"babel": {
"presets": [
[
"@babel/preset-env",
{
"targets": {
"node": "12.13.0"
}
}
]
]
},
"jest": {
"collectCoverage": true,
"testTimeout": 30000,
"setupFilesAfterEnv": [
"<rootDir>/jest/customMatchers.js"
],
"testPathIgnorePatterns": [
"<rootDir>/__tests__/fixtures/",
"<rootDir>/__tests__/util/"
]
},
"engines": {
"node": ">=12.13.0"
}
}

View file

@ -2,6 +2,7 @@ import path from 'path'
import fs from 'fs'
import _ from 'lodash'
import postcss from 'postcss'
import getModuleDependencies from './lib/getModuleDependencies'
import registerConfigAsDependency from './lib/registerConfigAsDependency'
@ -62,7 +63,7 @@ const getConfigFunction = (config) => () => {
return resolveConfig([...getAllConfigs(configObject)])
}
module.exports = function (config) {
const plugin = postcss.plugin('tailwindcss', (config) => {
const plugins = []
const resolvedConfigPath = resolveConfigPath(config)
@ -70,14 +71,11 @@ module.exports = function (config) {
plugins.push(registerConfigAsDependency(resolvedConfigPath))
}
return {
postcssPlugin: 'tailwindcss',
plugins: [
...plugins,
processTailwindFeatures(getConfigFunction(resolvedConfigPath || config)),
formatCSS,
],
}
}
return postcss([
...plugins,
processTailwindFeatures(getConfigFunction(resolvedConfigPath || config)),
formatCSS,
])
})
module.exports.postcss = true
module.exports = plugin

83
src/index.postcss8.js Normal file
View file

@ -0,0 +1,83 @@
import path from 'path'
import fs from 'fs'
import _ from 'lodash'
import getModuleDependencies from './lib/getModuleDependencies'
import registerConfigAsDependency from './lib/registerConfigAsDependency'
import processTailwindFeatures from './processTailwindFeatures'
import formatCSS from './lib/formatCSS'
import resolveConfig from './util/resolveConfig'
import getAllConfigs from './util/getAllConfigs'
import { defaultConfigFile } from './constants'
import defaultConfig from '../stubs/defaultConfig.stub.js'
function resolveConfigPath(filePath) {
// require('tailwindcss')({ theme: ..., variants: ... })
if (_.isObject(filePath) && !_.has(filePath, 'config') && !_.isEmpty(filePath)) {
return undefined
}
// require('tailwindcss')({ config: 'custom-config.js' })
if (_.isObject(filePath) && _.has(filePath, 'config') && _.isString(filePath.config)) {
return path.resolve(filePath.config)
}
// require('tailwindcss')({ config: { theme: ..., variants: ... } })
if (_.isObject(filePath) && _.has(filePath, 'config') && _.isObject(filePath.config)) {
return undefined
}
// require('tailwindcss')('custom-config.js')
if (_.isString(filePath)) {
return path.resolve(filePath)
}
// require('tailwindcss')
try {
const defaultConfigPath = path.resolve(defaultConfigFile)
fs.accessSync(defaultConfigPath)
return defaultConfigPath
} catch (err) {
return undefined
}
}
const getConfigFunction = (config) => () => {
if (_.isUndefined(config)) {
return resolveConfig([...getAllConfigs(defaultConfig)])
}
// Skip this if Jest is running: https://github.com/facebook/jest/pull/9841#issuecomment-621417584
if (process.env.JEST_WORKER_ID === undefined) {
if (!_.isObject(config)) {
getModuleDependencies(config).forEach((mdl) => {
delete require.cache[require.resolve(mdl.file)]
})
}
}
const configObject = _.isObject(config) ? _.get(config, 'config', config) : require(config)
return resolveConfig([...getAllConfigs(configObject)])
}
module.exports = function (config) {
const plugins = []
const resolvedConfigPath = resolveConfigPath(config)
if (!_.isUndefined(resolvedConfigPath)) {
plugins.push(registerConfigAsDependency(resolvedConfigPath))
}
return {
postcssPlugin: 'tailwindcss',
plugins: [
...plugins,
processTailwindFeatures(getConfigFunction(resolvedConfigPath || config)),
formatCSS,
],
}
}
module.exports.postcss = true