模块解析不适用于babel节点

时间:2017-06-22 09:47:20

标签: node.js reactjs babel

所以在我的webpack中解析app文件夹(在我的app文件夹中是"容器"和"组件"文件夹)

const express = require("express");
const path = require("path");
const bodyParser = require("body-parser");
const cookieParser = require("cookie-parser");

let server = express();

server.set("port", (process.env.PORT || 5000));

server.use(cookieParser());

server.use(bodyParser.json());
server.use(bodyParser.urlencoded({extended: true}));

server.use((req, res, next) => {
    // if req.cookies exists and testcookie is undefined within req.cookies
    if (req.cookies && typeof req.cookies["testcookie"] === "undefined") {
        console.log("Setting cookie! Testcookie was not found");
        res.cookie("testcookie", "test", {
            maxAge: ((((1000 * 60) * 60) * 24) * 7), /* expire a week from today */
            httpOnly: true /* document.cookie doesn't return this cookie */
        });
    }
    next();
});

const exampleMiddleWare = (req, res, next) => {
    res.hasTestCookie = !!req.cookies.testcookie
    next();
};

server.get("/", exampleMiddleWare, (req, res) => {
    res.send(`<h1>Cookie Test</h1><h2>Cookie Found: ${res.hasTestCookie}</h2>`);
});

server.listen(server.get("port"), () => {
    console.log("Server started!");
});

然后我使用babel节点进行测试..这里是server.js

 resolve:{
    modules:[
      path.join(process.cwd(), 'app'),
     path.join(process.cwd(), 'node_modules'),
    ],
    extensions: ['.js', '.jsx']
  },

错误是节点无法找到容器/应用程序/路由&#39;但如果我改变下面的server.js,它就可以了。

 import path from 'path'
 import { Server } from 'http'
 import Express from 'express'
 import React from 'react'
 import { renderToString } from 'react-dom/server'
 import { match, RouterContext } from 'react-router'
 import Routes from 'containers/App/Routes'

我是否需要添加一些配置以便节点也能读取我的webpack解析模块?它在webpack devserver中正常工作

0 个答案:

没有答案