UNPKG

@zohodesk/client_build_tool

Version:

A CLI tool to build web applications and client libraries

94 lines (60 loc) 6.5 kB
## Name Template Utility Documentation The provided code snippet represents a utility module for generating name templates used in the build process of the Client Build Tool (CBT). The module contains functions for creating name templates and determining whether a file is an internationalization file. Let's document the different parts of the code: ### Import Statements ```javascript import { isDevelopmentMode, isProductionMode } from './modeUtils'; ``` This import statement brings in the `isDevelopmentMode` and `isProductionMode` functions from the `modeUtils` module. ### Templates Object The `templates` object represents a collection of different name templates used for various types of files during the build process. Each key-value pair in the object represents a file type and its corresponding name templates. ### createNameTemplate Function The `createNameTemplate` function is used to generate a name template for a specific file type based on whether a hash should be included in the file name. It takes in the `name` and `useHash` parameters and returns the appropriate name template based on the `useHash` value. ### nameTemplates Function The `nameTemplates` function is a utility function that determines the name template for a specified file type based on the provided options. It takes in the `type` and `options` parameters and returns the corresponding name template. ### isI18nFile Function The `isI18nFile` function is a utility function that checks whether a given URL represents an internationalization file. It takes in the `url` parameter and returns `true` if the URL ends with `.i18n.js`, indicating it is an internationalization file. ### Export Statements The module exports the `nameTemplates` function, allowing it to be used in other parts of the build process. The `isI18nFile` function is not exported and is intended for internal use within the module. By using these utility functions, you can generate name templates for different types of files during the build process. These name templates play a crucial role in determining the output file names and paths, enabling effective asset management and caching strategies. Please note that the provided code snippet represents a partial implementation, and there may be additional code or dependencies required for the utility module to function correctly within the overall CBT system. ## File Templates Configuration Documentation The `templates` object in the provided code represents a collection of file templates used in the build process of the Client Build Tool (CBT). The object contains various file types as keys, and each key holds an array of file templates for development and production modes. Here is the documentation for the file templates: ```javascript const templates = { html: ['index.html', 'index.[contenthash].html'], js: ['js/[name].js', 'js/[name].[contenthash].js'], chunkjs: ['js-chunks/[name].js', 'js-chunks/[name].[contenthash].js'], i18njs: [ 'i18n-chunks/[locale]/[name].i18n.js', 'i18n-chunks/[locale]/[name].[chunkhash].i18n.js' ], i18nchunkjs: [ 'i18n-chunks/[locale]/[name].i18n.js', // 'i18n-chunks/[locale]/[name].[chunkhash].i18n.js' 'i18n-chunks/[locale]/[name].[contenthash].i18n.js' ], i18nmanifest: ['i18n-manifest.json', 'i18n-manifest.json'], workerjs: ['js/[name].js', 'js/[name].[contenthash].js'], css: ['css/[name].css', 'css/[name].[contenthash].css'], cssdir: ['css/[name].[dir].css', 'css/[name].[contenthash].[dir].css'], image: ['images/[name][ext]', 'images/[name].[contenthash][ext]'], font: ['fonts/[name][ext]', 'fonts/[name].[contenthash][ext]'], svg: ['fonts/[name][ext]', 'fonts/[name].[contenthash][ext]'], audio: ['fonts/[name][ext]', 'fonts/[name].[contenthash][ext]'], video: ['videos/[name][ext]', 'videos/[name].[contenthash][ext]'] }; ``` The `templates` object contains file templates for various types of assets used in the build process. Each key-value pair represents a file type and its corresponding file templates. Here are some key points regarding the file templates: - **html**: Contains file templates for HTML files. The development mode template is `'index.html'`, and the production mode template includes a `[contenthash]` placeholder, resulting in `'index.[contenthash].html'`. - **js**: Contains file templates for JavaScript files. The development mode template is `'js/[name].js'`, where `[name]` is replaced by the actual name of the JavaScript file. The production mode template includes a `[contenthash]` placeholder, resulting in `'js/[name].[contenthash].js'`. - **chunkjs**: Contains file templates for chunk JavaScript files. The templates follow a similar pattern to the `js` templates. - **i18njs**: Contains file templates for internationalization JavaScript files. The templates include a `[locale]` placeholder, representing the locale, and a `[chunkhash]` placeholder in the production mode template. - **i18nchunkjs**: Contains alternative file templates for internationalization JavaScript files. The production mode template uses a `[contenthash]` placeholder instead of `[chunkhash]`. - **i18nmanifest**: Contains file templates for the internationalization manifest file. The same template is used for both development and production modes. - **workerjs**: Contains file templates for worker JavaScript files. The templates follow a similar pattern to the `js` templates. - **css**: Contains file templates for CSS files. The templates follow a similar pattern to the `js` templates. - **cssdir**: Contains file templates for CSS files with directory placeholders. The templates include a `[dir]` placeholder in the file name. Changing this line may affect other files and plugins in the build process. - **image**, **font**, **svg**, **audio**, **video**: Contains file templates for different types of static assets. The templates follow specific patterns based on the file extensions and include placeholders like `[name]`, `[contenthash]`, and `[ext]` to generate dynamic file names. These file templates are used by the build process to determine the output file names and paths for different assets. They allow for effective asset management and caching strategies during development and production modes. Please note that the provided code snippet represents a partial implementation, and there may be additional code or dependencies required to fully utilize the file templates within the overall CBT system.