add frontend
This commit is contained in:
parent
ab83a53cf5
commit
d120c12cca
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
|||||||
**/.direnv
|
**/.direnv
|
||||||
**/result
|
**/result
|
||||||
**/result-*
|
**/result-*
|
||||||
|
**/.gup
|
||||||
|
|
||||||
.stack-work
|
.stack-work
|
||||||
|
|
||||||
|
|||||||
@ -16,7 +16,7 @@ cache:
|
|||||||
pages:
|
pages:
|
||||||
stage: deploy
|
stage: deploy
|
||||||
script: &build-script
|
script: &build-script
|
||||||
- nix develop -c stack run site -- build
|
- nix develop -c gup public
|
||||||
artifacts:
|
artifacts:
|
||||||
paths:
|
paths:
|
||||||
- public
|
- public
|
||||||
|
|||||||
@ -69,6 +69,8 @@
|
|||||||
"
|
"
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
yarn
|
||||||
|
gup
|
||||||
];
|
];
|
||||||
shellHook = ''
|
shellHook = ''
|
||||||
${config.pre-commit.installationScript}
|
${config.pre-commit.installationScript}
|
||||||
@ -81,9 +83,6 @@
|
|||||||
fourmolu.enable = true;
|
fourmolu.enable = true;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
packages = {
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@ -1 +1,3 @@
|
|||||||
indentation: 2
|
indentation: 2
|
||||||
|
|
||||||
|
indent-wheres: true
|
||||||
|
|||||||
2
frontend/.gitignore
vendored
Normal file
2
frontend/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
node_modules
|
||||||
|
dist
|
||||||
5
frontend/dist.gup
Normal file
5
frontend/dist.gup
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
gup --always
|
||||||
|
rm -rf dist
|
||||||
|
yarn run build
|
||||||
27
frontend/package.json
Normal file
27
frontend/package.json
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"name": "my-webpack-project",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"main": "index.js",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {},
|
||||||
|
"scripts": {
|
||||||
|
"build": "webpack"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@webpack-cli/generators": "^3.0.4",
|
||||||
|
"autoprefixer": "^10.4.14",
|
||||||
|
"css-loader": "^6.7.3",
|
||||||
|
"js-yaml": "^4.1.0",
|
||||||
|
"mini-css-extract-plugin": "^2.7.5",
|
||||||
|
"postcss": "^8.4.23",
|
||||||
|
"postcss-loader": "^7.3.0",
|
||||||
|
"prettier": "^2.8.8",
|
||||||
|
"sass": "^1.62.1",
|
||||||
|
"sass-loader": "^13.2.2",
|
||||||
|
"style-loader": "^3.3.2",
|
||||||
|
"webpack": "^5.82.1",
|
||||||
|
"webpack-cli": "^5.1.1",
|
||||||
|
"webpack-manifest-plugin": "^5.0.0",
|
||||||
|
"webpack-remove-empty-scripts": "^1.0.3"
|
||||||
|
}
|
||||||
|
}
|
||||||
5
frontend/postcss.config.js
Normal file
5
frontend/postcss.config.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
module.exports = {
|
||||||
|
// Add you postcss configuration here
|
||||||
|
// Learn more about it at https://github.com/webpack-contrib/postcss-loader#config-files
|
||||||
|
plugins: [["autoprefixer"]],
|
||||||
|
};
|
||||||
1
frontend/src/index.js
Normal file
1
frontend/src/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
import './main.sass';
|
||||||
2
frontend/src/main.sass
Normal file
2
frontend/src/main.sass
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
.red
|
||||||
|
color: red
|
||||||
70
frontend/webpack.config.js
Normal file
70
frontend/webpack.config.js
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
// Generated using webpack-cli https://github.com/webpack/webpack-cli
|
||||||
|
|
||||||
|
const path = require("path");
|
||||||
|
const { WebpackManifestPlugin } = require('webpack-manifest-plugin');
|
||||||
|
const MiniCssExtractPlugin = require("mini-css-extract-plugin");
|
||||||
|
const RemoveEmptyScriptsPlugin = require('webpack-remove-empty-scripts');
|
||||||
|
const yaml = require('js-yaml');
|
||||||
|
|
||||||
|
const stylesHandler = MiniCssExtractPlugin.loader;
|
||||||
|
|
||||||
|
const webpackVersion = require('webpack/package.json').version.split('.').slice(0, 2).join('.');
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
mode: 'production',
|
||||||
|
devtool: 'source-map',
|
||||||
|
entry: {
|
||||||
|
main: [ path.resolve(__dirname, "src", "index.js")
|
||||||
|
]
|
||||||
|
},
|
||||||
|
output: {
|
||||||
|
chunkFilename: '[chunkhash].js',
|
||||||
|
filename: '[chunkhash].js',
|
||||||
|
path: path.resolve(__dirname, 'dist', `wp-${webpackVersion}`),
|
||||||
|
publicPath: `/wp-${webpackVersion}/`,
|
||||||
|
hashFunction: 'shake256',
|
||||||
|
hashDigestLength: 36
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
new WebpackManifestPlugin({
|
||||||
|
fileName: path.resolve(__dirname, 'dist', '.manifest.yaml'),
|
||||||
|
publicPath: `/wp-${webpackVersion}/`,
|
||||||
|
generate: (seed, files, entrypoints) => Object.keys(entrypoints).reduce((acc, fs) => ({...acc, [fs]: files.filter(file => entrypoints[fs].filter(basename => !(/\.map$/.test(basename))).some(basename => file.path.endsWith(basename))).filter(file => file.isInitial).map(file => file.path)}), {}),
|
||||||
|
serialize: yaml.dump
|
||||||
|
}),
|
||||||
|
|
||||||
|
new MiniCssExtractPlugin({
|
||||||
|
filename: '[chunkhash].css',
|
||||||
|
chunkFilename: '[chunkhash].css',
|
||||||
|
}),
|
||||||
|
|
||||||
|
new RemoveEmptyScriptsPlugin({
|
||||||
|
extensions: /\.(js|css|scss|sass|less|styl)([?].*)?$/
|
||||||
|
}),
|
||||||
|
|
||||||
|
// Add your plugins here
|
||||||
|
// Learn more about plugins from https://webpack.js.org/configuration/plugins/
|
||||||
|
],
|
||||||
|
|
||||||
|
module: {
|
||||||
|
rules: [
|
||||||
|
{
|
||||||
|
test: /\.s[ac]ss$/i,
|
||||||
|
use: [stylesHandler, "css-loader", "postcss-loader", "sass-loader"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.css$/i,
|
||||||
|
use: [stylesHandler, "css-loader", "postcss-loader"],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i,
|
||||||
|
type: "asset",
|
||||||
|
},
|
||||||
|
|
||||||
|
// Add your rules for custom modules here
|
||||||
|
// Learn more about loaders from https://webpack.js.org/loaders/
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
module.exports = config;
|
||||||
3715
frontend/yarn.lock
Normal file
3715
frontend/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
@ -5,6 +5,10 @@ default-extensions:
|
|||||||
- OverloadedStrings
|
- OverloadedStrings
|
||||||
- NoImplicitPrelude
|
- NoImplicitPrelude
|
||||||
- ViewPatterns
|
- ViewPatterns
|
||||||
|
- DerivingStrategies
|
||||||
|
- DeriveGeneric
|
||||||
|
- GeneralizedNewtypeDeriving
|
||||||
|
- TypeApplications
|
||||||
|
|
||||||
executables:
|
executables:
|
||||||
site:
|
site:
|
||||||
@ -26,3 +30,6 @@ executables:
|
|||||||
- base
|
- base
|
||||||
- hakyll
|
- hakyll
|
||||||
- filepath
|
- filepath
|
||||||
|
- yaml
|
||||||
|
- containers
|
||||||
|
- Glob
|
||||||
|
|||||||
6
public.gup
Normal file
6
public.gup
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env sh
|
||||||
|
|
||||||
|
gup --always
|
||||||
|
gup -u frontend/dist
|
||||||
|
|
||||||
|
stack run site -- rebuild
|
||||||
35
src/Main.hs
35
src/Main.hs
@ -7,6 +7,14 @@ import Hakyll
|
|||||||
import qualified Data.List as List
|
import qualified Data.List as List
|
||||||
import Data.Maybe
|
import Data.Maybe
|
||||||
import System.FilePath
|
import System.FilePath
|
||||||
|
import qualified System.FilePath.Glob as Glob
|
||||||
|
|
||||||
|
import qualified Data.Yaml as Yaml
|
||||||
|
|
||||||
|
import Data.Map (Map)
|
||||||
|
import qualified Data.Map as Map
|
||||||
|
|
||||||
|
import Control.Monad
|
||||||
|
|
||||||
config :: Configuration
|
config :: Configuration
|
||||||
config =
|
config =
|
||||||
@ -25,11 +33,36 @@ main = hakyllWith config $ do
|
|||||||
route idRoute
|
route idRoute
|
||||||
compile copyFileCompiler
|
compile copyFileCompiler
|
||||||
|
|
||||||
|
frontendManifest <-
|
||||||
|
preprocess $
|
||||||
|
Yaml.decodeFileThrow @_ @(Map String [FilePath]) "frontend/dist/.manifest.yaml"
|
||||||
|
|
||||||
match "content/index.html" $ do
|
match "content/index.html" $ do
|
||||||
route $ stripPathPrefix "content"
|
route $ stripPathPrefix "content"
|
||||||
|
|
||||||
|
let context =
|
||||||
|
defaultContext
|
||||||
|
<> cssContext
|
||||||
|
|
||||||
|
cssContext = listField "css" innerContext genCSSItems
|
||||||
|
where
|
||||||
|
innerContext = urlField "url"
|
||||||
|
genCSSItems = genManifestItems $ Glob.compile "**/*.css"
|
||||||
|
|
||||||
|
genManifestItems :: Glob.Pattern -> Compiler [Item CopyFile]
|
||||||
|
genManifestItems p = do
|
||||||
|
let entryPoint = "main"
|
||||||
|
resources = filter (Glob.match p) $ frontendManifest Map.! entryPoint
|
||||||
|
forM resources $ load . fromFilePath . ("frontend/dist" </>) . dropDrive
|
||||||
|
|
||||||
compile $ do
|
compile $ do
|
||||||
getResourceBody
|
getResourceBody
|
||||||
>>= loadAndApplyTemplate "templates/site-layout.html" defaultContext
|
>>= loadAndApplyTemplate "templates/site-layout.html" context
|
||||||
|
>>= relativizeUrls
|
||||||
|
|
||||||
|
match "frontend/dist/wp-*/**" $ do
|
||||||
|
route $ stripPathPrefix "frontend/dist"
|
||||||
|
|
||||||
|
compile copyFileCompiler
|
||||||
|
|
||||||
match "templates/*" $ compile templateBodyCompiler
|
match "templates/*" $ compile templateBodyCompiler
|
||||||
|
|||||||
@ -4,6 +4,9 @@
|
|||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
$for(css)$
|
||||||
|
<link rel="stylesheet" href="$url$">
|
||||||
|
$endfor$
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user