在webpacking之后对库进行“未定义”

时间:2016-10-14 19:32:45

标签: reactjs webpack react-redux

我正在尝试使用webpack编译 server.jsx 。它编译,但是当我运行文件时,我得到“...未定义”错误。喜欢:“快递没有定义”。如果我检查已编译的源代码,我可以看到express显然是一个未定义的变量。 这是我的 webpack.config

{
   target: 'node',
   entry: {
    app: "./src/app/app.js",
   },
   output: {
    path: __dirname + "/dist/assets/",
    filename: "./js/app.js"
   }
   ,
   externals: [
    /^(?!\.|\/).+/i,
   ],
   module: {
       loaders: [{
        test: /\.html$/,
        loader: "file?name=[name].[ext]"
       },
       {
        test: /\.jsx?$/,
        exclude: /node_modules/,
        loaders: ["react-hot", 'babel?'+JSON.stringify(
            {
                presets: ['react', 'es2015'],
                "plugins": [
                    "syntax-class-properties",
                    "syntax-decorators",
                    "syntax-object-rest-spread",
                    "transform-class-properties",
                    "transform-object-rest-spread"
                ]
            }
        )]
       }]
   }
}; 

我想也许我应该使用 libraryTarget ,但我真的不知道我该怎么做。例如:如果我想使用express和mongoose,我应该在哪里设置它?

修改 Server.jsx:

'use strict';
require('babel-core/register'); 
import express from 'express';
import path from 'path';

import mongoose from 'mongoose';

import { renderToString } from 'react-dom/server'
import { Provider } from 'react-redux'
import React from 'react';
import store from '../app/store'
import { RouterContext, match } from 'react-router';
import routes from '../app/routes/routes.jsx';
import { createLocation } from 'history';
import cors from 'cors';

const app = express();
...

0 个答案:

没有答案