D
D
Dmitry2017-04-09 22:05:05
JavaScript
Dmitry, 2017-04-09 22:05:05

How to force webpack to initialize a library without a dash character in the name?

The webpack-glob-entries module is used , which allows you to initialize entry according to a template:

module.exports = {
    entry: globEntries('./src/entries/*.js'),
    ...
    output: {
        path: path.resolve(__dirname, './builded'),
        publicPath: '/builded/',
        filename: '[name].js',
        library: '[name]'
    },
}

As you can see, the output is generated by the file name and this is important. If the script has a name containing a " dash ", for example, user-profile.js , then I also get library var user-profile , which, accordingly, is not acceptable.
Is there any way to convert the lbrary name to camelCase or any other supported JS format?
For now, one option is to use a different file naming format, like camelCase or snake_case , but you'll agree that user-profile.js looks better than userProfile.js or user_profile.js
Thank you.
UPD:
You can, of course, implement your own version of the webpack-glob-entries module, where the module converted to camelCase will act as an index, but this is an extreme case. Maybe there are some tools out of the box?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad Feninets, 2017-04-11
@fnnzzz

in theory, this should help you - https://github.com/skozin/webpack-path-rewriter
you just need to override test: /\.js$/through the PathRewriterPlugin.rewriteAndEmit()
examples and the plugin doc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question