Reputation: 307
Like the titles says for itself. Is it possible to build a vue application with the help of webpack and without the vue cli? If not, why? For my understanding vue-cli uses also webpack to build their files.
Upvotes: 6
Views: 16727
Reputation: 4210
Use create-vue.
npm init vue@latest project-name
or in your current directory
npm init vue@latest .
Upvotes: -3
Reputation: 19609
You don't need any build tools at all if you're willing to work within the limitations of browser-supported JavaScript. The onboarding guide doesn't use vue-cli, webpack or even Node at all.
My first nontrivial Vue app did use webpack, but not vue-cli. It was hand-configured based on advice from a then-current how-to.
Vue-cli is convenient to get a build process up and running quickly, but it's optimized for people who are either very comfortable with node build tools, or don't want to mess with the defaults very much.
Upvotes: 2
Reputation: 11
Yes. You can add Vue functionality to existing project without Vue CLI. Preferably a project using Webpack as bundler...then it is pretty simple.
You need 3 packages: vue@next, @vue/compiler-sfc and vue-loader and add some rule configuration in your webpack.config.js file.
Note! At writing moment you can not choose latest official vue-loader as it is still dependent on vue-template-compiler (used in Vue 2). You need to force in installation of v16+ (I use vue-loader 16.8.3) together with latest Vue v.3 (3.2.28)...
Here you can read detail description how do do it.
Upvotes: 1
Reputation: 73
I'm using Vue 3 without the Vue CLI in an existing application that has a custom Webpack configuration, and the following steps worked for me:
Install Vue3:
npm install --save vue@next
Install vue-loader
(v16 or newer) and the new template compiler:
npm install --save-dev vue-loader@^16 @vue/compiler-sfc
Webpack Config:
const { VueLoaderPlugin } = require('vue-loader'); // load plugin
//...
module: {
rules: [
{
test: /\.vue$/,
exclude: /(node_modules)/,
use: [
{ loader: 'vue-loader' }
]
}
]
},
plugins: [
new VueLoaderPlugin()
]
Thanks to Webpack for Vue 3 for the tip on installing the compiler without the CLI; I couldn't find that in the Vue 3 documentation.
Upvotes: 4
Reputation: 212
Yes it is very possible...in fact, until recently, a lot of projects were built without that!
Upvotes: 1
Reputation: 34286
Yes, of course.
vue-cli
uses webpack under-the-hood, but it abstracts away all the tedious webpack configuration with a sensible default so you can focus on just writing your application.
If you need to alter the way your application is built, for example you want to compress image assets, then unless vue-cli
provides a config option for your specific need then you will have to alter the webpack configuration in some way (e.g. adding a new loader or altering the configuration of an existing loader, etc). vue-cli
does expose some ways to do this, but you don't have full control over the webpack build from the beginning.
I usually have very specific requirements for how I want my web apps to be built, so I opt for the DIY webpack solution so that I have full control over all aspects of the build.
If you don't want to use vue-cli
but still want to use webpack, then at minimum I would suggest the following packages:
webpack
vue
vue-loader
for compiling and bundling .vue
single file componentsbabel-loader
for transpiling JavaScriptfile-loader
for image assetsstyle-loader
for injecting styles into the DOM at runtimecss-loader
for loading modules referenced in CSS files like images and fontsUpvotes: 5
Reputation: 293
yes vue-cli include webpack to build assets. Now, vue.js does the same things. https://github.com/vuejs/vue/blob/dev/package.json here is the package.json of Vue.js and you can see webpack is required.
So by default webpack is included into Vue.js
Upvotes: -1