-
-
Couldn't load subscription status.
- Fork 6.3k
Description
What problem does this feature solve?
Presently npm run build will copy all files in the folder ./public (relative to the project folder) to the destination specified in outputDir. Which is fine if you stick to the default scaffolded folder structure (created by vue create [project_name]).
However in my case my entire vue project resides in slightly quirky folder structure like this (the public folder is in a 'sub folder' called vue-project). The 'sub folder' sort of 'encapsulates' the vue project), except for the babel, tsconfig.json, vue.config.js, etc. which all still reside in the root of the 'project folder.'
├── data
├── vue-project
│ ├── assets
│ ├── components
│ ├── dist
│ ├── public
│ └── src
├── lib-src
└── lib-tests
The code which copies the 'public' folder assets
// copy static assets in public/
const publicDir = api.resolve('public')
if (!isLegacyBundle && fs.existsSync(publicDir)) {
webpackConfig
.plugin('copy')
....
api.resolve('public') resolves to either the [project folder]/public or [environment variable VUE_CLI_CONTEXT]/public.
Unfortunately you can't workaround it by executing cd vue-project && npm run build nor by VUE_CLI_CONTEXT=vue-project npm run build since other parts of the cli rely on the context being correct.
EDIT:
A workaround is possible through vue.config.js using CopyWebpackPlugin, it's less pretty through:
outputDir: 'example/dist',
pages: {
index: {
entry: ...,
template: 'example/public/index.html',
filename: 'index.html',
},
},
...
configureWebpack: config => {
config.plugins.push(new CopyWebpackPlugin([{
from: 'example/public/',
to: '.',
ignore: ['index.html', '.DS_Store']
}]));
}
What does the proposed API look like?
Add a setting called sourcePublicDir in vue.config.js which value is resolved in places where api.resolve('public') (and api.resolve('public/index.html') etc.) are called.