Enable ES6 Redundant Import Path in Webpack 2

The structure of my folders is as follows:

- test
  - scripts
      index.js
      user.js
- default
  - scripts
      index.js
      api.js
      user.js

I need to allow the import path locally (the "test" directory), while backups in case of failure should be allowed through the "default" directory.

Code in test / scripts / index.js:

import api from 'scripts/api'; // should be taken from 'default'
import user from 'scripts/user; // should take the local 'user.js'
...

I am using Webpack 2.1.0 with the following configuration:

...
resolve: {
    modules: [
        path.resolve( './default' )
    ]
}
...

This configuration allows webpack to allow all module paths 'script/*'through "default", while relative paths './script/*'never leave the module directory, so the relative path cannot be used as a backup.

resolve.fallbackWebpack 2 seems to be not supported

normal-module-factory->before-resolve, , , .

- ? ?

+4
1

resolve: {
  modules: [
    path.resolve(__dirname, 'path/to/source-folder'),
    path.resolve(__dirname, 'path/to/fallback-folder'),
    'node_modules',
  ]
}

: https://www.npmjs.com/package/webpack-fallback-directory-resolver-plugin

0

Source: https://habr.com/ru/post/1650037/


All Articles