Skip to content

Commit

Permalink
Support custom filenames (vuejs#326)
Browse files Browse the repository at this point in the history
* support custom filenames

* update docs
  • Loading branch information
egoist authored Feb 2, 2017
1 parent 8e19c5a commit 8b1b918
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
16 changes: 13 additions & 3 deletions bin/vue-build
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,15 @@ if (hasBabelRc) {
babelOptions.presets.push(require.resolve('babel-preset-vue-app'))
}

var filenames = getFilenames(options)

var webpackConfig = {
entry: {
client: []
},
output: {
path: path.join(process.cwd(), options.dist),
filename: production ? '[name].[chunkhash:8].js' : '[name].js',
filename: filenames.js,
publicPath: '/'
},
performance: {
Expand Down Expand Up @@ -175,7 +177,7 @@ var webpackConfig = {
test: /\.(ico|jpg|png|gif|svg|eot|otf|webp|ttf|woff|woff2)(\?.*)?$/,
loader: 'file-loader',
query: {
name: options.lib ? 'static/[name].[ext]' : 'static/[name].[hash:8].[ext]'
name: filenames.static
}
}
].concat(loaders.styleLoaders(cssOptions))
Expand Down Expand Up @@ -253,7 +255,7 @@ if (production) {
new webpack.LoaderOptionsPlugin({
minimize: true
}),
new ExtractTextPlugin(options.lib ? `${replaceExtension(options.entry, '.css')}` : '[name].[contenthash:8].css')
new ExtractTextPlugin(filenames.css)
)
} else {
if (!options.watch) {
Expand Down Expand Up @@ -377,3 +379,11 @@ function handleBuild (err, stats, watch) {
console.log(` ${chalk.yellow('serve')} ${options.dist} --single\n`)
}
}

function getFilenames (options) {
return Object.assign({
js: options.production ? '[name].[chunkhash:8].js' : '[name].js',
css: options.lib ? `${replaceExtension(options.entry, '.css')}` : '[name].[contenthash:8].css',
static: options.lib ? 'static/[name].[ext]' : 'static/[name].[hash:8].[ext]'
}, options.filename)
}
16 changes: 15 additions & 1 deletion docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ If you want to directly test a component without manually create a Vue instance
$ vue build Component.vue
```

<details><summary>How does this work?</summary>
<details><summary>How does this work?</summary><br>
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`.
</details>

Expand Down Expand Up @@ -150,6 +150,20 @@ Type: `Object`

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

#### filename

Set custom filename for `js` `css` `static` files:

```js
{
filename: {
js: 'index.js',
css: 'style.css',
static: 'static/[name].[ext]'
}
}
```

#### proxy

Type: `string`, `Object`
Expand Down

0 comments on commit 8b1b918

Please sign in to comment.