是否可以在没有 vue-cli 的情况下构建 vue 应用程序? [英] Is it possible to build a vue application without vue-cli?
问题描述
就像标题本身所说的那样.是否可以在 webpack 的帮助下构建 vue 应用程序而无需 vue cli?如果不是,为什么?据我了解 vue-cli 也使用 webpack 来构建他们的文件.
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.
推荐答案
是的,当然.
vue-cli
在底层使用 webpack,但它使用合理的默认值抽象了所有繁琐的 webpack 配置,因此您可以专注于编写应用程序.
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.
如果你需要改变你的应用程序的构建方式,例如你想压缩图像资产,那么除非 vue-cli
为你的特定需求提供了一个配置选项,那么你将不得不改变以某种方式对 webpack 进行配置(例如添加新的加载器或更改现有加载器的配置等).vue-cli
确实公开了一些方法来做到这一点,但你不能从一开始就完全控制 webpack 构建.
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.
我通常对如何构建我的网络应用程序有非常具体的要求,所以我选择了 DIY webpack 解决方案,以便我可以完全控制构建的所有方面.
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.
如果你不想使用 vue-cli
但仍然想使用 webpack,那么至少我会推荐以下包:
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
用于编译和捆绑.vue
单文件组件babel-loader
用于转译 JavaScriptfile-loader
用于图像资产style-loader
用于在运行时将样式注入 DOMcss-loader
用于加载 CSS 文件中引用的模块,如图像和字体
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 fonts
这篇关于是否可以在没有 vue-cli 的情况下构建 vue 应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!