【问题标题】:Making a library importable using webpack and babel使用 webpack 和 babel 使库可导入
【发布时间】:2016-09-26 08:59:56
【问题描述】:

我正在尝试在npm (this one) 上发布我正在使用webpackbabel 开发的包。我的代码是用ES6 编写的。我的源文件中有一个文件index.js,它(目前)导出了我的库的一个核心组件,它就像这样:

import TheGamesDb from './scrapers/thegamesdb';
export { TheGamesDb };

我正在使用 webpackbabel 创建一个 dist index.js 这是我的包的主文件。我的webpack.config.js 是这样的:

const webpack = require('webpack');
const nodeExternals = require('webpack-node-externals');

module.exports = {
  entry: {
    index: ['babel-polyfill', './src/index.js'],
    development: ['babel-polyfill', './src/development.js']
  },
  output: {
    path: '.',
    filename: '[name].js',
    library: 'rom-scraper',
    libraryTarget: 'umd',
    umdNamedDefine: true
  },
  devtool: 'source-map',
  module: {
    loaders: [
      { test: /\.js$/, loader: 'babel-loader', exclude: /node_modules/ }
    ]
  },
  target: 'node',
  externals: [nodeExternals()]
};

现在当我在另一个项目中加载我的包并尝试 import 我的导出 TheGamesDb 就像这样

import { TheGamesDb } from 'rom-scraper';

我得到了错误

未捕获的类型错误:路径必须是字符串。收到未定义

需要注意的是,我正在将我的库导入electron

更新:Electron 似乎是这里的主要问题,它甚至不是我的库,而是引发此错误的依赖项(仅在 Electron 中)

【问题讨论】:

    标签: javascript npm webpack electron babeljs


    【解决方案1】:

    问题不是我的问题中的任何问题,而是node-expatelectron 中不起作用。我切换到另一个库,现在一切正常。

    【讨论】:

      猜你喜欢
      • 2016-01-19
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 2015-08-17
      • 1970-01-01
      • 2018-09-22
      • 1970-01-01
      • 2019-10-30
      相关资源
      最近更新 更多