Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support js in .hbs files #34

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Support js in .hbs files #34

wants to merge 4 commits into from

Conversation

Wishez
Copy link
Contributor

@Wishez Wishez commented Jan 13, 2023

No description provided.

@@ -0,0 +1,9 @@
yarn lint-staged --allow-empty
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил линтеры ямл, ts-а и js-а + запустил их на прекоммите

@@ -15,7 +15,7 @@ ui:

output:
clean: false
dir: build/site
dir: build/site/en
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

поднастроил тут, чтобы файлики по категории локали всё же были)

import type { Compiler } from 'webpack'
import { spawnCommand } from '../helpers/spawnCommand'

export class BuildAntoraPlugin {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Добавил плагин, который билдит антору после компиляции сборки и после делает форсированное обновления в браузере

// Compiler's webpack annotations are incompatible in types package:(
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
import ZipPlugin from 'zip-webpack-plugin'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

не получилось тут подтянуть типы, х его з почему)

@@ -0,0 +1,87 @@
// eslint-disable-next-line import/default
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Разделил файлики на разную конфигурацию. common — общая конфигурация, dev - при разработке, prod - при продакшене

чтобы запустить разные сборки, нужно выполнить команды

npm start - dev
npm run build - prod

import { getDirectoryFileNames } from './helpers'

const bundleName = 'ui-bundle'
const buildingScripts = getDirectoryFileNames(path.resolve(Env.cwd, './src/scripts')).reduce<
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

скрипты положил в отдельную папочку и компилирую их отдельным энтрипоинтом, чтобы потом подключить шаблон (смотри следующий коммент)

fileName: 'partials/body-local-scripts.hbs',
filterKey: 'tagName',
filterValue: 'script',
filterByTagNode: filterInjectingScriptByScriptNames(['highlight.js', 'main.js']),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тут настроил темплейт body-local-scripts, который будет содержать в себе указанные в массиве скрипты. сам шаблон работает для каждой страницы

по сути, можно будет создавать partials указывая им нужные скрипты из папки script и инжектить их в любые layouts

const config = merge<WebpackOptionsNormalized | Configuration>(commonConfig, {
mode: 'development',
target: 'web',
devServer: {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавил дев сервер с хотрелодом

@@ -0,0 +1,9 @@
<footer>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

добавил примерчик, чтобы протестить корректонсть работы скрипта:)

@@ -0,0 +1,32 @@
{
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

затащил ts, но не для обычных скриптов, в целом можно включить его и для них)

@Wishez Wishez mentioned this pull request Jan 13, 2023
@Wishez Wishez changed the title Support js Support js in .hbs files Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant