2016-06-27 8 views
0

test.js

console.log(require('./../images/xxx.png')); 
// images/xxx.png 
// correct should be ../images/xxx.png 

내가

webpack.config.js 필요에 의해 또는 로더 웹팩 발생하는 문제를 모르는 올바르지 않은 이미지 경로를 필요로

output : { 
    path : path.join(__dirname,'public'), 
    publicPath : '/public/' 
} 

{ 
    test: /\.(png|jpg)$/, 
    loaders: ['url?limit=8192&&name=images/[name].[ext]&context=./public/'] 
} 

로더 업데이트

loaders: ['url?limit=8192&&name=../images/[name].[ext]&context=./public/'] 
console.log(require('./../images/xxx.png')); 
// It's correct ../images/xxx/png. 
// But image will not in public/images folder 
+0

간단히 '../images/xxx.png'해 보셨습니까? –

+0

@MichaelPratt 예, 시도했습니다 이미지를 성공적으로 표시 할 수 있지만 이미지 폴더에 아무 것도 없습니다 – mqliutie

+0

@MichaelPratt 마지막으로 publicPath를 '../'로 수정했습니다. – mqliutie

답변

0

파일 로더와 연결된 이미지 로더를 추가해야합니다. 이런 식으로.

loaders: [ 
     { 
     test: /.*\.(gif|png|jpe?g|svg)$/i, 
     loaders: [ 
      'file?hash=sha512&digest=hex&name=[hash].[ext]', 
      'image-webpack' 
     ] 
     } 
    ]