小编Ilv*_*nis的帖子

如何在没有捆绑的情况下在Webpack-React应用程序中加载外部配置文件?

我有一个用React编写并与Webpack捆绑在一起的Web应用程序.该应用程序有一个JSON配置文件,我希望在运行时包含该文件,而不是与webpack捆绑在一起.

在我的应用程序入口点我使用json-loader导入内容,但这样做会强制将文件嵌入到应用程序中,并且在捆绑后我无法更新配置文件.

如何配置我的webpack.config.js文件以排除我的config.json文件但仍允许我在我的应用程序中导入它?它不是一个模块,所以我不知道它是否可以包含在externals我的webpack.config.js部分中

我尝试使用require.ensure,但我现在看到的是捆绑到1.1.bundle.js文件中的config.json的内容,更改配置文件什么都不做.

app.js

let config;
require.ensure(['./config.json'], require => {
    config = require('./config.json');
});
Run Code Online (Sandbox Code Playgroud)

externals reactjs webpack

11
推荐指数
1
解决办法
3074
查看次数

模拟用于MEAN应用程序单元测试的MongoDB连接

我一直在绞尽脑汁试图找出一种方法来处理模拟我的MongoDB连接以进行单元测试.我想知道这样做的正确方法是什么,因为我的应用程序布局可能是个问题.这适用于包含大量模块的大型项目.

总体布局

 package.json
 server.js
-models
    -index.js
    -users.js
    -events.js
    -...
-services
    -index.js
    -userActivity.js
    -...
 +public
+routes
+util
+test
Run Code Online (Sandbox Code Playgroud)

车型/ users.js

"use strict";
modules.export = function(mongoose) {
  var Schema = mongoose.Schema;
  var userSchema = new Schema({ name: String });
  var userModel = mongoose.model('User', userSchema);
  var userDAO {};

  userDAO.addUser(user) {
    var newUser = new userModel(user);
    return newUser.save();
  }

  userDAO.getUser(id) {
    return userModel.findById(id).lean().exec();
  }

  return userDAO;
};
Run Code Online (Sandbox Code Playgroud)

车型/ index.js

"use strict";
var bluebird= require('bluebird');
var mongoose = bluebird.promisifyAll(require('mongoose'));

var Users = require ('./users');
var …
Run Code Online (Sandbox Code Playgroud)

unit-testing mongodb node.js

5
推荐指数
1
解决办法
1219
查看次数

标签 统计

externals ×1

mongodb ×1

node.js ×1

reactjs ×1

unit-testing ×1

webpack ×1