You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pages/modules/roller/index.md
+157-5Lines changed: 157 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -125,7 +125,7 @@ Create a file called `tangible.config.js` in your project folder.
125
125
Example:
126
126
127
127
```js
128
-
module.exports= {
128
+
exportdefault {
129
129
build: [
130
130
{
131
131
src:'src/index.js',
@@ -176,10 +176,162 @@ Its value is one of:
176
176
177
177
The following optional task properties perform various substitutions.
178
178
179
-
-`alias` - Map import module name to target module name or file path
180
-
-`importToGlobal` - Map import module name to global variable name; supports dynamic name such as `@example/*`, for which a function should be given that takes the module name and returns the variable name
181
-
-`globalToImport` - Map global variable name to import module name
182
-
-`replaceStrings` - Map string to another string
179
+
##### alias
180
+
181
+
Using `alias` you can map an import module name to target another module name or file path. This uses rollup's [alias](https://github.com/rollup/plugins/tree/master/packages/alias#custom-resolvers) plugin under the hood.
182
+
183
+
Here's an example use of the `alias` parameter:
184
+
185
+
```js
186
+
exportdefault {
187
+
build: [
188
+
{
189
+
src:'src/index.js',
190
+
dest:'build/app.min.js',
191
+
alias: [
192
+
{
193
+
find:'src',
194
+
replacement:path.resolve(projectRootDir, 'src')
195
+
}
196
+
]
197
+
},
198
+
// ...
199
+
}
200
+
```
201
+
202
+
##### importToGlobal
203
+
204
+
Using `importToGlobal` you can map import module names to global variable names. It supports dynamic names such as `@example/*`, for which a function should be given that takes the module name and returns the variable name:
205
+
206
+
```js
207
+
exportdefault {
208
+
build: [
209
+
{
210
+
src:'src/index.js',
211
+
dest:'build/app.min.js',
212
+
importToGlobal: {
213
+
'@my-namespace/*':'myGlobalVar.*'
214
+
}
215
+
},
216
+
// ...
217
+
}
218
+
```
219
+
220
+
In WordPress mode Roller imports `@wordpress/*` into the global variable `wp.*`.
221
+
222
+
##### globalToImport
223
+
224
+
Using `globalToImport` would be a reverse situation of using `importToGlobal`. Here you can map a global variable name to an import module name. This uses Rollup's [inject](https://github.com/rollup/plugins/tree/master/packages/inject) plugin under the hood.
225
+
226
+
```js
227
+
exportdefault {
228
+
build: [
229
+
{
230
+
src:'src/index.js',
231
+
dest:'build/app.min.js',
232
+
globalToImport: {
233
+
// import { Promise } from 'es6-promise'
234
+
Promise: [ 'es6-promise', 'Promise' ],
235
+
236
+
// import { Promise as P } from 'es6-promise'
237
+
P: [ 'es6-promise', 'Promise' ],
238
+
239
+
// import $ from 'jquery'
240
+
$:'jquery',
241
+
242
+
// import * as fs from 'fs'
243
+
fs: [ 'fs', '*' ],
244
+
245
+
// use a local module instead of a third-party one
Using `replaceStrings` you can [map a string to another string](https://github.com/rollup/plugins/tree/master/packages/replace) during script processing. It can be handy for replacing placeholders with actual values at build time.
256
+
257
+
```js
258
+
exportdefault {
259
+
build: [
260
+
{
261
+
src:'src/index.js',
262
+
dest:'build/app.min.js',
263
+
replaceStrings: {
264
+
'process.env.NODE_ENV':'production',
265
+
__buildDate__: () =>newDate(),
266
+
__buildVersion__:15
267
+
},
268
+
replaceInclude: [
269
+
path.resolve( 'some/path/' ),
270
+
/\.[jt]sx?$/,
271
+
/node_modules/
272
+
]
273
+
},
274
+
// ...
275
+
}
276
+
```
277
+
278
+
The given values are encoded with `JSON.stringify()`.
279
+
280
+
By default, the string replacement applies to all files. Optionally use `replaceInclude` to specify an array of include file patterns.
281
+
282
+
The above replacements will convert this:
283
+
284
+
```js
285
+
constbuildTimeValues= {
286
+
date: __buildDate__,
287
+
version: __buildVersion__
288
+
}
289
+
```
290
+
291
+
..into..
292
+
293
+
```js
294
+
constbuildTimeValues= {
295
+
date:"2025-09-16T15:26:54.280Z",
296
+
version:15
297
+
}
298
+
```
299
+
300
+
##### replaceCode
301
+
302
+
This is similar to `replaceStrings`, but it replaces the source with literal code instead of JSON string. It's useful for replacing a placeholder with code that evaluates to a value at run time.
303
+
304
+
To demonstrate the difference:
305
+
306
+
```js
307
+
{
308
+
replaceCode: {
309
+
'process.env.NODE_ENV':'"production"'
310
+
__currentDate__:'new Date()'
311
+
__currentVersion__:'15'
312
+
}
313
+
}
314
+
```
315
+
316
+
The date constant will be replaced by the given code to get a new `Date` instance, instead of a string value evaluated at build time. The version constant will be replaced by the code `15`.
This feature requires a plugin to be registered with the [Framework](https://github.com/tangibleinc/framework) module, which adds a plugin settings page.
0 commit comments