【发布时间】:2016-05-25 20:29:06
【问题描述】:
我一直在用 webpack 和 angular 打破我的脑袋。这可能有一个简单的答案,但我无法弄清楚。我已经阅读了关于此主题的堆栈溢出中的几乎所有答案。
我有一个这样的 html 页面(还有其他有图片的模板):
<body>
<img ng-src="../images/angular-webpack.png">
<md-button class="md-primary md-raised">
Button
</md-button>
</body>
我还有一个 webpack 配置:
var webpack = require('webpack');
var CopyWebpackPlugin = require('copy-webpack-plugin');
var path = require('path');
module.exports = {
context: path.resolve(__dirname + '/src'),
entry: ['./js/core/app.module.js'],
output: {
path: './release',
publicPath:'/',
filename: 'app.js'
},
module: {
loaders: [
{
test: /\.html/,
exclude: 'node_modules',
loader: 'raw-loader'
},
{
test: /\.css/,
exclude: 'node_modules',
loader: 'style-loader!css-loader'
},
{
test: /\.(jpe?g|png)$/i,
exclude: 'node_modules',
loader: 'url-loader?limit=8192!img'
}
]
},
plugins: [
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false
}
}),
new CopyWebpackPlugin([
{from: './index.html', to: './index.html'}
], {
ignore: [
'*.txt',
{glob: '**/*', dot: true}
]
})
],
devServer: {
contentBase: './release'
},
watch: true
};
...但我没有看到我的图像正在加载。我已经尝试了 url-loader、带有 publicPath 和没有它的文件加载器。我很困惑,我不知道如何格式化 webpack 配置或 html 图像标签以使其正常工作。
有没有人有让图像与 webpack 一起工作的经验?此外,我不想将我的图像包含在控制器或任何其他 js 文件中。我希望在 html 页面中声明图像。
【问题讨论】:
标签: javascript html angularjs webpack