webapck打包libary后使用import导入为undefined

问题同上,贴下webpack的配置
`

//webpack.config.js
// const HtmlWebpackPlugin = require('html-webpack-plugin')
// const webpack = require('webpack')
const path = require('path')
const TerserPlugin = require('terser-webpack-plugin')
module.exports = {
    mode: process.env.NODE_ENV,
    entry: './src/index.js',
    devtool: 'source-map',
    output: {
        path: path.resolve(__dirname, 'dist'), //必须是绝对路径
        filename: 'bundle.js',
        library: 'sdk',
        libraryExport: 'AdvertSdk',
        libraryTarget: 'umd',
        umdNamedDefine: true
    },
    // node: {
    //     process: false
    // },
    module: {
        rules: [{
            test: /\.js?$/,
            use: ['babel-loader'],
            exclude: /node_modules/ //排除 node_modules 目录
        }],
    },
    optimization: {
        minimize: false,
        minimizer: [
            new TerserPlugin({
                sourceMap: true, // Must be set to true if using source-maps in production
                terserOptions: {
                    compress: {
                        drop_console: true,
                    },
                },
            })
        ]
    },
    plugins: [
        // new webpack.optimize.UglifyJsPlugin({
        //     compress: {
        //         warnings: false,
        //         drop_console: false,
        //     }
        // }),
    ]
}

`
打包index.js的文件之后,在其他项目用import总是undefined是什么原因,使用的是webpack4的版本
index.js文件为

export default {
    name: 'name'
}
阅读 4.3k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题