Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/376.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 发送html而不是js_Javascript_Node.js_Webpack - Fatal编程技术网

Javascript 发送html而不是js

Javascript 发送html而不是js,javascript,node.js,webpack,Javascript,Node.js,Webpack,我尝试用express配置webpack。但在浏览器cosole中的bundle.js中,我看到了与html文件中相同的代码,而不是预期的js。这是我的服务器配置: const express = require('express'); const app = express(); const http = require('http'); const webpack = require('webpack'); const webpackConfig = require('./webpack/w

我尝试用express配置webpack。但在浏览器cosole中的bundle.js中,我看到了与html文件中相同的代码,而不是预期的js。这是我的服务器配置:

const express = require('express');
const app = express();
const http = require('http');
const webpack = require('webpack');
const webpackConfig = require('./webpack/webpack.config');
const compiler = webpack(webpackConfig);

app.use(express.static(__dirname + '/'));

app.get(/.*/, function (req, res) {
  res.sendFile(__dirname + '/index.html');
  console.log(webpackConfig);
});

app.use(function(res, req, next) {
    const err = new Error('You have 404 error!');
    err.status = 404;
});

let server = http.createServer(app);
server.listen(3000, function onListening() {
    const address = server.address();
    console.log('This is port ' + address.port);
});
这是一个网页:

require('babel-polyfill').default;
const path = require('path');

const common = {
    entry: path.join(__dirname, '../src'),
    output: {
        path: path.join(__dirname, '../dist'),
        filename: 'bundle.js',
        publicPath: 'dist/',
        library: "home"
    },
    watch: true,
    watchOptions:{
        aggregateTimeout: 100
    },
    module: {
        loaders:[{
            test: /\.js$/,
            loaders: ['babel-loader'],
            exclude: /node_modules/,
        }]
    }
}

module.exports = common;
在index.html中,我包含如下js:

src="/dist/bundle.js"
文件夹的结构是:

.
├── bin
│   └── index.js
├── index.html
├── package.json
├── server.js
├── src
│   └── index.js
└── webpack
    └── webpack.config.js

是的,我们可以用Html代替Js。因为它很容易理解,对于入门级的学生来说也不会有任何混淆。

不,我的意思是,与其将网页包文件与js it plugged index.html文件捆绑在一起,不如使用js it plugged index.html文件