Frank
Frank

Reputation: 2173

Require files by name everywhere

this is my project structure:

.
├── node_modules
├── package.json
├── www
│   ├── css
│   ├── js
│       ├── file.js
│       ├── folder
│           ├── file2.js
│           ├── file3.js        
│   ├── lib
│   ├── folder
│       ├── file4.js
│   ├── index.html
│   ├── main.js
├── webpack.config.js

I'd like to be able to do something like require('file'), require('file2'), require('file3'), require('file4') from any file in any folder of my project.

What configuration do I need to set in my webpack.config.js? Do I maybe need to use alias?

Thanks

Upvotes: 1

Views: 25

Answers (1)

Gilad Artzi
Gilad Artzi

Reputation: 3084

alias sounds about right, just add to your webpack.config.js:

resolve: {
    alias: {
        file: '/path/to/file.js'
    }
}

Upvotes: 2

Related Questions