我的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
}
}
};
答案 0 :(得分:1)
这似乎对我有用:
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
},
...
devServer: {
contentBase: './dist',
// no publicPath
}