vue无法自动打开浏览器
原文链接: 点我
如果不能自动打开浏览器,是因为没有安装插件。
插件安装的方法
1.安装插件,在cmd中输入:
$ npm i open-browser-webpack-plugin --save
这里的 i 表示 install ,是缩写。
2.修改build\webpack.dev.conf.js文件。
在顶部声明最下面加入:
var OpenBrowserPlugin = require('open-browser-webpack-plugin')
在plugins中加入:
new OpenBrowserPlugin({ url: 'http://localhost:8080' }),
var config = require('../config') var webpack = require('webpack') var merge = require('webpack-merge') var utils = require('./utils') var baseWebpackConfig = require('./webpack.base.conf') var HtmlWebpackPlugin = require('html-webpack-plugin') var FriendlyErrors = require('friendly-errors-webpack-plugin') var OpenBrowserPlugin = require('open-browser-webpack-plugin') // add hot-reload related code to entry chunks Object.keys(baseWebpackConfig.entry).forEach(function (name) { baseWebpackConfig.entry[name] = ['./build/dev-client'].concat(baseWebpackConfig.entry[name]) }) module.exports = merge(baseWebpackConfig, { module: { loaders: utils.styleLoaders({ sourceMap: config.dev.cssSourceMap }) }, // eval-source-map is faster for development devtool: '#eval-source-map', plugins: [ new OpenBrowserPlugin({ url: 'http://192.168.10.105:8080' }), new webpack.DefinePlugin({ 'process.env': config.dev.env }), // https://github.com/glenjamin/webpack-hot-middleware#installation--usage new webpack.optimize.OccurrenceOrderPlugin(), new webpack.HotModuleReplacementPlugin(), new webpack.NoErrorsPlugin(), // https://github.com/ampedandwired/html-webpack-plugin new HtmlWebpackPlugin({ filename: 'index.html', template: 'index.html', inject: true }), new FriendlyErrors() ] })
3.最后,在运行npm run dev 即可。
作者:时来运转
大佬们好,我是Web前端菜鸟,初来乍到,想跟诸位共同学习成长;
综上是我每日闲时整理笔记,文章如有侵权请诸位及时告知我,谢谢关照!