HUGO

  • Новости
  • Документация
  • Темы
  • Витрина
  • Сообщество
  • GitHub
  • Telegram
Star
ASSET MANAGEMENT

Babel

Hugo Pipes can process JS files with Babel.

Any JavaScript resource file can be transpiled to another JavaScript version using resources.Babel which takes for argument the resource object and an optional dict of options listed below. Babel uses the babel cli.

Hugo Pipe’s Babel requires the @babel/cli and @babel/core JavaScript packages to be installed in the project or globally (npm install -g @babel/cli @babel/core) along with any Babel plugin(s) or preset(s) used (e.g., npm install @babel/preset-env --save-dev).

If you are using the Hugo Snap package, Babel and plugin(s) need to be installed locally within your Hugo site directory, e.g., npm install @babel/cli @babel/core --save-dev without the -g flag.

Config

In Hugo v0.75 we improved the way we resolve JS configuration and dependencies. One of them is that we now add the main project’s node_modules to NODE_PATH when running Babel and similar tools. There are some known issues with Babel in this area, so if you have a babel.config.js living in a Hugo Module (and not in the project itself), we recommend using require to load the presets/plugins, e.g.:

module.exports = {
        presets: [
                [
                        require('@babel/preset-env'),
                        {
                                useBuiltIns: 'entry',
                                corejs: 3
                        }
                ]
        ]
};

Options

config [string]
Path to the Babel configuration file. Hugo will, by default, look for a babel.config.js in your project. More information on these configuration files can be found here: babel configuration.
minified [bool]
Save as much bytes as possible when printing
noComments [bool]
Write comments to generated output (true by default)
compact [bool]
Do not include superfluous whitespace characters and line terminators. Defaults to auto if not set.
verbose [bool]
Log everything

Examples

{{- $transpiled := resources.Get "scripts/main.js" | babel  -}}

Or with options:

