使用Django进行Heroku部署:Webpack Bundle返回index.html的内容而不是实际的bundle

时间:2017-03-19 18:22:45

标签: django heroku webpack production

应用程序在开发中运行良好,但一旦投入生产,生成的webpack包文件将提供index.html的内容,而不是所有捆绑的模块和依赖项。

每当我检查服务器上的捆绑文件时,一切似乎都没问题,但在客户端上以不同的方式提供相同的路径。

webpack.config.js

//require our dependencies
var path = require('path')
var webpack = require('webpack')
var BundleTracker = require('webpack-bundle-tracker')

module.exports = {
    //the base directory (absolute path) for resolving the entry option
    context: __dirname,
    //the entry point we created earlier. Note that './' means 
    //your current directory. You don't have to specify the extension  now,
    //because you will specify extensions later in the `resolve` section
  entry: [
      './assets/js/index'
  ],    
  output: {
      path: path.resolve('./assets/bundles/'), 
      filename: "[name]-[hash].js"
  },

    plugins: [
        //tells webpack where to store data about your bundles.
        new webpack.NoErrorsPlugin(), // don't reload if there is an error
        new BundleTracker({filename: './webpack-stats.json'}), 
        //makes jQuery available in every module
        new webpack.ProvidePlugin({ 
            jQuery: 'jquery',
            'window.jQuery': 'jquery' 
        })
    ],

  module: {
    loaders: [
      // we pass the output from babel loader to react-hot loader
      { 
        test: [/\.js$/, /\.es6$/, /\.jsx?$/],
        exclude: /node_modules/, 
        loaders: ['babel'], 
      },
      { test: /\.css$/, loader: "style-loader!css-loader" }
    ]
  },

    resolve: {
        //tells webpack where to look for modules
        modulesDirectories: ['node_modules'],
        //extensions that should be used to resolve modules
        extensions: ['', '.js', '.jsx'] 
    }   
}

服务内容:

Uncaught SyntaxError: Unexpected token <

<!DOCTYPE html>  
<html lang="en">  
  <head>
    <meta charset="utf-8">
    <!--<title></title>-->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script type="text/javascript" src="/static/jquery/dist/jquery.js"></script>
    <script type="text/javascript" src="/static/materialize-css/dist/js/materialize.min.js"></script>
  </head>
  <body>
      <div id="container"></div>
      <script type="text/javascript" src="/static/assets/bundles/main-210eb139915d8d6abedf.js" ></script>
  </body>

提前致谢。

0 个答案:

没有答案