Skip to content

Commit 8b1b918

Browse files
authored
Support custom filenames (#326)
* support custom filenames * update docs
1 parent 8e19c5a commit 8b1b918

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

bin/vue-build

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,13 +125,15 @@ if (hasBabelRc) {
125125
babelOptions.presets.push(require.resolve('babel-preset-vue-app'))
126126
}
127127

128+
var filenames = getFilenames(options)
129+
128130
var webpackConfig = {
129131
entry: {
130132
client: []
131133
},
132134
output: {
133135
path: path.join(process.cwd(), options.dist),
134-
filename: production ? '[name].[chunkhash:8].js' : '[name].js',
136+
filename: filenames.js,
135137
publicPath: '/'
136138
},
137139
performance: {
@@ -175,7 +177,7 @@ var webpackConfig = {
175177
test: /\.(ico|jpg|png|gif|svg|eot|otf|webp|ttf|woff|woff2)(\?.*)?$/,
176178
loader: 'file-loader',
177179
query: {
178-
name: options.lib ? 'static/[name].[ext]' : 'static/[name].[hash:8].[ext]'
180+
name: filenames.static
179181
}
180182
}
181183
].concat(loaders.styleLoaders(cssOptions))
@@ -253,7 +255,7 @@ if (production) {
253255
new webpack.LoaderOptionsPlugin({
254256
minimize: true
255257
}),
256-
new ExtractTextPlugin(options.lib ? `${replaceExtension(options.entry, '.css')}` : '[name].[contenthash:8].css')
258+
new ExtractTextPlugin(filenames.css)
257259
)
258260
} else {
259261
if (!options.watch) {
@@ -377,3 +379,11 @@ function handleBuild (err, stats, watch) {
377379
console.log(` ${chalk.yellow('serve')} ${options.dist} --single\n`)
378380
}
379381
}
382+
383+
function getFilenames (options) {
384+
return Object.assign({
385+
js: options.production ? '[name].[chunkhash:8].js' : '[name].js',
386+
css: options.lib ? `${replaceExtension(options.entry, '.css')}` : '[name].[contenthash:8].css',
387+
static: options.lib ? 'static/[name].[ext]' : 'static/[name].[hash:8].[ext]'
388+
}, options.filename)
389+
}

docs/build.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ If you want to directly test a component without manually create a Vue instance
3838
$ vue build Component.vue
3939
```
4040

41-
<details><summary>How does this work?</summary>
41+
<details><summary>How does this work?</summary><br>
4242
When the input file ends with `.vue` extension, we use a [default app entry](/lib/default-entry.es6) to load the given component, otherwise we treat it as a normal webpack entry. For jsx component which ends with `.js` extension, you can enable this behavior manually by adding `--mount`.
4343
</details>
4444

@@ -150,6 +150,20 @@ Type: `Object`
150150

151151
Check out the [default template](/lib/template.html) file we use.
152152

153+
#### filename
154+
155+
Set custom filename for `js` `css` `static` files:
156+
157+
```js
158+
{
159+
filename: {
160+
js: 'index.js',
161+
css: 'style.css',
162+
static: 'static/[name].[ext]'
163+
}
164+
}
165+
```
166+
153167
#### proxy
154168

155169
Type: `string`, `Object`

0 commit comments

Comments
 (0)