鍍金池/ 問答/HTML/ webpack-dev-server 更改index.html目錄后無法訪問

webpack-dev-server 更改index.html目錄后無法訪問

我平時(shí)用 webpack-dev-server --inline --port 9000 --open 會(huì)默認(rèn)訪問我dist/index.html頁(yè)面,
現(xiàn)在dist目錄結(jié)構(gòu)改了一下 , 將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

但是自動(dòng)打開的頁(yè)面卻訪問失敗... 一定要手動(dòng)加/view訪問 , http://localhost:9000/view才行 , 請(qǐng)問有沒有什么辦法.. ?
下面是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'))
  ]
}
回答
編輯回答
雅痞

'/view/'

2017年8月13日 07:40
編輯回答
短嘆
var getHtmlConfig = function (name) {
  return {
    filename: name + '.html', // 去掉 'view/'
    template: path.join(__dirname, 'src', 'view', `${name}.html`),
    chunks: ['common', name]
  }
}
2018年3月26日 12:56