Webpack Image Loader设置

时间:2016-10-15 18:53:12

标签: javascript json webpack webpack-style-loader

我是Webpack的新手,请原谅我,如果这是一个微不足道的问题,但我在使用Image Webpack Loader时遇到了麻烦。

查看我的时间线Google Webdeveloper,我发现我的图片没有被压缩。

这是我当前的设置:

的WebPack

var path = require('path');
var webpack = require('webpack');
module.exports = {
  devtool: 'source-map',
  entry: [
    './src/index.js'
  ],
  output: {
    path: __dirname,
    publicPath: '/',
    filename: 'bundle.js'
  },
  module: {
    loaders: [{
      exclude: /node_modules/,
      loader: 'babel',
      query: {
        presets: ['react', 'es2015', 'stage-1']
      }
    },{
      test: /\.s?css$/,
      loaders: ['style','css','sass'],
      include: path.join(__dirname, 'src')
    },{
      test: /\.(jpe?g|png|gif|svg)$/i,
      loaders: [
        'file?hash=sha512&digest=hex&name=[hash].[ext]',
        'image-webpack?bypassOnDebug&optimizationLevel=7&interlaced=false'
      ],
      include: path.join(__dirname, 'src/image')
    }]
  },
  plugins: [
    new webpack.optimize.UglifyJsPlugin({minimize: true}),
    new webpack.DefinePlugin({
      'process.env': {
        'NODE_ENV': JSON.stringify("production")
      }
    })
  ],
  resolve: {
    extensions: ['', '.js', '.jsx'],
    alias: {
    'jquery': path.join(__dirname, 'node_modules/jquery/dist/jquery'),
    }
  },
  devServer: {
    historyApiFallback: true,
    contentBase: './'
  }
};

的package.json

{
  "name": "portfolio-remodeled",
  "version": "1.0.0",
  "description": "Portfolio",
  "main": "index.js",
  "repository": "",
  "scripts": {
    "start": "node ./node_modules/webpack-dev-server/bin/webpack-dev-server.js",
    "test": "mocha --compilers js:babel-core/register --require ./test/test_helper.js --recursive ./test",
    "test:watch": "npm run test -- --watch",
    "postinstall": "webpack -p"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "babel-core": "^6.2.1",
    "babel-loader": "^6.2.0",
    "babel-preset-es2015": "^6.1.18",
    "babel-preset-react": "^6.1.18",
    "chai": "^3.5.0",
    "chai-jquery": "^2.0.0",
    "image-webpack-loader": "^2.0.0",
    "jquery": "^3.1.0",
    "jsdom": "^9.5.0",
    "mocha": "^3.0.2",
    "node-sass": "^3.8.0",
    "react-addons-test-utils": "^15.3.1",
    "webpack": "^1.13.2",
    "webpack-dev-server": "^1.14.0"
  },
  "dependencies": {
    "babel-preset-stage-1": "^6.1.18",
    "css-loader": "^0.25.0",
    "express": "^4.14.0",
    "jquery": "^2.2.4",
    "lodash": "^4.16.1",
    "materialize-css": "^0.97.7",
    "node-sass": "^3.8.0",
    "react": "^15.3.1",
    "react-bootstrap": "^0.30.3",
    "react-dom": "^15.3.1 ",
    "react-materialize": "^0.16.4",
    "react-redux": "^4.0.0",
    "react-router": "^2.0.1",
    "react-tap-event-plugin": "^1.0.0",
    "redux": "^3.0.4",
    "redux-logger": "^2.6.1",
    "sass-loader": "^4.0.0",
    "shortid": "^2.2.6",
    "style-loader": "^0.13.1"
  }
}

我的目录设置:

enter image description here

我错过了什么?

0 个答案:

没有答案