【发布时间】:2018-12-03 09:54:46
【问题描述】:
我已经阅读了很多关于这方面的资料,但我似乎仍然无法按照我想要的方式提供我的文件。
我的文件结构:
root/
/dist/ <= here is where webpack is putting bundles
/public/ <= here are where all my images are stored
/src/ <= here are my source files
template.html <= some files under src
index.js
webpack.config.js <= files under root
index.html <= html now at root by webpack
我的 webpack.config 的 htmlWebpackPlugin 配置如下:
new HtmlWebpackPlugin({
"template": "./src/template.html",
"filename": "../index.html", <= moved up to root?
"hash": false,
"inject": true,
"compile": true,
"favicon": false,
"minify": false,
"cache": true,
"showErrors": true,
"chunks": "all",
"excludeChunks": [],
"title": "Webpack App",
"xhtml": true,
"chunksSortMode": 'none' //fixes bug
}),
我的输出配置如下:
output: {
filename: '[name].[chunkhash:4].js',
chunkFilename: '[name].[chunkhash:4].js', //name of non-entry chunk files
path: path.resolve(__dirname, 'dist'),
publicPath: "/public" <= not really sure about this
},
因此,据我所知,publicPath 是图像元素上的“src”属性将在整个代码中提供的位置,对吗?所以,在我的代码中,我可以只输入 src='/images....' 因为 '/public' 将被添加到前面。对吧?
另外,我读到了一些关于“webpack-dev-server”的内容,也将提供该文件夹(公共)中的文件。开发服务器是否曾经查看过 webpack 创建的 dist 目录?还是完全分开的?
所以,如您所见,我将 index.html 移至根目录。不确定我是否需要这样做,但我正在尝试弄清楚如何提供我从 html 本身中调用的图像。
如何从代码“/images/....”中轻松提供文件,并直接从 html 提供文件?我应该从“公共”文件夹中提供 html,还是会影响 dist 包的服务?
【问题讨论】:
标签: html webpack webpack-dev-server