Webpack url-loader路径问题

时间:2016-06-02 11:47:34

标签: javascript webpack urlloader

url-loader能够在指定的相应目录中发布图像,但是捆绑的js文件中指定的图像路径不正确。

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"
    }
};

捆绑文件中生成的路径为http://localhost:8080/Programs/2999/images/chart-1.png,但我需要路径为http://localhost:8080/build/Programs/2999/images/chart-1.png

虽然通过将webpack.config.js中的路径从'url-loader?limit=10&name=../../Programs/' + ProgramID + '/images/[name].[ext]'更改为'url-loader?limit=10&name=../Programs/' + ProgramID + '/images/[name].[ext]'来修复捆绑的js文件中的路径,但它会将图像输出到不同的文件夹中,因此无用。有没有办法可以为捆绑的js文件中定义的输出图像目录和路径分别指定路径。

0 个答案:

没有答案