javascript - How to use es6 import for images -
i'm using es6 , want import image use webpack. looking @ file-loader doc, example gave:
var url = require("file!./file.png");
url return /static/351f9446b3ba577b6a79e373e074d200.png
this works require, how use import
this, i've tried -
import * url '../images/151.png';
but doesn't work because url remains undefined. how set variable i'm importing when it's image?
import * url '../images/151.png';
but doesn't work because url remains undefined. how set variable i'm importing when it's image?
using webpack 2.0 file-loader plugged-in. works in case, import returns object bytemap instead of data-uri string;
and object has 'default' property, contains same data, if required.
honestly im'not sure object, , why there default property thats how i'v made works.
import '../css/bootstrap.css'; import '../css/app.scss'; import * url '../images/webpack_logo.png'; let img = document.createelement('img'); img.style = { height: '25%', width: '25' }; debugger; img.src = url.default; console.log('imported', url); document.getelementbyid('img_container').appendchild(img);
the way mentioned in previous answer returned undefined, btw. , it's expected cuase that's syntax relyes on default export been declared on source module.
Comments
Post a Comment