Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bolasblack/interpolate-webpack-plugin
Interpolate predefined variables to assets files
https://github.com/bolasblack/interpolate-webpack-plugin
webpack-plugin
Last synced: 11 days ago
JSON representation
Interpolate predefined variables to assets files
- Host: GitHub
- URL: https://github.com/bolasblack/interpolate-webpack-plugin
- Owner: bolasblack
- Created: 2018-08-12T06:42:57.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-07T19:57:39.000Z (over 1 year ago)
- Last Synced: 2024-11-10T03:36:32.229Z (2 months ago)
- Topics: webpack-plugin
- Language: TypeScript
- Homepage:
- Size: 505 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# interpolate-webpack-plugin [![Build Status](https://travis-ci.com/bolasblack/interpolate-webpack-plugin.svg?branch=master)](https://travis-ci.com/bolasblack/interpolate-webpack-plugin) [![Coverage Status](https://coveralls.io/repos/github/bolasblack/interpolate-webpack-plugin/badge.svg?branch=master)](https://coveralls.io/github/bolasblack/interpolate-webpack-plugin?branch=master)
Inspired by [react-dev-utils/InterpolateHtmlPlugin](https://github.com/facebook/create-react-app/blob/next/packages/react-dev-utils/InterpolateHtmlPlugin.js).
This Webpack plugin designed to lets us interpolate custom predefined variables into assets.
## Builtin variables
- `%GIT_DESCRIBE%`: result of `git describe --tags`
- `%GIT_REV%`: result of `git rev-parse --short HEAD`
- `%GIT_VERSION%`: `%GIT_DESCRIBE%` or `%GIT_REV%`
- `%packageJson.[data.path.in.package.json]%`: any data in `package.json`## Install
```bash
yarn add @c4605/interpolate-webpack-plugin -D
# or
npm install @c4605/interpolate-webpack-plugin --save-dev
```## Usage
```js
import { InterpolateWebpackPlugin, DefaultReplacer } from 'interpolate-webpack-plugin'export default {
// ... webpack configs
plugins: [
// Use with default replacer
new InterpolateWebpackPlugin(
new DefaultReplacer({ options }),
),// Or use custom replacer
new InterpolateWebpackPlugin({ replacer: (filename, source) =>
new PrefixSource(
prefix: '/* prefix */',
source,
)
}),
],
}
```Options structure can find in `src/index.ts#InterpolateWebpackPluginOptions`.
The default replacer will not modify binary files (checked by [isBinaryFile](https://github.com/gjtorikian/isBinaryFile)) and sourcemap files.
If you want to use the builtin variables, you can to this:
```js
module.exports = async () => {
// ... webpack configs
plugins: [
new webpack.DefinePlugin({
...(await new DefaultReplacer({ options }).getDefinePluginOptions()),
// ... other defines
}),
],
}
```## Development
```bash
yarn build # build code
yarn watch # build and watch code
yarn test # run tests
```