Skip to content

Make public folder path configurable #3184

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
marvinrabe opened this issue Dec 25, 2018 · 10 comments
Closed

Make public folder path configurable #3184

marvinrabe opened this issue Dec 25, 2018 · 10 comments

Comments

@marvinrabe
Copy link

marvinrabe commented Dec 25, 2018

What problem does this feature solve?

Renaming or moving the public folder in order to use vue-cli alongside other frameworks (e.g. Laravel).

Yes, it is possible to achieve it with this configuration:

const path = require('path')

const publicDir = 'assets/html';

module.exports = {
    chainWebpack: config => {
        config
            .plugin('html')
            .tap(args => {
                args[0].template = path.resolve(publicDir + '/index.html');
                return args
            })

        config
            .plugin('copy')
            .tap(([pathConfigs]) => {
                pathConfigs[0].from = path.resolve(publicDir);
                return [pathConfigs]
            })
    }
}

But for such a simple configuration this feels ridiculous.

What does the proposed API look like?

Specify the public directory path in the vue.config.js

module.exports = {
    publicDir: 'assets/html' // Defaults to 'public'
}
@yyx990803
Copy link
Member

yyx990803 commented Jan 27, 2019

The public directory is NOT the actual assets that are getting served. All final deliverable assets are in dist when you build your app. (static assets in public are copied into dist)

The workflow for using Vue CLI with a backend framework is let the Vue CLI app live in its own isolated directory and (after build) target/copy your dist folder to proper location in your backend framework.

@marvinrabe
Copy link
Author

I know that the public folder is copied into dist. But then why is the directory public called public, when it should not be public? dist should be public (but is not called public).

For the current issue I really don't care if the default name is public or not. But at least add the option to change the path - if one needs to.

Your proposition (https://github.com/yyx990803/laravel-vue-cli-3) with integrating Vue CLI with a backend framework is not optimal. It works. But on a daily basis it is quite inconvenient. I work on the client and backend at the same time. This means I have to change between folders often (root project folder and client folder) respectively switch between multiple terminal sessions for running CLI commands (like artisan, yarn ...). Occasionally I run a command in the wrong folder. Therefore, I prefer having the client and backend in the same root directory.

@yyx990803
Copy link
Member

@marvinrabe in that case you should just use the default config from Laravel (via Mix) instead of the CLI.

@marvinrabe
Copy link
Author

No. In my opinion Laravel Mix is not really suited for SPA. Vue CLI is. But Vue CLI has one little quirk: no configurable public directory. It assumes a strict separation between client and backend which is not sensible in smaller projects. The client and backend are developed and deployed together.

I spend some time digging through older issues to fully understand your reasons. For future reference the reasons for not providing a configuration for the public directory are:

  1. The CLI is designed for SPAs or projects that separates front-end from the backend.
  2. There's little practical benefits in changing the src or public directory names.
  3. Consistent source code structure across all Vue CLI projects.
  4. Maintenance cost

I strongly disagree on the first 3 points. But as explained by @LinusBorg in #3061 the maintenance cost is a good reason for rejecting this feature.

Thank you for taking time responding to this issue.

Sources:

@yyx990803
Copy link
Member

Yes, your summary is basically my reason for rejecting this. Note that (1) is the whole premise for providing the CLI, so disagreeing with that means you have a different vision for what this project should be - in that case you should probably fork it.

@thinsoldier
Copy link

thinsoldier commented Nov 29, 2019

@marvinrabe Thank you for the config example. I have been struggling with this same problem for days.

At the very least I wish I could tell vue to not copy any or at least certain files from the public folder over to the /dist. My several gigabytes of files in the /public/gallery folder takes a while to copy and it's a waste of space to make a copy of it.

Something I very much do not understand is why the results of npm run serve does not create a dist folder but the photos are loading properly (from /public/gallery) but the results of npm run build does not put a gallery folder in /dist because I used your configuration and therefore the photos do not load, which is expected. What magic is npm run server doing to make it different from build. If build doesn't load the photos then server should not either. Strange.

@livthomas
Copy link

I also ran into this issue in the CLI. How come these two very popular frameworks (Vue.js and Laravel) have conflicting folder structures when they are so often used together? Cannot the teams cooperate together if it is a typical technology stack?

@yyx990803 I see your point here. But sometimes you need to have a thin Laravel wrapper around your Vue.js SPA and you don't want to move all Vue.js code to a subfolder if that's the place where you spend the most time during development. So having it at least configurable would be a great improvement. Although the ultimate solution would be not to have any conflicts between Vue.js and Laravel default folder structure.

@kakenbok
Copy link

I have a number of vue projects running, and to avoid boilerplate I put all common configuration in a node package called 'vue2-bootsrap', which is installed via npm and from which the vue-cli gets started:

vue-cli-service serve $INIT_CWD/src/main.js

While this works perfectly fine, the cli serve/build tasks are looking into the local vue2-bootstrap/public folder and do not respect the projects public folder index.html template or local static assets like a favicon.ico or a logo.png.

It would be greate to have a publicFolder option.

@marvinrabe
Copy link
Author

Anyone using Laravel have a look at nuxt.js and this boilerplate:

https://github.com/acidjazz/laranuxt

You can create a SPA in combination with a Laravel backend without the public folder issues of vue-cli.

Simply stop using vue-cli. In my opinion nuxt.js has the overall better design nonetheless.

@ifer-itcast
Copy link

const path = require('path')
const publicDir = 'assets' // Defaults to 'public'

module.exports = {
  chainWebpack(config) {
    config.plugin('html').tap((args) => {
      args[0].template = path.resolve(publicDir, 'index.html')
      return args
    })
    /* config
      .plugin('copy')
      .use(require('copy-webpack-plugin'), [
        [{ from: path.resolve(publicDir) }],
      ]) */
    config
      .plugin('copy')
      .use(require('copy-webpack-plugin'))
      .tap((args) => {
        return [
          [...(args[0] ? args[0] : []), { from: path.resolve(publicDir) }],
        ]
      })
  },
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants