M
M
Maxim Korolsky2016-06-10 20:59:36
Node.js
Maxim Korolsky, 2016-06-10 20:59:36

Are there several node modules included in each file by default?

I want several modules to be included in each file by default, for example, Link, etc. And it would be even better that you could configure specific modules for a specific directory, in order not to include them in each file.
How to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim, 2016-06-10
@maxfarseer

I don’t know about directories, but you can not import them in files, for this you need to use webpack-provide-plugin

...
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.ProvidePlugin({
      'React':     'react'
    })
  ],
...

Here is a little more (I will translate the last example - how to import several at once ...)
new webpack.ProvidePlugin({
    '$':          'jquery',
    '_':          'lodash',
    'ReactDOM':   'react-dom',
    'cssModule':  'react-css-modules',
    'Promise':    'bluebird'
  })

Will let you not write in files:
import ReactDOM from ‘react-dom’
import _ from 'lodash'
import $ from 'jquery'
import cssModule from 'react-css-modules'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question