Looksイメージタグがindex.ejsテンプレート内にある場合、webpack設定でイメージを読み込む設定がありません。.ejsテンプレートのイメージ用Webpackファイル/イメージローダー
私のプロジェクトのHTMLファイルのすべてのイメージは、ビルド時に正しく名前が変更されロードされますが、.ejsファイルのイメージタグは無視されます。私.ejsで
つまり、私は<img src="../../home.png">
を持っている場合は、それがそのように残っているが、通常のHTMLファイルには、私の現在のローダー<img src="12345677.png">
に変更します。
loaders: [
//HTML Files
{
test: /\.html$/,
loader: 'html'
},
//Transpile ES6 to ES5
{
test: /\.js$/,
include: path.join(__dirname, 'src'),
exclude: /node_modules/,
loader: 'babel',
query: {
presets: [
["es2015", {"module": false}]
]
}
},
//Extract Normal CSS
{
test: /\.css$/,
loader: ExtractTextPlugin.extract({ loader : 'css?sourceMap!autoprefixer', publicPath: "../"})
},
//Bundle Less into CSS Code
{
test: /\.less$/,
loader: ExtractTextPlugin.extract({ loader : 'css?sourceMap!autoprefixer!less?sourceMap', publicPath: "../"})
},
//Images
{
test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/,
loader: 'file'
}
]
と重要なプラグイン:
plugins.push(
new HtmlWebpackPlugin({
hash: true,
filename: 'index.html',
template: './src/index.ejs',
favicon: './src/favicon.ico',
inject : false
}),
// Write out CSS bundle to its own file:
new ExtractTextPlugin({
filename: 'css/[contenthash].styles.css',
allChunks: true
}),
);
を含み、このthread
にauthorにより示唆されるように、画像ファイルをロードするためにunderscore-template loaderこのリンクを試すことができますあなたは使っていますか? [this](https://github.com/ampedandwired/html-webpack-plugin/blob/master/migration.md#loaders-in-templates)では、テンプレート内のローダーが2.0でサポートされている方法について説明しています –
@RedMercuryありがとう!それは私を狂って運転していた!それは魅力のように働いています –