Skip to content

Commit 99cbd98

Browse files
authored
Merge pull request adambullmer#112 from siphomateke/custom-artifact-filename
Support custom artifact filenames
2 parents 43abbf8 + a4c01ed commit 99cbd98

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,36 @@ module.exports = {
164164

165165
Directory where the zipped browser extension should get created.
166166

167+
- **artifactFilename**
168+
169+
- Type: `Function`
170+
- Default: ``({name, version, mode}) => `${name}-v${version}-${mode}.zip` ``
171+
172+
Optional function to generate a custom artifact filename. Useful for naming builds for different browsers.
173+
174+
The function takes a single object parameter containing:
175+
- `name` - Name from `package.json`
176+
- `version` - Version from `package.json`
177+
- `mode` - Vue CLI mode such as 'production'
178+
179+
For example,
180+
181+
```js
182+
// vue.config.js
183+
module.exports = {
184+
pluginOptions: {
185+
browserExtension: {
186+
artifactFilename: ({ name, version, mode }) => {
187+
if (mode === 'production') {
188+
return `${name}-v${version}-${process.env.BROWSER}.zip`;
189+
}
190+
return `${name}-v${version}-${process.env.BROWSER}-${mode}.zip`;
191+
},
192+
},
193+
},
194+
};
195+
```
196+
167197
### Component options
168198

169199
Some browser extension components have additional options which can be set as follows:

index.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,20 @@ module.exports = (api, options) => {
100100
}
101101

102102
if (isProduction) {
103+
let filename
104+
if (pluginOptions.artifactFilename) {
105+
filename = pluginOptions.artifactFilename({
106+
name: packageJson.name,
107+
version: packageJson.version,
108+
mode: api.service.mode
109+
})
110+
} else {
111+
filename = `${packageJson.name}-v${packageJson.version}-${api.service.mode}.zip`
112+
}
103113
webpackConfig.plugin('zip-browser-extension').use(ZipPlugin, [
104114
{
105115
path: api.resolve(pluginOptions.artifactsDir || 'artifacts'),
106-
filename: `${packageJson.name}-v${packageJson.version}-${api.service.mode}.zip`
116+
filename: filename
107117
}
108118
])
109119
}

0 commit comments

Comments
 (0)