For example, I installed tailwind CSS via npm by npm init && npm install tailwindcss. After that, I make a script in package.json like "build-css": "tailwindcss build src/styles.css -o public/styles.css"(I just copy-paste it from stuckoverflow). Now focus on -o, how a developer knows there is a -o option available for tailwind. I checked node-module/tailwindcss/script/build.js but there is no such thing that I currently understand( I mean, I found 0 clue). Pls give light on it. Do we have some standardization or unwritten rule that creator of npm package follow?
The scripts field in your package.json defines commands that are run with npm run in the context of npm. This allows you to use the command-line interface that are provided by different npm packages, without installing them globally. Many of these CLIs also expose a --help flag, or a help command.
To run the CLI from a npm package not installed globally, you may need to use npx. In your case, you can run:
npx tailwindcss
which tells you that there is a help command that gives you more information.
$ npx tailwindcss
tailwindcss 2.1.2
Usage:
tailwind <command> [options]
Commands:
help [command] More information about the command.
init [file] Creates Tailwind config file. Default: tailwind.config.js
build <file> [options] Compiles Tailwind CSS file.
If you are comfortable reading the source code in your node_modules folder, you can also find more information about these commands and the code that runs. To find where the CLI is defined, you can check node_modules/tailwindcss/package.json, which defines a bin key. In this case, it shows that the tailwindcss command comes from lib/cli.js. While the code is transformed, you can poke around and find lib/cli/commands/build.js, which contains the options for the build command.
const options = [{
usage: '-o, --output <file>',
description: 'Output file.'
}, {
usage: '-c, --config <file>',
description: 'Tailwind config file.'
}, {
usage: '--no-autoprefixer',
description: "Don't add vendor prefixes using autoprefixer."
}];
If the package is open source, you may be able to find the original, untransformed source online. In Tailwind's case, they have a Github repo where you can view the raw source for the build command.
When I run the following command:
npx prisma migrate dev --preview-feature
I get the following error:
$ npx prisma migrate dev --preview-feature
npx: installed 600 in 26.334s
▸ migrate dev is not a prisma command.
▸ Perhaps you meant generate
▸ Run prisma help for a list of available commands.
Get in touch if you need help: https://slack.prisma.io
To get more detailed output, run $ set -x DEBUG "*"
(node:6096) [DEP0066] DeprecationWarning: OutgoingMessage.prototype._headers is deprecated
(Use `node --trace-deprecation ...` to show where the warning was created)
However, the prisma migrate dev command should be available in the Prisma CLI. Why doesn't this work?
Okay I figured it out, I accidentally invoked the Prisma 1 CLI which is available as the prisma package on npm.
The way to fix this is to make sure that the Prisma 2 CLI which is available as the #prisma/cli package on npm is installed locally (see docs):
npm install #prisma/cli --save-dev
# or
yarn add #prisma/cli --dev
That way npx will execute the right binary from the local node_modules folder.
From the npx docs:
Executes <command> either from a local node_modules/.bin, or from a central cache, installing any packages needed in order for <command> to run.
By default, npx will check whether <command> exists in $PATH, or in the local project binaries, and execute that. If <command> is not found, it will be installed prior to execution.
Unless a --package option is specified, npx will try to guess the name of the binary to invoke depending on the specifier provided. All package specifiers understood by npm may be used with npx, including git specifiers, remote tarballs, local directories, or scoped packages.
If for some reason the local binary is not picked up, you can try to add the prisma script to your package.json:
{
"scripts": {
"prisma": "prisma"
}
}
I have a vue.js app, and it is using two files named dev.env.js and prod.env.js to read environment variables and configure the app.
the dev.env.js is currently configured with data that our frontend developers are using.
I need to make some adjustments on my own and need another env file.
I have created a file named ninja.env.js next to the other files in config/ which contains:
'use strict'
module.exports = {
NODE_ENV: '"development"',
SERVER_PATH: '"localhost:8560"',
SOCKET_PATH: '"localhost:8561/map"'
}
but there is no way to run this.
I have tried:
$ npm run ninja
>>> npm ERR! missing script: ninja
$ npm run dev --mode ninja
>>> Failed to compile with 1 errors 11:12:02 AM
This dependency was not found:
* ninja in multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ninja
To install it, you can run: npm install --save ninja
so, is there a way to add multiple environment files?
Yes, as mentioned in docs, basically you can add different modes like this:
.env.[MODE_NAME]
And they you can run it like:
vue-cli-service build --mode [MODE_NAME]
What should I do after developing a Vue app with vue-cli?
In Angular there was some command that bundle all the scripts into one single script.
Is there something the same in Vue?
I think you've created your project like this:
vue init webpack myproject
Well, now you can run
npm run build
Copy index.html and /dist/ folder into your website root directory. Done.
If you've created your project using:
vue init webpack myproject
You'd need to set your NODE_ENV to production and run, because the project has web pack configured for both development and production:
NODE_ENV=production npm run build
Copy dist/ directory into your website root directory.
If you're deploying with Docker, you'd need an express server, serving the dist/ directory.
Dockerfile
FROM node:carbon
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
ADD . /usr/src/app
RUN npm install
ENV NODE_ENV=production
RUN npm run build
# Remove unused directories
RUN rm -rf ./src
RUN rm -rf ./build
# Port to expose
EXPOSE 8080
CMD [ "npm", "start" ]
in your terminal
npm run build
and you host the dist folder. for more see this video
To deploy your application to prod environment add
"build": "vue-cli-service build --mode prod"
in your scripts in package.json file.
Open your main.js and add
Vue.config.productionTip = false;
right after your imports.
Then open your cli in the project folder and run this command
npm run build
This will make a dist folder in your project directory you may upload that dist folder in your host and your website will be live
If you run into problems with your path, maybe you need to change the assetPublicPath in your config/index.js file to your sub-directory:
http://vuejs-templates.github.io/webpack/backend.html
The vue documentation provides a lot of information on this on how you can deploy to different host providers.
npm run build
You can find this from the package json file. scripts section. It provides scripts for testing and development and building for production.
You can use services such as netlify which will bundle your project by linking up your github repo of the project from their site. It also provides information on how to deploy on other sites such as heroku.
You can find more details on this here
The commands for what specific codes to run are listed inside your package.json file under scripts. Here is an example of mine:
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint"
},
If you are looking to run your site locally, you can test it with
npm serve
If you are looking to prep your site for production, you would use
npm build
This command will generate a dist folder that has a compressed version of your site.
THIS IS FOR DEPLOYING TO A CUSTOM FOLDER (if you wanted your app not in root, e.g.
URL/myApp/) - I looked for a longtime to find this answer...hope it helps someone.
Get the VUE CLI at https://cli.vuejs.org/guide/ and use the UI build to make it easy. Then in configuration you can change the public path to /whatever/ and link to it URL/whatever.
Check out this video which explains how to create a vue app using CLI if u need more help: https://www.youtube.com/watch?v=Wy9q22isx3U
For NPM => npm run Build
For Yarn => yarn run build
You also can check scripts in package.json file
You write down the below command being at the project root.
npm run build
First Install Vue Cli Globally
npm install -g #vue/cli
To create a new project, run:
vue create project-name
run vue
npm run serve
Vue CLI >= 3 uses the same vue binary, so it overwrites Vue CLI 2 (vue-cli). If you still need the legacy vue init functionality, you can install a global bridge:
Vue Init Globally
npm install -g #vue/cli-init
vue init now works exactly the same as vue-cli#2.x
Vue Create App
vue init webpack my-project
Run developer server
npm run dev
This command is for start the development server :
npm run dev
Where this command is for the production build :
npm run build
Make sure to look and go inside the generated folder called 'dist'.
Then start push all those files to your server.
One way to do this without using VUE-CLI is to bundle the all script files into one fat js file and then reference that big fat javascript file into main template file.
I prefer to use webpack as a bundler and create a webpack.conig.js in the root directory of project. All the configs such as entry point, output file, loaders, etc.. are all stored in that config file. After that, I add a script in package.json file that uses webpack.config.js file for webpack configs and start watching files and create a Js bundled file into mentioned location in webpack.config.js file.
I think you can use vue-cli
If you are using Vue CLI along with a backend framework that handles static assets as part of its deployment, all you need to do is making sure Vue CLI generates the built files in the correct location, and then follow the deployment instruction of your backend framework.
If you are developing your frontend app separately from your backend - i.e. your backend exposes an API for your frontend to talk to, then your frontend is essentially a purely static app. You can deploy the built content in the dist directory to any static file server, but make sure to set the correct baseUrl
npm run build - this will uglify and minify the codes
save index.html and dist folder in root directory of your website.
free hosting service that you might be interested in -- Firebase hosting.
if you used vue-cli and webpack when you created your project.
you can use just
npm run build command in command line, and it will create dist folder in your project. Just upload content of this folder to your ftp and done.
If you are using npm u can use npm run build but if you are using yarn you can simply run yarn build
If you want to create a build for a domain, you can use the $ npm run build command.
If you're going to build for a sub-domain, follow these instructions:
Create a file that's name is vue.config.js in the root
Write down the below code in the vue.config.js file:
module.export = {
publicPath: '/demo-project',
}
Now run $ npm run build
Note: Use your subdomain name instead of "/demo-project".
If you want to build and send to your remote server you can use cli-service (https://cli.vuejs.org/guide/cli-service.html) you can create tasks to serve, build and one to deploy with some specific plugins as vue-cli-plugin-s3-deploy
Hi I'm trying to install Grunt on Windows 7 64 bit. I have installed Grunt using commands
npm install -g grunt
npm install -g grunt-cli
but now if I try to do grunt init, it is throwing me an error -
A valid Gruntfile could not be found. Please see the getting started
guide for more information on how to configure grunt:
http://gruntjs.com/getting-started Fatal error: Unable to find
Gruntfile.
But when I look inside the grunt folder on my system the Gruntfile.js is there. can someone please guide me how to install this grunt properly and how to write built Script using the grunt. I have one HTML page and java script if i wants built a script using Grunt how can i do it?
To setup GruntJS build here is the steps:
Make sure you have setup your package.json or setup new one:
npm init
Install Grunt CLI as global:
npm install -g grunt-cli
Install Grunt in your local project:
npm install grunt --save-dev
Install any Grunt Module you may need in your build process. Just for sake of this sample I will add Concat module for combining files together:
npm install grunt-contrib-concat --save-dev
Now you need to setup your Gruntfile.js which will describe your build process. For this sample I just combine two JS files file1.js and file2.js in the js folder and generate app.js:
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
concat: {
"options": { "separator": ";" },
"build": {
"src": ["js/file1.js", "js/file2.js"],
"dest": "js/app.js"
}
}
});
// Load required modules
grunt.loadNpmTasks('grunt-contrib-concat');
// Task definitions
grunt.registerTask('default', ['concat']);
};
Now you'll be ready to run your build process by following command:
grunt
I hope this give you an idea how to work with GruntJS build.
NOTE:
You can use grunt-init for creating Gruntfile.js if you want wizard-based creation instead of raw coding for step 5.
To do so, please follow these steps:
npm install -g grunt-init
git clone https://github.com/gruntjs/grunt-init-gruntfile.git ~/.grunt-init/gruntfile
grunt-init gruntfile
For Windows users: If you are using cmd.exe you need to change ~/.grunt-init/gruntfile to %USERPROFILE%\.grunt-init\. PowerShell will recognize the ~ correctly.
Some time we need to set PATH variable for WINDOWS
%USERPROFILE%\AppData\Roaming\npm
After that test with where grunt
Note: Do not forget to close the command prompt window and reopen it.
I got the same issue, but i solved it with changing my Grunt.js to Gruntfile.js
Check your file name before typing grunt.cmd on windows cmd (if you're using windows).
You should be installing grunt-cli to the devDependencies of the project and then running it via a script in your package.json. This way other developers that work on the project will all be using the same version of grunt and don't also have to install globally as part of the setup.
Install grunt-cli with npm i -D grunt-cli instead of installing it globally with -g.
//package.json
...
"scripts": {
"build": "grunt"
}
Then use npm run build to fire off grunt.