I have an Aurelia application with a file structure like this. I m using aurelia skeleton-typescript-webpack 1.0.0
|-- assets
|-- images
|-- imageA.jpg
|-- imageB.jpg
|-- src
|-- app.ts
|-- main.ts
|--views
|-- viewA.ts
|-- viewA.html
Right now in viewA.html if I want to link an image, I do it with an absolute path :
<img src="/assets/images/imageA.jpg">
But on production, the app will be at : http://domain.com/app/, so absolute path is not an option.
If I use a relative path on dev environment, aurelia-loader-webpack throw a can't resolve error.
<img src="assets/images/imageA.jpg">
Module not found: Error: Can't resolve './assets/images/imageA.jpg' in '/app/src/views'
@ ./src/views/viewA.html 1:191-213
@ ./src ^\.\/.*$
@ ./~/aurelia-loader-webpack/dist/commonjs/aurelia-loader-webpack.js
is there a way to setup up the path on dev environnement so assets are loaded from the right folder ? Or to change the img src to relive when i run build:prod ?
Eventually What I'd like to do is use this in my template:
<img src="imageA.jpg">
That will get transformed on absolute /assets/images/ on run dev env, and relative assets/images/ on build prod.
I guess that's something that I can do in webpack.config.ts, but couldn't find a way.
EDIT, here is the webpack loaders
{ loaders:
[ { test: /\.tsx?$/,
loader: 'awesome-typescript',
exclude: [Object] },
{ test: /\.html$/, loader: 'html', exclude: [Object] },
{ test: /\.scss$/i,
loaders: '/App/node_modules/extract-text-webpack-plugin/loader.js?{"id":1,"omit":0,"remove":true,"notExtractLoader":"style"}!css!sass' },
{ test: /\.css$/i,
loaders: '/App/node_modules/extract-text-webpack-plugin/loader.js?{"id":2,"omit":0,"remove":true,"notExtractLoader":"style"}!css' },
{ test: /\.(png|gif|jpg)$/, loader: 'url', query: [Object] },
{ test: /\.woff2(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url',
query: [Object] },
{ test: /\.woff(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'url',
query: [Object] },
{ test: /\.(ttf|eot|svg|otf)(\?v=[0-9]\.[0-9]\.[0-9])?$/,
loader: 'file' }
] }