2017-09-15 185 views
0

我得到一个空白的html文档。但是,当我查看src代码时,我看到我的脚本标记引用dist/app.js,这是我的捆绑代码。webpack输出不显示在index.html中

这是我的WebPack这里是我的index.html

而且,这里是我的文件夹结构。

/dist/app.js 
/node_modules 
/src/index.js 
index.html 
package.json 
webpack.config.js 

var ExtractTextPlugin = require('extract-text-webpack-plugin');

module.exports = { 
    entry: { 
    homepage: './src/index.js', 
    }, 

    output: { 
    filename: './dist/app.js' 
    }, 

    // Resolve the `./src` directory so we can avoid writing 
    // ../../styles/base.css 
    resolve: { 

    extensions: ['.js', '.jsx'] 
    }, 

    // Instruct webpack how to handle each file type that it might encounter 
    module: { 
    loaders:[ 
     { 
     test: /\.js[x]?$/, exclude: /node_modules/, loader: 'babel-loader', 
     query: { 
      ///plugins: ['transform-runtime'], 
      presets: ["es2015", "react"] 
     } 
     } 
    ] 
    }, 

    // This plugin moves all the CSS into a separate stylesheet 
    plugins: [ 
    new ExtractTextPlugin('app.css') 
    ] 
}; 

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Hello</title> 
    </head> 
<body> 
    <script src="/dist/app.js"></script> 
</body> 
</html> 
+0

你如何查看index.html文件?直接从硬盘或通过开发服务器提供? – ideaboxer

+0

通过开发服务器。我正在运行npm start。 – user8280738

+0

浏览器控制台没有错误? – ideaboxer

回答

0

对不起仍不能评论,所以我不得不回答。

我的猜测是路径是关闭的东西也许尝试在蒸馏水面前扔点

<script src="./dist/app.js"></script> 

的WebPack是怪异与路径,我对于新手,所以我不完全掌握它的所有然而。但最终你会希望缓存清除并以编程方式将你的JS包注入到你的index.html中。查看html-webpack-plugin。该插件采用主webpack块生成一个index.html的副本与正确的脚本标记。

我建议https://survivejs.com/webpack/developing/getting-started/#setting-up-webpack-configuration入门与HTML-的WebPack-插件