webpack-dev-server 更改index.html目录后无法访问

我平时用 webpack-dev-server --inline --port 9000 --open 会默认访问我dist/index.html页面,
现在dist目录结构改了一下 , 将index.html放在了view目录下 , 然后将命令改为
webpack-dev-server --inline --port 9000 --open --content-base dist/view/

├─dist
│  ├─js
│  │   base.js
│  │   index.js
│  │   login.js
│  │
│  └─view
│       index.html
│       login.html

但是自动打开的页面却访问失败... 一定要手动加/view访问 , http://localhost:9000/view才行 , 请问有没有什么办法.. ?
下面是webpack的代码...

var path = require('path');
var webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const HtmlWebpackPlugin = require('html-webpack-plugin');
var getHtmlConfig = function (name) {
  return {
    filename: 'view/' + name + '.html',
    template: path.join(__dirname, 'src', 'view', `${name}.html`),
    chunks: ['common', name]
  }
}
module.exports = {
  entry: {
    'common': ['./src/page/common/index.js'],
    'index': ['./src/page/index/index.js'],
    'login': ['./src/page/login/index.js'],
  },
  output: {
    path: path.join(__dirname, 'dist'),
    filename: 'js/[name].js',
  },
  externals: {
    'jquery': 'window.jQuery'
  },
  resolve: {
      ....
  },
  module: {
      ....
  },
  plugins: [
    new CleanWebpackPlugin('dist'),
    new ExtractTextPlugin("css/[name].css"),
    new webpack.optimize.CommonsChunkPlugin({
      name: 'common',
      filename: 'js/base.js'
    }),
    //html模板的处理
    new HtmlWebpackPlugin(getHtmlConfig('index')),
    new HtmlWebpackPlugin(getHtmlConfig('login'))
  ]
}
阅读 4.5k
3 个回答
var getHtmlConfig = function (name) {
  return {
    filename: name + '.html', // 去掉 'view/'
    template: path.join(__dirname, 'src', 'view', `${name}.html`),
    chunks: ['common', name]
  }
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题