简体   繁体   English

Angular2 图像未显示

[英]Angular2 image not showing

Anytime i add a image tag in the html and i do something like this:任何时候我在 html 中添加一个图像标签,我都会做这样的事情:

<img src="../resources/img/myimg.png">

The image doesn't show.图像不显示。 Instead i get something this showing相反,我得到了这样的东西空图像

I have tried putting <base href="/"> in my index.html head but i get no changes.我试过将<base href="/">放在我的 index.html 头中,但我没有得到任何改变。 What could be the cause of this?这可能是什么原因? What else must i do to make this work?我还必须做什么才能使这项工作?

I also tried installing image-webpack-loader Here is the content of my webpack.config.js file我也尝试安装 image-webpack-loader 这是我的 webpack.config.js 文件的内容

 var webpack = require('webpack'); var path = require('path'); // Webpack Config var webpackConfig = { entry: { 'polyfills': './src/polyfills.browser.ts', 'vendor': './src/vendor.browser.ts', 'main': './src/main.browser.ts', }, output: { path: __dirname + '/dist', }, plugins: [ new webpack.optimize.OccurenceOrderPlugin(true), new webpack.optimize.CommonsChunkPlugin({ name: ['main', 'vendor', 'polyfills'], minChunks: Infinity }), ], module: { loaders: [ // .ts files for TypeScript { test: /\\.ts$/, loaders: ['awesome-typescript-loader', 'angular2-template-loader'] }, { test: /\\.css$/, loaders: ['to-string-loader', 'css-loader'] }, { test: /\\.html$/, loader: 'raw-loader' }, { test: /.*\\.(gif|png|jpe?g|svg)$/i, loaders: [ 'file?hash=sha512&digest=hex&name=[hash].[ext]', 'image-webpack?{progressive:true, optimizationLevel: 7, interlaced: false, pngquant:{quality: "65-90", speed: 4}}' ] } ] } }; // Our Webpack Defaults var defaultConfig = { devtool: 'cheap-module-source-map', cache: true, debug: true, output: { filename: '[name].bundle.js', sourceMapFilename: '[name].map', chunkFilename: '[id].chunk.js' }, resolve: { root: [ path.join(__dirname, 'src') ], extensions: ['', '.ts', '.js'] }, devServer: { historyApiFallback: true, watchOptions: { aggregateTimeout: 300, poll: 1000 } }, node: { global: 1, crypto: 'empty', module: 0, Buffer: 0, clearImmediate: 0, setImmediate: 0 } }; var webpackMerge = require('webpack-merge'); module.exports = webpackMerge(defaultConfig, webpackConfig);

你不能离开base href范围,你应该将你的资产移动到src目录中,在给定路径后,例如./resources它将是src/resources

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM