Skip to content

Additional public directory paths #1550

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
miljan-aleksic opened this issue Jun 12, 2018 · 5 comments
Closed

Additional public directory paths #1550

miljan-aleksic opened this issue Jun 12, 2018 · 5 comments

Comments

@miljan-aleksic
Copy link

What problem does this feature solve?

When using vue-cli in a monorepo project there might be apps sharing the public folder content, at least partially. With the current static public folder those apps must duplicate that content.

What does the proposed API look like?

A public config option, allowing to set a array of paths that will be looked at for the content to be copied. The current public dir should be always considered and taken as priority.

@miljan-aleksic miljan-aleksic changed the title Add possibility to set additional public directory paths Additional public directory paths Jun 12, 2018
@LinusBorg
Copy link
Member

LinusBorg commented Jul 2, 2018

That shouldn't require much more than:

chainWebpack: config => {
  config.plugin('copy')
    .tap(([pathConfigs]) => {
      const to = pathConfigs[0].to
      pathConfigs[0].force = true // so the original `/public` folder keeps priority
 
      // add other locations.
      pathConfigs.unshift({
        from: 'some/path',
        to,
      })
     
     return [pathConfigs]
    })
}

@Miaoxingren
Copy link

Miaoxingren commented Jul 13, 2018

const path = require('path')

module.exports = {
  lintOnSave: false,
  chainWebpack: config => {
    config.plugin('copy')
      .tap(([pathConfigs]) => {
        var conf = [{
          from: path.resolve(__dirname, './src/public'),
          to: path.resolve(__dirname, './dist')
        }]
        if (!pathConfigs) {
          pathConfigs = conf
        } else {
          pathConfigs.concat(conf)
        }
        return [pathConfigs]
      })

    config
      .plugin('html')
      .tap(args => {
        args[0].template = path.resolve(__dirname, './src/public/index.html')
        return args
      })
  }
}

I'm getting this error when I delete '/public' folfer.

-  Building for production... ERROR  TypeError: Cannot read property '__expression' of undefined
TypeError: Cannot read property '__expression' of undefined
    at Object.toConfig (e:\lib_project\cola_new\node_modules\webpack-chain\src\Plugin.js:38:38)
    at clean.Object.assign.plugins.plugins.values.map.plugin (e:\lib_project\cola_new\node_modules\webpack-chain\src\Config.js:125:61)
    at Array.map (<anonymous>)
    at module.exports.toConfig (e:\lib_project\cola_new\node_modules\webpack-chain\src\Config.js:125:40)
    at Service.resolveWebpackConfig (e:\lib_project\cola_new\node_modules\@vue\cli-service\lib\Service.js:194:34)
    at PluginAPI.resolveWebpackConfig (e:\lib_project\cola_new\node_modules\@vue\cli-service\lib\PluginAPI.js:103:25)
    at module.exports (e:\lib_project\cola_new\node_modules\@vue\cli-service\lib\commands\build\resolveAppConfig.js:28:25)
    at build (e:\lib_project\cola_new\node_modules\@vue\cli-service\lib\commands\build\index.js:115:50)
    at api.registerCommand (e:\lib_project\cola_new\node_modules\@vue\cli-service\lib\commands\build\index.js:64:13)
    at Service.run (e:\lib_project\cola_new\node_modules\@vue\cli-service\lib\Service.js:179:12)
    at Object.<anonymous> (e:\lib_project\cola_new\node_modules\@vue\cli-service\bin\vue-cli-service.js:22:9)
    at Module._compile (internal/modules/cjs/loader.js:702:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10)
    at Module.load (internal/modules/cjs/loader.js:612:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:551:12)
    at Function.Module._load (internal/modules/cjs/loader.js:543:3)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] build: `vue-cli-service build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:

@azampagl
Copy link

@LinusBorg Your solution works if --modern is not provided. Once it is provided, you get the same error @Miaoxingren .

[pathConfigs] becomes an empty array when --modern is provided on the cli. When a config is "forced" (@Miaoxingren 's example), you get the __expression error.

@LinusBorg
Copy link
Member

@LinusBorg Your solution works if --modern is not provided. Once it is provided, you get the same error @Miaoxingren .

Yeah, the copy webpack plugin is skipped during modern mode as we only want to copy files once.

Can be fixed like this:

config.plugins.has('copy') && config.plugin('copy').tap(([pathConfigs]) => { ...

I'll close this request as we currently don't see this as something to add to the cli config.

For multiple plubc dirs, people can add paths like I showed, or simply add a new instance of the copy plugin.

@fvena
Copy link

fvena commented Jan 26, 2020

In vue.config.js

const path = require('path');

module.exports = {
  ...
  configureWebpack: {
    devServer: {
      contentBase: [
        path.join(process.cwd(), './public'), 
        path.join(process.cwd(), './docs')
      ],
    },
  },
};

hannesfrank added a commit to hannesfrank/remnote-library that referenced this issue Dec 1, 2020
This is the easiest to request images from.
It's not quite clean, especially if one wants to move this to another repo later.

This almost works to add another public folder:
vuejs/vue-cli#1550

But it passes the files though the minifier which I don't like.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants