How can I change the name of the _nuxt folder? - node.js

Hello I've got an issue with a Nuxt.js app that I can't seem to resolve. What I want to do is to change the name of the generated _nuxt folder with some other name. So far I've updated the nuxt.config.js and added this snippet:
build: {
publicPath: '/new-folder'
},
as far as I understand this publicPath variable expects a CDN link so probably this is not the correct way of changing the default _nuxt folder name.
I have also tried adding the buildDir: 'new-folder but when I run the build command it doesn't show up in the project. No matter what changes I added in the nuxt.config file when I deployed it on heroku all the assets where still in the _nuxt folder which causes issues to my project. Am I not seeing something am I doing something wrong?

Since the default answer in nuxt JS Documentation is /_nuxt/. The correct answer should be /yourCustomName/ - be ware that you need two forward slash.
In nuxt.config.js
build: {
publicPath: '/customName/'
}

t's simple, just change in build the publicPath.
buildDir is to change the folder for development, where the files will be when coding
nuxt.config.js:
build: {
publicPath: 'new-folder/',
},
in my case, my publicPath is leo/
you can check more about it here:
https://medium.com/#andrejsabrickis/how-to-set-custom-configuration-for-nuxt-js-generate-task-5055e53c2da5

Related

How to deploy Ganttlab in a path different than "/"

I am installing Ganttlab locally and I want to be able to use it in https://[mygitlabserver]/ganttlab/. The configuration and build process are pretty straightforward. However, I noticed that some files like "dist/index.html" and "dist/js/app.xxxxxx.js" have been built with "/" as the default path, resulting in a lot of 302's or 404's.
Is there a way I can configure this path before the build:webapp?
Thanks in advance.
The webapp uses vue.
So create a vue config file: packages/ganttlab-adapter-webapp/vue.config.json
module.exports = {
publicPath: './'
}
The code above will make all paths relative.
Depending on you setup you can also set the path explicit publicPath: '/ganttlab/'
For more info: github.com/ganttlab/ganttlab download and install

How to set up a base url when using the Vue.js blueprint?

