Nuxt.js: Can I override Nuxt.js' default directory structure?

Created on 19 Jun 2017  路  4Comments  路  Source: nuxt/nuxt.js

Hi, I'm wondering if I could do something like moving the pages and components directory from

/

to

/src

From Nuxt.js' source code /lib/webpack/base.config.js file, I saw these directories are defined in the webpack alias.
So in nuxt.config.js file in my project, I override these alias like:

var projectSrc = path.join(__dirname, 'src')

module.exports = {
    extend(config, ctx) {
            // Override
            config.resolve.alias['~'] = path.join(projectSrc)
            config.resolve.alias['~assets'] = path.join(projectSrc, 'assets')
            config.resolve.alias['~components'] = path.join(projectSrc, 'components')
            config.resolve.alias['~middleware'] = path.join(projectSrc, 'middleware')
            config.resolve.alias['~pages'] = path.join(projectSrc, 'pages')
            config.resolve.alias['~plugins'] = path.join(projectSrc, 'plugins')
    }
}

But I got this error while trying to run npm run dev:

Couldn't find a `pages` directory. Please create one under the project root

This question is available on Nuxt.js community (#c788)

Most helpful comment

Have a look at https://nuxtjs.org/api/configuration-srcdir/#the-srcdir-property.

All 4 comments

Have a look at https://nuxtjs.org/api/configuration-srcdir/#the-srcdir-property.

Thanks! Could not believe I missed that out!

No problem!

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

msudgh picture msudgh  路  3Comments

jaredreich picture jaredreich  路  3Comments

vadimsg picture vadimsg  路  3Comments

VincentLoy picture VincentLoy  路  3Comments

mattdharmon picture mattdharmon  路  3Comments