我无法从es2015 NPM模块导入导出的变量

时间:2016-10-07 03:51:23

标签: npm ecmascript-6 webpack

我有一个名为sidebar的npm模块。我使用webpack将es2015 src文件编译成单个文件。到目前为止,运行webpack不会输出任何问题并创建文件lib/sidebar.min.js

我已将其设置为package.json

中的主文件
...
"description": "",
"main": "lib/sidebar.min.js",
"scripts": {
...

我在src/index.js文件

中有这个
export const foo = 'foo'
export const bar = 'bar'

我尝试在我的主项目中使用此模块

import { foo, bar } from 'sidebar'
console.log(foo)
console.log(bar)

两个控制台日志调用都输出undefined

在互联网上搜索了几个小时之后,我完全不知道为什么这是一个问题。

有什么想法吗?

编辑:这是主存储库的webpack配置

var webpackConfig = {
    entry: {
        app: './src/app/main.app.js',
        vendor: ['angular']
    },
    output: {
        path: DIST_DIRECTORY + '/scripts/',
        publicPath: '/scripts/',
        filename: '[name].min.js',
        chunkFilename: '[name].min.js'
    },
    devtool: 'source-map',
    module: {
        loaders: [{
            test: /\.js$/,
            loader: 'babel'
        }, {
            test: /\.html$/,
            loader: 'raw'
        }]
    },
    plugins: [
        new webpack.NoErrorsPlugin(),
        new webpack.optimize.DedupePlugin(),
        new webpack.optimize.UglifyJsPlugin({
            compress: {
                unused: true,
                dead_code: true
            },
            sourceMap: true
        }),
        new webpack.DefinePlugin({
            'process.env': {
                'NODE_ENV': JSON.stringify('production')
            }
        }),
        new webpack.optimize.CommonsChunkPlugin("vendor", "vendor.bundle.js")
    ],
    devServer: {
        contentBase: DIST_DIRECTORY + '/'
    }
};

0 个答案:

没有答案
相关问题