没有提供Webpack dist文件夹

问题描述 投票:0回答:1

我的webpack配置文件有一个指向publicPath文件夹的dist设置,但是当我运行时

webpack-dev-server

提供项目根目录中的index.html。当我将index.html从根目录移动到dist文件夹时,我只是在浏览器中看到一个目录视图。

我的目录

index.html
src
  game.ts
dist
  bundle.js

如何告诉webpack我的index.html也在dist文件夹中?为什么webpack甚至会使用dist文件夹之外的任何内容......?

var path = require('path');
var pathToPhaser = path.join(__dirname, '/node_modules/phaser/');
var phaser = path.join(pathToPhaser, 'dist/phaser.js');

module.exports = {
  entry: './src/game.ts',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  module: {
    rules: [
      { test: /\.ts$/, loader: 'ts-loader', exclude: '/node_modules/' },
      { test: /phaser\.js$/, loader: 'expose-loader?Phaser' },
      { test: /\.(png|jpg|gif)$/, use: [{loader: 'file-loader', options: {
              outputPath: 'images',
      } }]}
    ]
  },
  devServer: {
    contentBase: path.resolve(__dirname, './'),
    publicPath: '/dist/',
    host: '127.0.0.1',
    port: 8080,
    open: true
  },
  resolve: {
    extensions: ['.ts', '.js'],
    alias: {
      phaser: phaser
    }
  }
};
webpack
1个回答
1
投票

这似乎对我有用:

output: {
  path: path.resolve(__dirname, 'dist'),
  filename: 'bundle.js',
},

...

devServer: {
  contentBase: './dist',
  // no publicPath
}
© www.soinside.com 2019 - 2024. All rights reserved.