Webpack不在浏览器中呈现应用程序

时间:2015-12-01 11:59:05

标签: webpack webpack-dev-server

我已经成功地使用webpack进行构建并尝试使用https://localhost:9000在浏览器中打开我的应用程序,但它没有显示任何内容....任何想法可能是什么原因?它只是说“这个网页不可用”

我的webpack.config.js是

var webpack = require('webpack');
var path = require('path');
var prod = process.env.prod;
var hot = process.env.hot;
//Variables
var plugins = [];
var dest;

var ngAnnotatePlugin = require('ng-annotate-webpack-plugin');
plugins.push(new ngAnnotatePlugin({
  add: true
}));

var nodeModulesPath = path.join(__dirname, 'node_modules');
var bowerComponentsPath = path.join(__dirname, 'bower_components');

var bowerResolvePlugin = new webpack.ResolverPlugin(
  new webpack.ResolverPlugin.DirectoryDescriptionFilePlugin("bower.json", ["main"])
);

plugins.push(bowerResolvePlugin);

//Setup Webpack
if (prod) {
  dest = path.join(__dirname, 'dist');
  config.output.filename = config.output.filename.replace('.js', '.min.js');
  config.output.sourceMapFilename = config.output.sourceMapFilename.replace('.js', '.min.js');
} else {
  dest = path.join(__dirname, '.tmp');
}



module.exports = {
  devtool: 'source-map',
  debug:true,
  context: __dirname,
  devServer: {
    inline: true,
    colors: true,
    historyApiFallback: true,
   // host: 'localhost',
   // port: 9000,
   // contentBase: './app'
  },
  entry: {
    app: './app/scripts/app.js'
  },
  proxy: {
        '*': 'http://localhost:9000'
    },
  output: {
    path: dest,
    filename: 'scripts.js',
    sourceMapFilename: 'scripts.js.map',
    publicPath: 'http://localhost:9000/app'   
  },
  resolve: {
    root: './bower_components',
   },
  module: {
    loaders: [
      {test: /\.js$/, exclude: /(node_modules|bower_components)/, loader: 'babel'},
      {test: /\.less$/, loader: 'style!css!less'},
      {test: /\.html$/, loader: 'html'},
     {test: /\.(woff|woff2|ttf|eot|svg|png|gif|jpg)(\?v=[0-9]\.[0-9]\.[0-9])?$/, loader:'file-loader?name=res/[name].[ext]?[hash]'}
     
    ]
    
  },
  plugins: plugins
};


//Setup build
if (prod) {
  var err = function (err) {
    if (err) throw console.error(err);
  };
  var fs = require('fs-extra');
  var minify = require('html-minifier').minify;

  fs.emptyDir('./dist', function (err) {
    if (err) throw console.error(err);
    fs.readFile('./app/index.html', 'utf8', function (err, data) {
      if (err) throw console.error(err);
      var result = minify(data, {
        removeComments: true,
        collapseWhitespace: true,
        removeRedundantAttributes: true,
        useShortDoctype: true,
        removeScriptTypeAttributes: true,
        removeStyleLinkTypeAttributes: true,
        removeOptionalTags: true
      });
      fs.writeFile('./dist/index.html', result, err);
    });
  });
}

亲爱的回顾并告诉我......

0 个答案:

没有答案