Webpack and assets/dist folder

时间:2018-02-03 09:44:34

标签: url webpack static assets angular5

I'm using Angular5 and webpack for generate the dist folder. For generating the assets folder i'm using the "copy-webpack-plugin". It copies the assets folder from /src/assets into /dist folder. The problem is: all the path used by a admin console template of my src code uses relative paths starting from "assets/..." and the server include /dist/assets. All static resources will throw 404 not found. What is the best way to include an assets folder into a dist folder?

1 个答案:

答案 0 :(得分:0)

我建议使用为此目的而设计的file-loader

webpack.config.js中配置后,您可以导入文件的路径以便在JavaScript中使用,如果您还使用html-loader,则可以导入HTML模板。

const myImageUrl = require('./path/to/an/image.png')

doSomething(myImageUrl)