webpack4 pit library packed encounter

    output: {
        publicPath: '/',
        path: path.join(__dirname, 'lib'),
        filename: 'chart.js',
        library: 'tcharts',
        libraryTarget: 'umd', umdNamedDefine: true, },

output configuration, mainly libraryTarget and umdNamedDefine.

Another point is the babel configuration need to add "sourceType": "unambiguous" in this configuration.

Because webpack4 not supported export default and module.exports mix, and we usually use in the project is a way to export default, and webpack packed library is module.exports way, so do not add this configuration, the use of import to load webpack packaged library get is undefined. After adding this would speculate by grammar, so that it can be used normally. 

Guess you like

Origin www.cnblogs.com/3body/p/11855191.html