The url-loader is able to publish the images in appropriate directory as specified however, the image path specified in the bundled js file is incorrect.
Webpack.config.js
/* Custom Config */
var ProgramID = '2999';
/* Default Config */
var webpack = require('webpack');
var path = require('path');
var polyfill = require("babel-polyfill");
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var BUILD_DIR = path.resolve(__dirname, 'build/Programs/' + ProgramID);
var APP_DIR = path.resolve(__dirname, 'src/import');
module.exports = {
entry: [
'babel-polyfill',
'webpack-dev-server/client?http://localhost:8080/',
APP_DIR + '/import.js'
],
output: {
path: BUILD_DIR + '/',
filename: '/js/bundle.js'
},
module: {
loaders: [{
test: /\.jsx?$/,
loaders: ['react-hot', 'babel?presets[]=es2015,presets[]=react,plugins[]=transform-runtime'],
exclude: /node_modules/
}, {
test: /\.css$/,
loader: ExtractTextPlugin.extract("style-loader", "css-loader")
}, {
test: /\.scss$/,
loader: ExtractTextPlugin.extract(['css','sass'])
}, {
test: /\.(png|woff|woff2|eot|ttf|svg|jpg|gif)$/,
loader: 'url-loader?limit=10&name=../../Programs/' + ProgramID + '/images/[name].[ext]'
}]
},
plugins: [
new ExtractTextPlugin("style.css"),
new webpack.HotModuleReplacementPlugin(),
new webpack.NoErrorsPlugin()
],
process: function(path, filename) {
if (filename.indexOf('node_modules') === -1) {
path = babelJest.process(path, filename);
path = webpackAlias.process(path, filename);
}
return path;
},
externals: {
"jquery": "jQuery"
}
};
The path generated in bundled file is http://localhost:8080/Programs/2999/images/chart-1.png
but I need the path to be http://localhost:8080/build/Programs/2999/images/chart-1.png
.
Although by changing the path in webpack.config.js from 'url-loader?limit=10&name=../../Programs/' + ProgramID + '/images/[name].[ext]'
to 'url-loader?limit=10&name=../Programs/' + ProgramID + '/images/[name].[ext]'
fixes the path in bundled js file it outputs image in different folder so its of no use. Is there a way by which I can specify paths separately for output image directory and path defined within bundled js file.