Movatterモバイル変換


[0]ホーム

URL:


@rushstack/hashed-folder-copy-plugin
TypeScript icon, indicating that this package has built-in type declarations

1.1.14 • Public • Published

Installation

npm install @rushstack/hashed-folder-copy-plugin --save-dev

Overview

This webpack plugin provides a simple method for copying a folder to the build outputand including a hash in the folder's name, accessible to the bundle's runtime.

Usage

In your Webpack config, include the plugin in yourplugins array:

import{HashedFolderCopyPlugin}from'@rushstack/hashed-folder-copy-plugin';{plugins:[newHashedFolderCopyPlugin()]}

and call therequireFolder function in your webpack bundle:

constfolderUrl=requireFolder({outputFolder:'my-folder-name_[hash]',sources:[{globsBase:'../assets/',globs:['**/*.png']}]})

TypeScript typings are provided for therequireFolder function:

importtype{IRequireFolderOptions}from'@rushstack/hashed-folder-copy-plugin';declarefunctionrequireFolder(options:IRequireFolderOptions):string;constfolderUrl:string=requireFolder({outputFolder:'my-folder-name_[hash]',sources:[{globsBase:'../assets/',globPatterns:['**/*.png']}]})

TherequireFolder takes an options object with two properties:

outputFolder

This is the name of the folder to be created in the webpack output folder. Itsname supports a[hash] token, which will be replaced with a stable hash of the assetsthat are copied to the folder. Note that the[hash] token is not required.

sources

This is an array of glob base paths and glob patterns that will be copied to theoutput folder. Each entry in this array takes aglobsBase property, which is thebase path to the folder to be copied, and aglobPatterns property, which is an array ofglob patterns to be evaluated under theglobsBase folder. The path inglobsBasesupports standard Node resolution.

Example project

See theexample project.

A note about ambient types

To get therequireFolder function type to work in TypeScript, include a reference to"@rushstack/hashed-folder-copy-plugin/ambientTypes" in yourtsconfig.json file'scompilerOptions.types property. For example:

{"compilerOptions": {"types": ["webpack-env","@rushstack/hashed-folder-copy-plugin/ambientTypes"// This value, specifically    ]  }}

Readme

Keywords

none

Package Sidebar

Install

npm i @rushstack/hashed-folder-copy-plugin

Weekly Downloads

97

Version

1.1.14

License

MIT

Unpacked Size

32.7 kB

Total Files

18

Last publish

Collaborators

  • rushstack-admin
  • odspnpm
  • octogonz

[8]ページ先頭

©2009-2025 Movatter.jp