如何在 vue.js 构建中重命名 index.html?
how to rename index.html on a vue.js build?
我想重命名 npm run build
生成的 index.html
。我在 webpack 配置中找不到任何东西。
我还创建了一个 vue.config.js
描述如下:https://github.com/vuejs/vue-cli/tree/dev/docs/config
module.exports = {
pages: {
index: {
filename: 'dapp.html',
}
}
};
但是输出文件还是index.html
由于您正在创建 vue.config.js 我假设您使用的是 vue-cli 3.0。
鉴于您应该在 vue.config.js.
中添加以下行
module.exports = {
// modify the location of the generated HTML file.
// make sure to do this only in production.
chainWebpack: (config) => {
if (process.env.NODE_ENV === 'production') {
config.plugin('html').tap((opts) => {
opts[0].filename = './dist/dapp.html';
return opts;
});
}
},
};
Vue 的创建者在 github https://github.com/yyx990803/laravel-vue-cli-3 上设置了一个 laravel-vue-cli-3 示例,您可以在其中查看
vue-cli 旧版本更新
如果您使用的是 vue webpack 模板,那么在 config 文件夹中有一个 index.js 文件。在 module.exports 中,您将找到以下可以设置输出的位置:
...
build: {
// Template for index.html
index: path.resolve(__dirname, './dist/index.html'),
...
},
只需将 index.html 更改为 dapp.html 即可。
如果您使用的是 webpack 模板,您可以在 http://vuejs-templates.github.io/webpack/backend.html 查看更多详细信息。
您可以直接使用
module.exports = {
indexPath: 'index_bundled.html'
}
作为vue cli默认选项更改文件
我想重命名 npm run build
生成的 index.html
。我在 webpack 配置中找不到任何东西。
我还创建了一个 vue.config.js
描述如下:https://github.com/vuejs/vue-cli/tree/dev/docs/config
module.exports = {
pages: {
index: {
filename: 'dapp.html',
}
}
};
但是输出文件还是index.html
由于您正在创建 vue.config.js 我假设您使用的是 vue-cli 3.0。
鉴于您应该在 vue.config.js.
中添加以下行module.exports = {
// modify the location of the generated HTML file.
// make sure to do this only in production.
chainWebpack: (config) => {
if (process.env.NODE_ENV === 'production') {
config.plugin('html').tap((opts) => {
opts[0].filename = './dist/dapp.html';
return opts;
});
}
},
};
Vue 的创建者在 github https://github.com/yyx990803/laravel-vue-cli-3 上设置了一个 laravel-vue-cli-3 示例,您可以在其中查看
vue-cli 旧版本更新
如果您使用的是 vue webpack 模板,那么在 config 文件夹中有一个 index.js 文件。在 module.exports 中,您将找到以下可以设置输出的位置:
...
build: {
// Template for index.html
index: path.resolve(__dirname, './dist/index.html'),
...
},
只需将 index.html 更改为 dapp.html 即可。
如果您使用的是 webpack 模板,您可以在 http://vuejs-templates.github.io/webpack/backend.html 查看更多详细信息。
您可以直接使用
module.exports = {
indexPath: 'index_bundled.html'
}
作为vue cli默认选项更改文件