I wrote a small library and now I am trying to translate it to ES6, but also to make a version for normal use, just to connect the script tag and use it. I use webpack and babel-loader. Code from the main library file:
'use strict'; import helpers from './lib/helpers'; import styles from './lib/styles'; import color from './lib/color'; import decorators from './lib/decorators'; import forms from './lib/forms'; import DOM from './lib/DOM'; import namespace from './lib/namespace'; import addMethod from './lib/addMethod'; var eclipse = { globals: {}, storage: { dropdowns: [], bundles: [], spinners: [], staticTabs: [], adaptiveTabs: [], searches: [], cache: {} }, helpers: helpers, styles: styles, color: color, decorators: decorators, forms: forms, DOM: DOM, modules: {} }; eclipse.namespace = namespace.bind(eclipse); eclipse.addMethod = addMethod.bind(eclipse); export default eclipse; Webpack settings:
var webpack = require('webpack'); module.exports = { entry: './eclipse.js', externals: { jquery: 'jQuery' }, output: { path: __dirname, filename: 'eclipse.js', library: 'eclipse', libraryTarget: 'umd', umdNamedDefine: false }, resolve: { extensions: ['', '.js'] }, module: { loaders: [ { loader: 'babel-loader', query: { presets: ['es2015'] }, test: /\.js$/, exclude: /(node_modules)/ } ] }, devtool: null }; It seems everything is going well, but there is one problem. When usually connected via a script tag, an object falls into the global scope:
{ __esModule: true, default: мой объект библиотеки eclipse } It turns out that I can not do so
eclipse.someMethod It falls like this:
eclipse.default.someMethod How can I get around this. I'm not familiar with the webpack. I understand that this happens because of "export default eclipse;", but I don’t know how to get around this. You can of course write "module.exports = eclipse;" but maybe there is another way? Maybe my method of assembly is not suitable at all? I did not do anything like this before, so maybe I did stupid things. I also use Gulp, but probably its code is hardly needed here.
webpackis an amateur product. Your gulp will work fine without it. - vp_arth