https://github.com/andrelmlins/variables-loader
Webpack loader to parse variables
https://github.com/andrelmlins/variables-loader
loader parse-variables variables-loader webpack webpack-loader
Last synced: about 1 year ago
JSON representation
Webpack loader to parse variables
- Host: GitHub
- URL: https://github.com/andrelmlins/variables-loader
- Owner: andrelmlins
- License: mit
- Created: 2020-02-14T20:47:48.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T06:02:47.000Z (over 3 years ago)
- Last Synced: 2024-12-22T19:05:51.629Z (over 1 year ago)
- Topics: loader, parse-variables, variables-loader, webpack, webpack-loader
- Language: JavaScript
- Size: 127 KB
- Stars: 8
- Watchers: 3
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Variables loader
Webpack loader to parse variables
[](https://www.npmjs.com/package/variables-loader) [](https://github.com/andrelmlins/variables-loader/blob/master/LICENSE) [](https://travis-ci.com/andrelmlins/variables-loader)
## Install
```
npm install variables-loader
```
or
```
yarn add variables-loader
```
## Usage
**env.js**
```js
module.exports = () => {
return {
URL: "http://www.example.com"
};
};
```
**webpack.config.js**
```js
module.exports = {
module: {
rules: [
{
test: /\.(ts|js)x?$/,
use: ["variables-loader"]
}
]
}
};
```
### How will the result be?
**before in Link.jsx**
```jsx
import React from "react";
const LinkComponent = () => Link;
export default LinkComponent;
```
**after in Link.jsx**
```jsx
import React from "react";
const LinkComponent = () => Link;
export default LinkComponent;
```
## Options
### `fileName`
Type `String|Function` Default: `env.js`
**webpack.config.js**
#### `String`
```js
module.exports = {
module: {
rules: [
{
test: /\.(ts|js)x?$/,
loader: "variables-loader",
options: {
fileName: "environments.js"
}
}
]
}
};
```
#### `Function`
```js
module.exports = {
module: {
rules: [
{
test: /\.(ts|js)x?$/,
loader: "variables-loader",
options: {
fileName: () => {
if (process.env.NODE_ENV === "development") {
return "environments.test.js";
}
return "environments.js";
}
}
}
]
}
};
```
### `format`
Type `String|Function` Default: `js`
**webpack.config.js**
#### `String`
```js
module.exports = {
module: {
rules: [
{
test: /\.(ts|js)x?$/,
loader: "variables-loader",
options: {
format: "js"
}
}
]
}
};
```
#### `Function`
```js
module.exports = {
module: {
rules: [
{
test: /\.(ts|js)x?$/,
loader: "variables-loader",
options: {
format: () => {
if (process.env.NODE_ENV === "development") {
return "json";
}
return "js";
}
}
}
]
}
};
```
### `marker`
Type `String|Function|Array` Default: `[[]]`
**webpack.config.js**
#### `String`
```js
module.exports = {
module: {
rules: [
{
test: /\.(ts|js)x?$/,
loader: "variables-loader",
options: {
marker: "{{}}"
}
}
]
}
};
```
#### `Function`
```js
module.exports = {
module: {
rules: [
{
test: /\.(ts|js)x?$/,
loader: "variables-loader",
options: {
marker: () => {
if (process.env.NODE_ENV === "development") {
return "{{}}";
}
return "[[]]";
}
}
}
]
}
};
```
## NPM Statistics
Download stats for this NPM package
[](https://nodei.co/npm/variables-loader/)
## License
Variables Loader is open source software [licensed as MIT](https://github.com/andrelmlins/variables-loader/blob/master/LICENSE).