Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to direct vue-cli to put built project files in different directories?

Tags:

vue.js

vue-cli

Maybe 8-9 months ago I created a Webpacked Vue.js project with vue-cli and was able to modify /build/webpack.dev.conf.js to have it put the "compiled" index.html and JavaScript / CSS files in the right folders in my Flask app when I run npm run build.

I am now showing someone else how to create a Vue.js / Flask app and I see that the way vue-cli works seems to have changed, so that I no longer have access to the /build/ folder.

I read the docs and they seemed to say that it now abstracts away the Webpack config ("Since @vue/cli-service abstracts away the webpack config..."), but that if I want to see Webpack's config options, I can do vue inspect > output.js. I did that and don't see the entries in there that I changed when I did this eight months ago:

/build/webpack.prod.conf.js:

new HtmlWebpackPlugin({   filename: process.env.NODE_ENV === 'testing' -    ? 'index.html' +    ? 'app.html'     : config.build.index, -  template: 'index.html', +  template: 'app.html', 

/build/webpack.dev.conf.js:

new HtmlWebpackPlugin({ -   filename: 'index.html', -   template: 'index.html', +   filename: 'app.html', +   template: 'app.html', 

/config/index.js:

module.exports = {   build: {     env: require('./prod.env'), -    index: path.resolve(__dirname, '../dist/index.html'), -    assetsRoot: path.resolve(__dirname, '../dist'), -    assetsSubDirectory: 'static', -    assetsPublicPath: '/', +    index: path.resolve(__dirname, '../../server/templates/app.html'), +    assetsRoot: path.resolve(__dirname, '../../server/static/app'), +    assetsSubDirectory: '', +    assetsPublicPath: '/static/app', 

It looks like the vue build command-line command can accept an argument that allows you to specify the output directory, but I need to specify two different directories: one for the HTML file (which should live in Flask's /templates/ folder), and another for the JavaScript / CSS code (which should go in Flask's /static/ folder).

like image 315
Nathan Wailes Avatar asked Feb 18 '18 12:02

Nathan Wailes


People also ask

How do I add a path to vue?

To use vue as command in cmd. Open the cmd as admin and run the the following command. setx /M path "%path%;%appdata%\npm" Now restart the cmd and run the vue again. It should work just fine.

How do I import a vue project?

1 Answer. Show activity on this post. Navigate via the 'more...' menu (bottom left) to Vue Project Manager (or here http://localhost:8000/project/select). You have the option to import a project.

What is vue proxy?

The Vue 3 guide on reactivity explains proxies like this: a Proxy is an object that encases another object or function and allows you to intercept it.


1 Answers

I just had to do this for a new project using the latest Vue-CLI and it was pretty simple: I just needed to have a file called vue.config.js at the top-level of my Vue project and within it I needed the following code:

const path = require("path");  module.exports = {   outputDir: path.resolve(__dirname, "../backend/templates/SPA"),   assetsDir: "../../static/SPA" } 

Warning: Vue-CLI will delete the contents of whatever folders you specify to use for its output. To get around this, I created the "SPA" folders within my templates/ and static/ directories.

Note also that the assetsDir is specified relative to the outputDir.

like image 71
Nathan Wailes Avatar answered Sep 22 '22 21:09

Nathan Wailes