webpack dev服务器为图像名称添加前缀

时间:2017-04-07 02:11:09

标签: webpack webpack-dev-server

webpack-dev-server正在为图像文件名添加前缀'dist',而webpack -p不添加'dist'前缀。我在youtube上完成了Petr Tichy的教程,我只是看不到webpack.config.js文件中的问题所在。它不是为其他文件添加前缀,只是图像文件名。你能看出这里的问题是什么吗?

    var HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const path = require("path");

module.exports = {
    entry: './src/app.js',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'app.bundle.js'
    },
    module:{
       rules:  [
          {
            test: /\.scss$/, 
              use: ExtractTextPlugin.extract({
                fallback: 'style-loader',
                use: ['css-loader','sass-loader'],
                publicPath: '/dist'
              })
          },
            {

              test: /\.(gif|png|jpe?g|svg)$/i,
              use: 'file-loader'
            }   
         ]
    },
     devServer: {
        contentBase: path.join(__dirname, "dist"),
        compress: true,
        port: 9000,
        stats: "errors-only",
        open: true
    },
    plugins: [
      new HtmlWebpackPlugin({
        title: 'The Title',
        minify: { 
          collapseWhitespace: true
        },
        hash: true,
        template: './src/index.ejs', // Load a custom template (ejs by default see the FAQ for details)
      }),
      new ExtractTextPlugin({
            filename: 'app.css',
            disable: false,
            allChunks: true
        })
    ]
}

这是package.json文件:

{
  "name": "thename",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "serve": "webpack-dev-server",
    "dev": "webpack -d --watch",
    "prod": "webpack -p"
  },
  "author": "",
  "license": "ISC",
  "devDependencies": {
    "css-loader": "^0.28.0",
    "extract-text-webpack-plugin": "^2.0.0-rc.0",
    "file-loader": "^0.11.1",
    "html-webpack-plugin": "^2.28.0",
    "image-webpack-loader": "^3.3.0",
    "node-sass": "^4.5.2",
    "sass-loader": "^6.0.3",
    "style-loader": "^0.16.1",
    "webpack": "^2.3.3",
    "webpack-dev-server": "^2.4.2"
  }
}

0 个答案:

没有答案