Skip to content

Support js in .hbs files#34

Open
Wishez wants to merge 4 commits intotaymyr:mainfrom
Wishez:support-js
Open

Support js in .hbs files#34
Wishez wants to merge 4 commits intotaymyr:mainfrom
Wishez:support-js

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-а + запустил их на прекоммите

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