Using resources.PostCSS to handle stylesheets

This commit is contained in:
Regis Philibert 2021-01-06 11:19:12 -05:00
parent 7761676dee
commit 16fc5e6d80
19 changed files with 102 additions and 6636 deletions

View File

@ -0,0 +1,7 @@
module.exports = {
plugins: [
require("postcss-import")({
path: ["/assets/ananke/css"],
})
],
};

3
config.yaml Normal file
View File

@ -0,0 +1,3 @@
module:
hugoVersion:
min: "0.79.0"

View File

@ -15,14 +15,7 @@
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
{{ end }}
{{ $stylesheet := .Site.Data.webpack_assets.app }}
{{ with $stylesheet.css }}
<link href="{{ relURL (printf "%s%s" "dist/" .) }}" rel="stylesheet">
{{ end }}
{{ range .Site.Params.custom_css }}
<link rel="stylesheet" href="{{ relURL (.) }}">
{{ end }}
{{ partial "site-style.html" . }}
{{ block "favicon" . }}
{{ partialCached "site-favicon.html" . }}

View File

@ -1,4 +1,5 @@
{{ define "main" }}
<article class="cf ph3 ph5-l pv3 pv4-l f4 tc-l center measure-wide lh-copy mid-gray">
{{ .Content }}
</article>

View File

@ -0,0 +1,10 @@
{{ with resources.Get "/ananke/css/main.css" }}
{{ $settings := dict "config" "/assets/ananke/css/postcss.config.css" }}
{{ $style := . | resources.PostCSS }}
{{ with $style }}
<link rel="stylesheet" href="{{ .RelPermalink }}">
{{ end }}
{{ end }}
{{ range .Site.Params.custom_css }}
<link rel="stylesheet" href="{{ relURL (.) }}">
{{ end }}

34
package.hugo.json Normal file
View File

@ -0,0 +1,34 @@
{
"name": "gohugo-theme-ananke",
"version": "2.7.0",
"description": "Base Theme to start Hugo Sites",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/theNewDynamic/gohugo-theme-ananke.git"
},
"scripts": {
"version": "auto-changelog -p --template keepachangelog --commit-limit 0 && git add CHANGELOG.md"
},
"keywords": [
"hugo",
"gohugo"
],
"author": "budparr",
"license": "MIT",
"bugs": {
"url": "https://github.com/theNewDynamic/gohugo-theme-ananke/issues"
},
"homepage": "https://github.com/theNewDynamic/gohugo-theme-ananke#readme",
"devDependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-env": "^1.4.0",
"cssnano": "^3.10.0",
"postcss-cli": "^7.1.0",
"postcss-import": "^12.0.1",
"postcss-cssnext": "^2.10.0",
"tachyons": "^4.9.1",
"auto-changelog": "^1.16.1"
}
}

View File

@ -1,26 +1,49 @@
{
"name": "gohugo-default-theme",
"version": "2.6.1",
"author": "budparr",
"bugs": {
"url": "https://github.com/theNewDynamic/gohugo-theme-ananke/issues"
},
"comments": {
"dependencies": {},
"devDependencies": {
"auto-changelog": "project",
"babel-core": "project",
"babel-loader": "project",
"babel-preset-env": "project",
"cssnano": "project",
"postcss-cli": "project",
"postcss-cssnext": "project",
"postcss-import": "project",
"tachyons": "project"
}
},
"dependencies": {},
"description": "Base Theme to start Hugo Sites",
"main": "index.js",
"repository": {
"type": "git",
"url": "git+https://github.com/theNewDynamic/thenewdynamic.com.git"
},
"scripts": {
"version": "auto-changelog -p --template keepachangelog --commit-limit 0 && git add CHANGELOG.md"
"devDependencies": {
"auto-changelog": "^1.16.1",
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-env": "^1.4.0",
"cssnano": "^3.10.0",
"postcss-cli": "^7.1.0",
"postcss-cssnext": "^2.10.0",
"postcss-import": "^12.0.1",
"tachyons": "^4.9.1"
},
"homepage": "https://github.com/theNewDynamic/gohugo-theme-ananke#readme",
"keywords": [
"hugo",
"gohugo"
],
"author": "budparr",
"license": "MIT",
"bugs": {
"url": "https://github.com/theNewDynamic/thenewdynamic.com/issues"
"main": "index.js",
"name": "gohugo-theme-ananke",
"repository": {
"type": "git",
"url": "git+https://github.com/theNewDynamic/gohugo-theme-ananke.git"
},
"homepage": "https://github.com/theNewDynamic/thenewdynamic.com#readme",
"devDependencies": {
"auto-changelog": "^1.16.1"
}
"scripts": {
"version": "auto-changelog -p --template keepachangelog --commit-limit 0 \u0026\u0026 git add CHANGELOG.md"
},
"version": "2.7.0"
}

View File

@ -1,8 +0,0 @@
module.exports = {
plugins: {
'postcss-import': {},
'postcss-cssnext': {
browsers: ['last 2 versions', '> 5%'],
}
}
};

View File

@ -1,16 +0,0 @@
import styles from './../css/main.css';
// NOTE: TO use Jquery, just call the modules you want
// var $ = require('jquery/src/core');
// require('jquery/src/core/init');
// require('jquery/src/manipulation');
// OR, use all of them
// var $ = require('jquery/src/jquery');
// And write your code
// $('body').append('<p>Jquery is working</p>');
//
// You can also "require" any script from its location in the node modules folder. Webpack often knows what to look for, but you can add a script directly like this:
// var javascriptthingy = require('name/folder/file.js');

6453
src/package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -1,32 +0,0 @@
{
"name": "gohugo-default-styles",
"version": "1.0.0",
"description": "Default Theme for Hugo Sites",
"main": "index.js",
"repository": "",
"author": "budparr",
"license": "MIT",
"scripts": {
"build:production": "rm -rf ../static/dist && webpack -p",
"build": "webpack --progress --colors --watch",
"start": "npm run build"
},
"devDependencies": {
"assets-webpack-plugin": "^3.9.10",
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-env": "^1.4.0",
"css-loader": "^0.28.0",
"cssnano": "^3.10.0",
"extract-text-webpack-plugin": "^2.1.0",
"file-loader": "^0.11.1",
"postcss": "^5.2.16",
"postcss-cssnext": "^2.10.0",
"postcss-import": "^9.1.0",
"postcss-loader": "^1.3.3",
"style-loader": "^0.16.1",
"tachyons": "^4.9.1",
"webpack": "^2.3.3"
},
"dependencies": {}
}

View File

@ -1,39 +0,0 @@
## Welcome to the SRC folder for the Gohugo Ananke Theme.
The contents of this folder are used to generate CSS and javascript. You may never have to touch anything here, unless you want to more deeply customize your styles.
## Tools
### Yarn
We use [Yarn](https://yarnpkg.com) for package managment (instead of NPM) because it's fast and generates a lock file to make dependency management more consistent. The theme's `.gitignore` file should be kept intact to make sure that all files in the `node_modules` folder are not pushed to the repository.
### Webpack
We use Webpack to manage our asset pipeline. Arguably, Webpack is overkill for this use-case, but we're using it here because once it's set up (which we've done for you), it's really easy to use. If you want to use an external script, just add it via Yarn, and reference it in main.js. You'll find instructions in the js/main.js file.
### PostCSS
PostCSS is just CSS. You'll find `postcss.config.js` in the css folder. There you'll find that we're using [`postcss-import`](https://github.com/postcss/postcss-import) which allows us import css files directly from the node_modules folder, [`postcss-cssnext`](http://cssnext.io/features/) which gives us the power to use upcoming CSS features today. If you miss Sass you can find PostCss modules for those capabilities, too.
### Tachyons
This theme uses the [Tachyons CSS Library](http://tachyons.io/). It's about 15kb gzipped, highly modular, and each class is atomic so you never have to worry about overwriting your styles. It's a great library for themes because you can make most all the style changes you need right in your layouts.
## How to Use
You'll find the commands to run in `src/package.json`.
For development, you'll need Node and Yarn installed:
```
$ cd themes/gohugo-theme-ananke/src/
$ yarn install
$ npm start
```
This will process both the postcss and scripts.
For production, instead of `npm start`, run `npm run build:production,` which will output minified versions of your files.

View File

@ -1,57 +0,0 @@
var path = require('path');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var webpack = require('webpack');
var AssetsPlugin = require('assets-webpack-plugin');
module.exports = {
entry: {
app: './js/main.js'
},
module: {
rules: [
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: ['env']
}
}
},
{
test: /\.css$/,
use: ExtractTextPlugin.extract({
fallback: 'style-loader',
use: 'css-loader?importLoaders=1!postcss-loader'
})
}
]
},
output: {
path: path.join(__dirname, './../static/dist'),
filename: 'js/[name].[chunkhash].js'
},
resolve: {
modules: [path.resolve(__dirname, 'src'), 'node_modules']
},
plugins: [
new AssetsPlugin({
filename: 'webpack_assets.json',
path: path.join(__dirname, '../data'),
prettyPrint: true
}),
new ExtractTextPlugin({
filename: getPath => {
return getPath('css/[name].[contenthash].css');
},
allChunks: true
})
],
watchOptions: {
watch: true
}
};