Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/393.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Webpack 2文件加载器返回stringized module.exports_Javascript_Webpack_Webpack File Loader - Fatal编程技术网

Javascript Webpack 2文件加载器返回stringized module.exports

Javascript Webpack 2文件加载器返回stringized module.exports,javascript,webpack,webpack-file-loader,Javascript,Webpack,Webpack File Loader,当我尝试通过导入JS中的一些资源(不是样式,它们工作正常)图像或字体时 import Logo from 'img/logo.png' 我收到奇怪的JSON.stringifiedstring module.exports=\uuuuuuu webpack\upublic\uu path\uuuuuu+“img/logo.png” 当我将publicPath设置为/时,我收到以下消息: module.exports=“img/logo.png” 这是我的网页配置。我做错了什么 const is

当我尝试通过导入JS中的一些资源(不是样式,它们工作正常)图像或字体时

import Logo from 'img/logo.png'
我收到奇怪的
JSON.stringified
string

module.exports=\uuuuuuu webpack\upublic\uu path\uuuuuu+“img/logo.png”

当我将publicPath设置为
/
时,我收到以下消息:

module.exports=“img/logo.png”

这是我的网页配置。我做错了什么

const isDevelopment=process.env.NODE\u env!='生产",

const CONTEXT = 'frontend';
const alias = ['img', 'img/icons', '/scss', '/src', '/src/_common', '/src/_common/functions'];

const PLUGINS = [
  new ExtractTextPlugin({
    filename: (isDevelopment) ? '[name].css' : '[hash:12].css',
    disable: isDevelopment && !process.env.CSS
  }),
  new webpack.DefinePlugin({
    NODE_ENV: JSON.stringify(process.env.NODE_ENV)
  }),
  new HtmlWebpackPlugin({
    template: './index.html'
    // favicon: './favicon.ico'
  }),
  new webpack.optimize.CommonsChunkPlugin({
    name: 'vendor',
    minChunks: Infinity
  })
];

if (isDevelopment) {
  PLUGINS.push(new webpack.NamedModulesPlugin());
} else {
  PLUGINS.push(new webpack.optimize.UglifyJsPlugin());
  PLUGINS.push(new webpack.BannerPlugin({
    banner: `
    /* ${packageJSON.name} app v${packageJSON.version}.
    * Under ${packageJSON.license} protection.
    * Made by: ${packageJSON.author}.
    * ================================================================== */`,
    entryOnly: true,
    raw: true
  }));
}

const jsLoader = {
  test: /\.jsx?$/,
  exclude: /node_modules/,
  use: 'babel-loader'
};


const imageLoader = {
  test: /\.(png|jpe?g|gif|svg)?$/,
  exclude: /node_modules/,
  use: [{
    loader: 'file-loader',
    options: {
      publicPath: '',
      outputPath: '',
      name: (isDevelopment) ? '[path][name].[ext]' : '[hash:12].[ext]'
    }
  }]
};
if (!isDevelopment) {
  imageLoader.use.push({
    loader: 'image-webpack-loader',
    options: {

    }
  });
}

const fontLoader = {
  test: /\.(ttf|eot|svg|woff(2)?)(\?[a-z0-9#=&.]+)?$/,
  include: /font/,
  exclude: /(node_modules|img)/,
  use: {
    loader: 'file-loader',
    options: {
      name: (isDevelopment) ? '[path][name].[ext]' : '[hash:12].[ext]'
    }
  }
};

module.exports = {
  devtool: (isDevelopment) ? 'source-map' : false,
  context: path.resolve(__dirname, CONTEXT),
  entry: {
    vendor: Object.keys(packageJSON.dependencies),
    app: ['babel-polyfill', './src/app.js']
  },
  output: {
    path: path.resolve(__dirname, (isDevelopment) ? CONTEXT : 'build'),
    publicPath: '',
    filename: (isDevelopment) ? '[name].js' : '[chunkhash:12].js'
  },
  resolve: {
    alias: Array.prototype.reduce.call(alias, (acc, v) => {
      acc[v.split(/\/_?/).pop()] = path.join(__dirname, CONTEXT, v);
      return acc;
    }, {}),
    extensions: ['.js', '.jsx']
  },
  plugins: PLUGINS,
  module: {
    loaders: [jsLoader, sassLoader, svgLoader, imageLoader, fontLoader]
  }
};

这看起来不像Webpack2配置。Webpack 2配置使用
模块.rules
,但您使用的是
模块.loaders
。看这里