{{ $opts := dict "noComments" true }}
{{- $transpiled := resources.Get "scripts/main.js" | babel $opts -}}
  • О Хьюго
    • Обзор
    • Модель безопасности Хьюго
    • Hugo и GDPR
    • Что такое Хьюго
    • Функции Хьюго
    • Преимущества статики
    • Лицензия
  • С чего начать
    • Обзор начала работы
    • Быстрый старт
    • Установка Хьюго
    • Основы использования
    • Структура каталогов
    • Настройка
    • Внешние ресурсы обучения
  • Модули Хьюго
    • Обзор модулей Hugo
    • Настройка модулей
    • Использование модулей Hugo
    • Компоненты темы
  • Управление контентом
    • Обзор управления контентом
    • Организация
    • Пакеты страниц
    • Форматы контента
    • Front Matter
    • Page Resources
    • Параметры сборки
    • Обработка изображений
    • Шорткоды
    • Связанный контент
    • Разделы
    • Типы контента
    • Архетипы
    • Таксономии
    • Содержание
    • Ссылки и перекрестные ссылки
    • Управление URL-адресами
    • Меню
    • Статические файлы
    • Комментарии
    • Многоязычный и i18n
    • Подсветка синтаксиса
  • Templates
    • Templates Overview
    • Introduction
    • Template Lookup Order
    • Custom Output Formats
    • Base Templates and Blocks
    • List Page Templates
    • Homepage Template
    • Section Templates
    • Taxonomy Templates
    • Single Page Templates
    • Content View Templates
    • Data Templates
    • Partial Templates
    • Shortcode Templates
    • Local File Templates
    • 404 Page
    • Menu Templates
    • Pagination
    • RSS Templates
    • Sitemap Template
    • Robots.txt
    • Internal Templates
    • Alternative Templating
    • Template Debugging
  • Functions
    • Functions Quick Reference
    • .AddDate
    • .Format
    • .Get
    • .GetPage
    • .HasMenuCurrent
    • .IsMenuCurrent
    • .Param
    • .Render
    • .RenderString
    • .Scratch
    • .Unix
    • absLangURL
    • absURL
    • after
    • anchorize
    • append
    • apply
    • base64
    • chomp
    • complement
    • cond
    • countrunes
    • countwords
    • dateFormat
    • default
    • delimit
    • dict
    • echoParam
    • emojify
    • eq
    • errorf and warnf
    • fileExists
    • findRE
    • first
    • float
    • ge
    • getenv
    • group
    • gt
    • hasPrefix
    • highlight
    • hmac
    • htmlEscape
    • htmlUnescape
    • hugo
    • humanize
    • i18n
    • Image Functions
    • in
    • index
    • int
    • intersect
    • isset
    • jsonify
    • lang.Merge
    • lang.NumFmt
    • last
    • le
    • len
    • lower
    • lt
    • markdownify
    • Math
    • md5
    • merge
    • ne
    • now
    • os.Stat
    • partialCached
    • path.Base
    • path.Dir
    • path.Ext
    • path.Join
    • path.Split
    • plainify
    • pluralize
    • print
    • printf
    • println
    • querify
    • range
    • readDir
    • readFile
    • ref
    • reflect.IsMap
    • reflect.IsSlice
    • relLangURL
    • relref
    • relURL
    • replace
    • replaceRE
    • safeCSS
    • safeHTML
    • safeHTMLAttr
    • safeJS
    • safeURL
    • seq
    • sha
    • shuffle
    • singularize
    • slice
    • slicestr
    • sort
    • split
    • string
    • strings.Count
    • strings.HasSuffix
    • strings.Repeat
    • strings.RuneCount
    • strings.TrimLeft
    • strings.TrimPrefix
    • strings.TrimRight
    • strings.TrimSuffix
    • substr
    • symdiff
    • templates.Exists
    • time
    • title
    • transform.Unmarshal
    • trim
    • truncate
    • union
    • uniq
    • upper
    • urlize
    • urls.Parse
    • where
    • with
  • Variables
    • Variables Overview
    • Site Variables
    • Page Variables
    • Shortcode Variables
    • Pages Methods
    • Taxonomy Variables
    • File Variables
    • Menu Entry Properties
    • Hugo Variables
    • Git Variables
    • Sitemap Variables
  • Hugo Pipes
    • Hugo Pipes Overview
    • Hugo Pipes Introduction
    • SASS / SCSS
    • PostProcess
    • PostCSS
    • JavaScript Building
    • Babel
    • Asset minification
    • Asset bundling
    • Fingerprinting and SRI
    • Resource from Template
    • Resource from String
  • CLI
  • Troubleshooting
    • Troubleshoot
    • FAQ
    • Build Performance
  • Tools
    • Developer Tools Overview
    • Migrations
    • Starter Kits
    • Frontends
    • Editor Plug-ins
    • Search
    • Other Projects
  • Hosting & Deployment
    • Hosting & Deployment Overview
    • Hugo Deploy
    • Host-Agnostic Deploys with Nanobox
    • Host on AWS Amplify
    • Host on Netlify
    • Host on Render
    • Host on Firebase
    • Host on GitHub
    • Host on GitLab
    • Hosting on KeyCDN
    • Host on Bitbucket
    • Deployment with Wercker
    • Deployment with Rsync
  • Contribute
    • Contribute to Hugo
    • Development
    • Documentation
    • Themes
  • Maintenance
“Babel” последнее обновление: December 24, 2020: Добавил папку для перевода RU (5edbf8359)
Улучшить эту страницу
Авторы Hugo
Hugo Logo
  • Подать вопрос
  • Получить помощь
  • Обсудить исходный код
  • @GoHugoIO
  • @spf13
  • @bepsays
 
 

Спонсоры Hugo

Logo for Forestry.io
Logo for Linode
Logo for eSolia
 

Авторские права на логотипы Hugo принадлежат © Steve Francia 2013–2021.

Hugo Gopher основан на оригинальной работе Renée French.

  • Новости
  • Документация
  • Темы
  • Витрина
  • Сообщество
  • GitHub
  • Telegram
  • О Хьюго
  • С чего начать
  • Модули Хьюго
  • Управление контентом
  • Templates
  • Functions
  • Variables
  • Hugo Pipes
  • CLI
  • Troubleshooting
  • Tools
  • Hosting & Deployment
  • Contribute
  • Maintenance