Skip to content
This repository has been archived by the owner on Mar 17, 2021. It is now read-only.

webpack stats.json original filename? #11

Closed
iam4x opened this issue Apr 20, 2015 · 5 comments
Closed

webpack stats.json original filename? #11

iam4x opened this issue Apr 20, 2015 · 5 comments

Comments

@iam4x
Copy link

iam4x commented Apr 20, 2015

Hey,

For my server side rendering, I would need to map the original filename/path to the generated one. To make require(xxxx.png) works in node.

Is there a way to achieve this easily?

@sokra
Copy link
Member

sokra commented Apr 20, 2015

stats.modules[x].assets

@iam4x
Copy link
Author

iam4x commented Apr 20, 2015

@sokra

Let's say I have this:

<img src={require('react-logo.png')} />

In my stats.json if I search for react-logo there's no results. I want to map the original filename to the generated one.

To achieve something like that:

{
  'react-logo.png': '28D983jdui.png'
}

Or am I thinking in the wrong way?

@sokra
Copy link
Member

sokra commented Apr 20, 2015

in stats.modules you have all modules in this format:

{
    id: 11,
    identifier: "...\\node_modules\\file-loader\\index.js!...\\test\\browsertest\\img\\image.png",
    name: "(webpack)/~/file-loader!./img/image.png",
    size: 81,
    cacheable: true,
    built: true,
    optional: false,
    prefetched: false,
    chunks: [0],
    assets: ["c31e9820c001c9c4a86bce33ce43b679.png"],
    issuer: "...\\test\\browsertest\\lib\\index.web.js",
    profile: {
        factory: 245,
        building: 121
    },
    failed: false,
    errors: 0,
    warnings: 0,
    reasons: [
        {
            moduleId: 0,
            moduleIdentifier: "...\\test\\browsertest\\lib\\index.web.js",
            module: "./lib/index.web.js",
            moduleName: "./lib/index.web.js",
            type: "cjs require",
            userRequest: "!file!../img/image.png",
            loc: "105: 3-36"
        }
    ],
    source: 'module.exports = __webpack_public_path__ + "c31e9820c001c9c4a86bce33ce43b679.png"'
}

assets: ["c31e9820c001c9c4a86bce33ce43b679.png"]

@iam4x
Copy link
Author

iam4x commented Apr 20, 2015

Thanks found it 👍

@iam4x iam4x closed this as completed Apr 20, 2015
@catamphetamine
Copy link

FYI
https://github.com/halt-hammerzeit/webpack-isomorphic-tools

This module enables the thing you tried to implement (requiring images on server for example)

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

3 participants