leijing7 / wx-mina-meteor

一个微信小程序通过 DDP 协议和 Meteor 后端交换数据的简单例子
32 stars 13 forks source link

webpacks 打包好的asteroid,提示underfind #1

Open marlti7 opened 8 years ago

marlti7 commented 8 years ago

引入路径没有问题

leijing7 commented 7 years ago

https://github.com/Micjoyce/wechat-mina-ddp-example

There is another new and updated repo might help you.

kedeng commented 5 years ago

webpack的配置文件 libraryTarget:'commonjs2' 如果不设置这个,将不会导出任何函数。

  entry: './src/asteroid.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'asteroid.bundle.js',
    libraryTarget:'commonjs2'
  },
  devtool: 'source-map',
  mode: 'development',
};

另外asteroid还会有一个Websocket初始化的错误,解决方法是使用weapp.socket.io, 将SocketConstructor 设成 socketio

const socketio =  require("../webpacknpm/weapp.socket.io/dist/weapp.socket.io.js");
const asteroid = require("../webpacknpm/asteroid/dist/asteroid.bundle.js");

function initAsteroid(endPoint){
    const Asteroid = asteroid.createClass();
    // Connect to a Meteor backend
    const asteroidInst = new Asteroid({
      endpoint: endPoint,
      SocketConstructor: socketio
    });
    return asteroidInst;
}

module.exports = {
    initAsteroid
}