Skip to content

Commit

Permalink
docs(configuration): document generator publicPath (#4779)
Browse files Browse the repository at this point in the history
* sort

* document generator publicPath

* use version Badge

* use version Badge
  • Loading branch information
chenxsan committed Mar 27, 2021
1 parent cbdf0d6 commit 6f2e9ff
Showing 1 changed file with 53 additions and 20 deletions.
73 changes: 53 additions & 20 deletions src/content/configuration/module.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,18 @@ module.exports = {
generator: {
asset: {
// Generator options for asset modules

// Customize publicPath for asset modules, available since webpack 5.28.0
publicPath: 'assets/',
},
'asset/inline': {
// Generator options for asset/inline modules
},
'asset/resource': {
// Generator options for asset/resource modules

// Customize publicPath for asset/resource modules, available since webpack 5.28.0
publicPath: 'assets/',
},
javascript: {
// No generator options are supported for this module type yet
Expand Down Expand Up @@ -603,6 +609,31 @@ module.exports = {
};
```

### Rule.generator.emit

Opt out of writing assets from [Asset Modules](/guides/asset-modules/), you might want to use it in Server side rendering cases.

- Type: `boolean = true`
- Available: <Badge text='5.25.0+' />
- Example:

```js
module.exports = {
//
module: {
rules: [
{
test: /\.png$/i,
type: 'asset/resource',
generator: {
emit: false,
},
},
],
},
};
```

### Rule.generator.filename

The same as [`output.assetModuleFilename`](/configuration/output/#outputassetmodulefilename) but for specific rule. Overrides `output.assetModuleFilename` and works only with `asset` and `asset/resource` module types.
Expand Down Expand Up @@ -633,30 +664,32 @@ module.exports = {
};
```

### Rule.generator.emit
### Rule.generator.publicPath

Opt out of writing assets from [Asset Modules](/guides/asset-modules/), you might want to use it in Server side rendering cases.
Customize `publicPath` for specific Asset Modules.

- Type: `boolean = true`
- Available: 5.25.0+
- Example:
- Type: `string | ((pathData: PathData, assetInfo?: AssetInfo) => string)`
- Available: <Badge text='5.28.0+' />

```js
module.exports = {
//
module: {
rules: [
{
test: /\.png$/i,
type: 'asset/resource',
generator: {
emit: false,
},
```js
module.exports = {
//...
output: {
publicPath: 'static/',
},
module: {
rules: [
{
test: /\.png$/i,
type: 'asset/resource',
generator: {
publicPath: 'assets/',
},
],
},
};
```
},
],
},
};
```

## `Rule.resource`

Expand Down

1 comment on commit 6f2e9ff

@vercel
Copy link

@vercel vercel bot commented on 6f2e9ff Mar 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.