Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

html-loader won't work properly #133

Closed
Turanchoks opened this issue Dec 5, 2015 · 6 comments
Closed

html-loader won't work properly #133

Turanchoks opened this issue Dec 5, 2015 · 6 comments

Comments

@Turanchoks
Copy link

So I want to use html-loader with the plugin and I just add

    new HtmlWebpackPlugin({
        template: 'html!src/index.html',
        inject: 'body',
        chunk: 'app'
    })

And my html contains <img src="logo.png">. When I try to build I get the

Module not found: Error: Cannot resolve 'file' or 'directory' ./\""

But when I wrap logo.png with single quotes or just append it to the image name it will start looking for it.

Module not found: Error: Cannot resolve 'file' or 'directory' ./\"'logo.png\"

I assume it's a problem with html-loader but it works as a common loader to require other html files. Any ideas what causes that weird behavior? Thanks

@jantimon
Copy link
Owner

jantimon commented Dec 6, 2015

Could you please show us your entire configuration?

@Turanchoks
Copy link
Author

const path = require("path");
const HtmlWebpackPlugin = require('html-webpack-plugin');
const TransferWebpackPlugin = require('transfer-webpack-plugin');
const src_path = path.join(__dirname, '/src');

module.exports = {
    context: src_path,

    entry: {
        app: './app.js'
    },

    output: {
        path: path.join(__dirname, 'dist'),
        filename: '[name].[hash].js',
        publicPath: '/'
    },

    module: {
        loaders: [{
            test: /\.js$/,
            exclude: /node_modules/,
            query: {
                presets: 'es2015',
            },
            loader: 'babel'
        }, {
            test: /\.scss$/,
            loader: 'style!css!sass'
        }, {
            test: /\.css$/,
            loader: "style!css"
        }, {
            test: /\.(png|jpg|jpeg|gif|svg|woff|woff2|ttf|eot)$/,
            loader: 'file'
        }, {
            test: /\.html$/,
            loader: 'html'
        }]
    },

    plugins: [
        new HtmlWebpackPlugin({
            template: 'html!' + path.join(src_path, 'index.html'),
            inject: 'head',
            chunk: 'app'
        })
    ]
};

It's not full but this won't build.

@jantimon
Copy link
Owner

jantimon commented Dec 6, 2015

Okay index.html is a html file and you specified a loader for html files:

{
            test: /\.html$/,
            loader: 'html'
        }

This causes the html loader to be executed twice.

The solution might be '!!html!' + path.join(src_path, 'index.html')

@wmadden
Copy link

wmadden commented Dec 7, 2015

Why not just omit the html!?

You can instead write <img src="<%= require('logo.png') %>" /> and assuming the image can be found everything should just work.

@SamanthaAdrichem
Copy link

Html loader indeed breaks if you use double quotes in for your src attribute. Use single quotes and it does work.

@lock
Copy link

lock bot commented May 31, 2018

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock bot locked as resolved and limited conversation to collaborators May 31, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants