vuejs实现全站可配置
1、找到/build/webpack.dev.conf.js新增配置,运行项目用到
```js
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'index.html',
node_env_dev: true, // 新增配置
inject: true,
favicon: path.resolve('./static/favicon.ico')
}),
```
2、找到/build/webpack.prod.conf.js新增配置,打包项目用到
```js
new HtmlWebpackPlugin({
filename: config.build.index,
template: 'index.html',
inject: true,
node_env_prod: true, // 新增配置
version_time: new Date().getTime(), // 配置打包后config.js文件,加时间戳
...
}),
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, '../static'),
to: config.build.assetsSubDirectory,
ignore: ['.*','config.js'] // 忽略掉 config.js 文件的复制
},
// 复制配置文件到根路径下
{
from: path.join(__dirname,'../static/config.js')
}
])
```
3、找到需要配置的页面index.html
//判断运行配置文件的引用路径,使打包后正常引用。
```?v=<%=htmlWebpackPlugin.options.version_time%>``` 对引入文件加时间戳
```html
<% if ( htmlWebpackPlugin.options.node_env_prod ) { %>
<% } %>
<% if ( htmlWebpackPlugin.options.node_env_dev ) { %>
<% } %>
```
以上是编程学习网小编为您介绍的“vuejs实现全站可配置”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。