I would like my app to run on /myapp instead of / but I can't seem to make that work.
I would like this to work when running the application as a jar, without running the client separately, and when running it from IntelliJ as a Spring Boot App (again, without running the client separately).
I have generated the application with JHipster and it was working fine on /
Then I did the following:
in application.yml
server.servlet.context-path: /myapp
in webapp/app/router/index.ts
export default new Router({
mode: 'history',
base: '/myapp/',
routes: [
{
Now, when running the app and calling localhost:8080/myapp I get the error page telling "An error has occured :-(" and I can see that it's trying to call
http://localhost:8080/content/css/loading.css
http://localhost:8080/app/main.bundle.js
http://localhost:8080/app/global.bundle.js
http://localhost:8080/manifest.webapp
which all result in 404s.
What am I missing ?
Thank you.
EDIT
The version html-webpack-plugin version is 3.2.0.
I tried making the change in webpack/webpack.common.js:
new HtmlWebpackPlugin({
template: './src/main/webapp/index.html',
chunks: ['vendors', 'main', 'global'],
chunksSortMode: 'manual',
inject: true
}),
new BaseHrefWebpackPlugin({ baseHref: '/myapp/' }),
but it didn't work, even after trying
npm run webpack:build
It only worked after I manually modified the index.html to
<base href="/myapp/" />
The next question is: can this be made dynamic ?
For example, when running the app in a Docker container, that I can pass the path as an environment parameter.
I can do it for Spring, but can it also be done for Vue ?
Thank you.
You will need to configure the <base href="/" /> in index.html. You can do this by setting the base config option for the HtmlWebpackPlugin in webpack.common.js or webpack.prod.js (code from sample app). It is set to / by default:
new HtmlWebpackPlugin({
base: '/',
Change to:
new HtmlWebpackPlugin({
base: '/myapp/',
This was added to the blueprint in this commit.
If you want to use the context-path in dev with the BrowserSync setup, configure webpack-dev-server with:
publicPath: '/myapp/',
contentBasePublicPath: '/myapp/',
Add .map(path => '/myapp' + path) to the end of devServer.proxy[0].context (the list of paths to proxy like /api). May be a better way to do this part but could not find it.
This is not configurable out-of-the-box for Docker containers through environment variables due to the fact the base href is replaced during the client build process. One possible solution here is to add a step to the entrypoint.sh to replace the base href in /app/resources/static/index.html with the context path (for example if SERVER_SERVLET_CONTEXT_PATH is set).
Note: If you are using jhipster-vuejs with a version of html-webpack-plugin v3.x, then upgrade html-webpack-plugin to v4.3.0, remove <base href="/" /> from index.html, and remove chunkSortMode: 'dependency' like here.

Deploy VueJS App in a sub-directory or sub-path

I’m experiencing problems deploying a Vue JS app built using the Webpack CLi to work.
If uploaded in a root directory everything renders fine, but inside a subfolder, all the links break.
I want deploy VueJS App to this url :
https://event.domain.net/webinar
I have added publicPath in vue.config.js :
var path = require(‘path’)
module.exports = {
publicPath: ‘./’
}
But only the css and js folders point to the path /webinar.
For assets, fonts and others still point to the subdomain https://event.domain.net.
CSS and JS point to path /webinar
Asset, fonts still point to subdomain https://event.domain.net/
Console
use value of publicPath as /webinar that should work.
More details are here https://cli.vuejs.org/config/#publicpath
you can configure publicPath even based on environment.
Sagar Rabadiya pointed you to the right link:
create a file called vue.config.js in the project root (where your package.json is located).
prompt the following code snippet inside:
module.exports = {
publicPath: process.env.NODE_ENV === 'production'? '/your-sub-directory/' : '/'
}
and save the file.
Open a terminal and navigate to your project, then run npm run build to generate a production build from it.
As soon as the production build has been generated, copy the contents from it and paste it in the sub-directory you created in the root folder. For example, if you use Apache, the default root directory is the htdocs folder. I've also created a virtual host on the server, maybe you also need to do this.
Open the browser and type the address where your sub-directory lives. For example: http://your-server-url:your-port/your-sub-directory/ Your should see your app now.

Unexpected token import - using react and node

I'm getting an error when running my react app: Uncaught SyntaxError: Unexpected token import
I know that there are a plethora of similar issues on here, but I think mine is a little different. First of all, here is the repository, since I'm not sure where exactly the error is: repo
I'm using create-react-app, and in a seperate backend directory I'm using babel (with a .babelrc file containing the preset es2015). The app worked fine until I added another file in a new directory in the backend folder (/backend/shared/validations/signup.js).
I was using es6 before that too, and it was working perfectly fine. First I thought it was some problem with windows, but I cloned the repo on my Ubuntu laptop and I'm getting the same error there.
Some things I tried already:
Move the entire folder from /backend to the root folder
Move just the file (signup.js) just about everywhere
So no matter where the file is, the error stays the same. If I remove the entire file and all references to it the app works again.
I think this error is pretty weird, considering I'm using es6 everywhere else in the app without trouble. It would be great if anyone could help me with this error.
edit: If you want to test this on your own machine just clone the repo and run npm start in the root folder (and also npm start in the backend folder, but that isn't required for the app to run, or for the error to show up).
That's what's happening:
Your webpack is set to run babel loader only in the src folder (include directive).
To change that, one approach is:
1) extract webpack configuration with npm run eject (don't know if there is another way to override settings in react-create-app). From the docs:
Running npm run eject copies all the configuration files and the
transitive dependencies (Webpack, Babel, ESLint, etc) right into your
project so you have full control over them.
2) in config/paths.js, add an appShared key, like that:
module.exports = {
/* ... */
appSrc: resolveApp('src'),
appShared: resolveApp('backend/shared'),
/* ... */
};
3) in config/webpack.config.dev.js, add the path to the babel loader, like that:
{
test: /\.(js|jsx)$/,
include: [ paths.appSrc, paths.appShared ],
loader: 'babel',
/* ... */
},
It works now!

Vue.js Webpack Template in a Docker Container: How do I add Webpack-Dev-Server --watch-poll flag?

I am running the webpack / webpack-dev-server portion of the base Vue.js Webpack template (https://github.com/vuejs-templates/webpack/) inside of a docker container I created. The container also contains the vue CLI in order to create new projects (you can get my container here if you want: https://hub.docker.com/r/ncevl/webpack-vue/).
Hot-reload does not work after moving from the webpack-simple template to this one.
Everything was working using the Webpack-Simple template which you can clone / see over here: https://github.com/vuejs-templates/webpack-simple
I was able to get the simple template running (with hot-reload working as intended) with the following webpack-development-server launch command:
webpack-dev-server --hot --inline --progress --host 0.0.0.0 --watch-poll
That said the full (not simple) version of the webpack template does not appear to use a webpack-dev-server launch command and instead appears to use additional middleware as referenced in build/dev-server.js (https://github.com/vuejs-templates/webpack/blob/master/template/build/dev-server.js) and the webpack dev config.
Since the --watch-poll was the key to getting the WDS hot-reload functionality to work within a docker container in the last project, my thinking is that I need to do something similar with the webpack-hot-middleware but I dont see anything in their docs (over here: https://github.com/glenjamin/webpack-hot-middleware) that talks about changing to a polling based approach.
I am not 100% sure the polling flag will do the trick since I can see the container recompile my source when I make a change. I can also see the change in my browser if I refresh it manually.
Whats stranger still is if I inspect my page in browser within chrome dev tools, and then head over to network / XHR I can see that the browser actually does receive information from the webpack-dev-server, but visually it does not update.
Give the above I assume websockets (or socket.io which I think is used) are working and communicating between the browser and the WDS so maybe this is a browser caching issue of some sort?
I checked in my console and found this so it is looking like a header issue:
For reference the text error from that image (to make it easier for anyone having the same issue to find this post) is:
EventSource cannot load http://__webpack_hmr/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://0.0.0.0:8080' is therefore not allowed access.
Again the Hot-Reload / Hot Module Reload was working with this identical container setup when using the webpack-simple Vue.js template.
I am wondering if anyone has run into anything similar or has any ideas on how to add the polling option . I guess my alternative would be roll back to a more basic webpack config and rebuild that portion of things to use the traditional webpack-dev-server / webpack config but give the above I am not sure that is going to fix it.
I am adding this as a separate answer since it more specifically answers the question in the title, while my other answer more specifically explains what solved my actual problem.
The vue.js webpack template project (which can either be init'd from the Vue CLI or pulled from its repo over here: https://github.com/vuejs-templates/webpack) separates its config files into several different directories.
I am posting this answer so that anyone who runs into the need to add polling to their project will be able to understand how / where to do that.
The base project structure for a Vue.js webpack template project looks like this:
The files that you care about if you are messing with trying to get hot module reload working are related to creating your server primarily with webpack-dev-middleware. The most important files related to that are highlighted here:
Basically if you want to add the polling code to the webpack-dev-middleware server you need to be in the /build/dev-server.js file on lines 20 to 24 that look like this:
var devMiddleware = require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
quiet: true
})
To add polling you would add it just before or after quiet: true. As a side note, if you are having trouble with HMR I would change "quiet:true" to queit false to get a more verbose read out of whats going on from webpack-dev-middleware. I have included verbose and polling modifications to the above code here:
var devMiddleware = require('webpack-dev-middleware')(compiler, {
publicPath: webpackConfig.output.publicPath,
quiet: false, //Changed to for additional verbosity
watchOptions: { //Add Polling
aggregateTimeout: 300,
poll: 1000
}
})
My other answer is in regards to what ended up solving my problem, not necessarily how to actually add polling (which might be necessary for someone else but did not end up being needed to make my dockerized setup work).
It should also be noted that sometimes when HMR (webpack hot module reload) is not detecting changes it is due to the fact that webpack-hot-middleware or webpack-dev-middleware is running into an issue whereby some invisible characters are / were added to the name of the base project directory (probably by someone building the base Vue project) and therefore webpack on certain OSes is not able to see the changes.
If that happens to you and you are on OSx or running webpack inside of a docker container and you can't get HMR to detect changes, try to rename your vue-webpack project directory and it should work.
Ok. So I can't really take credit for this one since it was actually answered by Discuss user Cristian Pallarés over here: http://webpack.github.io/docs/webpack-dev-server.html#combining-with-an-existing-server
Christian says:
I was just trying the same. I just use "php artisan serve" on localhost:8000, and Webpack Dev Server on localhost:3000. You should make this:
set your webpack config "output.publicPath" as "http://localhost:3000/static/" instead of "/static/"
make your php application load this:
The key is the output.publicPath being absolute. Now, you should run "php artisan serve" and launch your webpack dev server too (in my case I use gulp).
Basically I took that and dug through the Vue.js Webpack Template files to locate the config file where webpack was looking for the public path. the public path setting ended up being in the index.js file located in the /config directory of the template.
I changed my code to look like this:
assetsSubDirectory: 'http://localhost:8080/static/', //!!Changed from /static/
assetsPublicPath: 'http://localhost:8080/', //!!Changed from /
As opposed to the previous setting which DID NOT WORK and looked like this:
assetsSubDirectory: '/static/',
assetsPublicPath: '/',
After that I was able to see my changes hot reload while running the vue.js Webpack template from within my docker container.

Resources