https://github.com/jmurzy/babel-plugin-transform-assets
Transforms asset imports at compile time using Babel 📦
https://github.com/jmurzy/babel-plugin-transform-assets
babel react-native
Last synced: about 1 year ago
JSON representation
Transforms asset imports at compile time using Babel 📦
- Host: GitHub
- URL: https://github.com/jmurzy/babel-plugin-transform-assets
- Owner: jmurzy
- License: mit
- Created: 2016-03-01T08:38:05.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-11-16T05:41:36.000Z (over 7 years ago)
- Last Synced: 2025-04-08T18:40:30.649Z (about 1 year ago)
- Topics: babel, react-native
- Language: JavaScript
- Homepage:
- Size: 13.7 KB
- Stars: 31
- Watchers: 2
- Forks: 7
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# babel-plugin-transform-assets
Transforms importing of asset files at compile time using Babel. This plugin removes the need to run your server code through [Webpack](https://github.com/webpack/webpack) module bundler when using loaders such as file-loader, url-loader and building isomorphic universal apps. Aids in creating a cleaner, maintainable build process at the cost of yet another [Babel](https://github.com/babel/babel) [plugin](https://babeljs.io/docs/plugins/).
[](https://circleci.com/gh/jmurzy/babel-plugin-transform-assets)
[](https://www.npmjs.com/package/babel-plugin-transform-assets)
[](https://github.com/jmurzy/babel-plugin-transform-assets/blob/master/LICENSE.md)
## Example
```js
import file from '../file.txt';
```
will be transformed to
```js
var file = 'file.txt?9LDjftP';
```
See the spec for [more examples](https://github.com/jmurzy/babel-plugin-transform-assets/blob/master/test/index.spec.js).
## Requirements
[Babel](https://github.com/babel/babel) v6 or higher.
## Installation
```sh
npm install -D babel-plugin-transform-assets
```
## Usage
### Via `.babelrc`
**.babelrc**
```json
{
"plugins": [
["transform-assets", {
"extensions": ["svg"],
"name": "[name].[ext]?[sha512:hash:base64:7]"
}]
]
}
```
### Via Node API
```javascript
require('babel-core').transform('code', {
plugins: [
['transform-assets', {
extensions: ['svg'],
name: '[name].[ext]?[sha512:hash:base64:7]',
}]
]
});
```
### Contributing
Contributions are very welcome—bug fixes, features, documentation, tests. Just make sure the tests are passing.
### Related Projects
[babel-plugin-css-modules-transform](https://github.com/michalkvasnicak/babel-plugin-css-modules-transform)