catamphetamine / universal-webpack

Isomorphic Webpack: both on client and server

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is there a way to make webpack's resolve work both on client and server?

ignatevdev opened this issue · comments

In my app, the main folder is src, and when I want to import a component, I would like to write
import {Test} from 'components', rather than import {Test} from '../../components'.

The webpack's resolve.moduleDirectories along with NODE_PATH env works, but only for the client build, whereas when I am trying to start the server, it throws an Unexpected token error when trying to import anything but js (styles, images, etc..).

Using relative paths is not that crucial for me, but if there is a chance to set up my project with the resolve rule, I would like to do so.
Thanks.

Try using resolve.alias instead
https://github.com/halt-hammerzeit/universal-webpack/blob/bc635a5d27e521aa6aa8de8b3db2d0b5fc0fd62d/source/server%20configuration.js#L154-L166

    resolve: {
        alias: {
            'components': path.resolve(__dirname, '../src/components')
        }
    }

That should work

That helped!
Thanks a lot.