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

发布于 2022-09-12 03:29:01 字数 1539 浏览 7 评论 0

问题同上,贴下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'
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文