Webpack and Angular Upload HTML Image

I rack my brains with webpack and angular. This may have a simple answer, but I cannot figure it out. I read almost every answer here in the stack overflow on this topic to no avail.

I have an html page like this one (also another image template):

<body>
    <img ng-src="../images/angular-webpack.png">

    <md-button class="md-primary md-raised">
        Button
    </md-button> 
</body>

I also have a webpack configuration:

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
};

... but I do not see the loading of my images. I tried the url loader loader, file loader with and without publicPath. I'm confused, I don't know how to format the webpack configuration or html image tag to make it work.

Does anyone have any experience getting webpack images? Also I don't want to include my images in controllers or in any other js file. I want the images to be declared on the html page.

+4
1

, raw-loader CommonJS, - .

, webpack HTML , html-loader. Html- HTML . <img src="...">. html-loader ng-src, :

// webpack.config.js

    ...
    loaders: [{
        test: /\.html$/,
        loaders: [
            "html?" + JSON.stringify({
                attrs: ["img:src", "img:ng-src"]
            })
        ]}
    ]
+7

Source: https://habr.com/ru/post/1628765/


All Articles