This time I will bring you what new special effects vue-cli3.0 has added, and what are the precautions for the new special effects of vue-cli3.0. The following is a practical case, let’s take a look.
Vue-cli 3.0 has been used in recent development projects. The user experience can be said to be very good. The templates are more customized and the configuration is simpler. The following summarizes some experiences during the application process.
New project
# 安装 npm install -g @vue/cli # 新建项目 vue create my-project # 项目启动 npm run serve # 打包 npm run build
The packaged file has preloading (preload/prefetch) injected into the reference resources, and the manifest/icon link is injected when the PWA plug-in is enabled, and Inlines webpack runtime/chunk manifest for best performance.
Function configuration
Function selection
- TypeScript ##Progressive Web App (PWA) Support
- Router
- ##Vuex
##CSS Pre-processors
Linter / Formatter
Unit Testing
E2E Testing
can be experienced according to the project size and functionality To configure different functions, use the space bar to select/invert selection, press the a key to select all/unselect all, press the i key to invert the selected items, and use the up and down keys to move the selection up and down.
After selecting the function, you will be asked for more detailed configuration,
TypeScript:
Whether to use class-style component syntax: Use class-style component syntax?
Whether to use babel for escaping: Use Babel alongside TypeScript for auto-detected polyfills?
CSS Pre-processors:
Select CSS pre-processing type: Pick a CSS pre-processor
Linter / Formatter
Select Linter / Formatter specification type: Pick a linter / formatter config
Select lint mode, check when saving/check when submitting: Pick additional lint features
Testing
Select Unit testing mode
Select E2E testing method
Select the storage location of custom configurations such as Babel, PostCSS, ESLint, etc. Where do you prefer placing config for Babel, PostCSS, ESLint, etc. ?
vue.config.js Complete default configurationmodule.exports = {
// 基本路径
baseUrl: '/',
// 输出文件目录
outputDir: 'dist',
// eslint-loader 是否在保存的时候检查
lintOnSave: true,
// use the full build with in-browser compiler?
// https://vuejs.org/v2/guide/installation.html#Runtime-Compiler-vs-Runtime-only
compiler: false,
// webpack配置
// see https://github.com/vuejs/vue-cli/blob/dev/docs/webpack.md
chainWebpack: () => {},
configureWebpack: () => {},
// vue-loader 配置项
// https://vue-loader.vuejs.org/en/options.html
vueLoader: {},
// 生产环境是否生成 sourceMap 文件
productionSourceMap: true,
// css相关配置
css: {
// 是否使用css分离插件 ExtractTextPlugin
extract: true,
// 开启 CSS source maps?
sourceMap: false,
// css预设器配置项
loaderOptions: {},
// 启用 CSS modules for all css / pre-processor files.
modules: false
},
// use thread-loader for babel & TS in production build
// enabled by default if the machine has more than 1 cores
parallel: require('os').cpus().length > 1,
// 是否启用dll
// See https://github.com/vuejs/vue-cli/blob/dev/docs/cli-service.md#dll-mode
dll: false,
// PWA 插件相关配置
// see https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-pwa
pwa: {},
// webpack-dev-server 相关配置
devServer: {
open: process.platform === 'darwin',
host: '0.0.0.0',
port: 8080,
https: false,
hotOnly: false,
proxy: null, // 设置代理
before: app => {}
},
// 第三方插件配置
pluginOptions: {
// ...
}
}
Set proxy
# string module.exports = { devServer: { proxy: '<url>' } } # Object module.exports = { devServer: { proxy: { '/api': { target: '<url>', ws: true, changeOrigin: true }, '/foo': { target: '<other_url>' } } } }</other_url></url></url>Enable dll
After enabling dll, the [chunkhash] value of the vendor generated by our dynamic library file will be the same every time it is packaged. The value can be true/false, or it can be specified. Specific code base. module.exports = {
dll: true
}
module.exports = {
dll: [
'dep-a',
'dep-b/some/nested/file.js'
]
}
Relative path
The static resource path starting with @ represents
The static resource path starts with ~, which can import resources in node modules
-
Static resource references in the public folder
# 在 public/index.html中引用静态资源 <link>favicon.ico" rel="external nofollow" > # vue templates中,需要在data中定义baseUrl <template> <img src="/static/imghwm/default1.png" data-src="`${baseUrl}my-image.png`" class="lazy" alt="What new special effects have been added to vue-cli3.0?" > </template> <script> data () { return { baseUrl: process.env.BASE_URL } } </script>
Use webpack-chain to modify webpack-related configurations. It is strongly recommended to be familiar with webpack-chain and vue-cli source code in order to better understand the configuration items of this option. Module processing configuration
// vue.config.js module.exports = { chainWebpack: config => { config.module .rule('js') .include .add(/some-module-to-transpile/) // 要处理的模块 } }
Modify webpack Loader configuration
// vue.config.js module.exports = { chainWebpack: config => { config.module .rule('scss') .use('sass-loader') .tap(options => merge(options, { includePaths: [path.resolve(__dirname, 'node_modules')], }) ) } }
Modify webpack Plugin configuration
// vue.config.js module.exports = { chainWebpack: config => { config .plugin('html') .tap(args => { return [/* new args to pass to html-webpack-plugin's constructor */] }) } }
eg: 在本次项目较小,只对uglifyjs进行了少量的修改,后期如果还有配置上优化会继续添加。
chainWebpack: config => { if (process.env.NODE_ENV === 'production') { config .plugin('uglify') .tap(([options]) =>{ // 去除 console.log return [Object.assign(options, { uglifyOptions: { compress: { drop_console : true, pure_funcs: ['console.log'] }} })] }) } }
全局变量的设置
在项目根目录创建以下项目:
.env # 在所有环节中执行 .env.local # 在所有环境中执行,git会ignored .env.[mode] # 只在特定环境执行( [mode] 可以是 "development", "production" or "test" ) .env.[mode].local # 在特定环境执行, git会ignored .env.development # 只在生产环境执行 .env.production # 只在开发环境执行
在文件里配置键值对:
# 键名须以VUE_APP开头 VUE_APP_SECRET=secret
在项目中访问:
console.log(process.env.VUE_APP_SECRET)
这样项目中的 process.env.VUE_APP_SECRET 就会被 secret 所替代。
vue-cli 3 就项目性能而言已经相当友好了,私有制定性也特别强,各种配置也特别贴心,可以根据项目大小和特性制定私有预设,对前期项目搭建而言效率极大提升了。
相信看了本文案例你已经掌握了方法,更多精彩请关注php中文网其它相关文章!
推荐阅读:
The above is the detailed content of What new special effects have been added to vue-cli3.0?. For more information, please follow other related articles on the PHP Chinese website!

大家都知道win7系统有很多种版本,比如win7旗舰版、win7专业版、win7家庭版等,有不少用户在家庭版和旗舰版之间纠结,不知道选择哪个版本比较好,所以今天小编来跟大家说说win7家庭餐与win7旗舰版的区别介绍,大家一起来看看吧。1、体验不同家庭普通版使您的日常操作变得更快、更简单,可以更快、更方便地访问使用最频繁的程序和文档。家庭高级版让您享有最佳的娱乐体验,可以轻松地欣赏和共享您喜爱的电视节目、照片、视频和音乐。旗舰版集各版本功能之大全,具备Windows7家庭高级版的所有娱乐功能和专

了解SpringMVC的关键特性:掌握这些重要的概念,需要具体代码示例SpringMVC是一种基于Java的Web应用开发框架,它通过模型-视图-控制器(MVC)的架构模式来帮助开发人员构建灵活可扩展的Web应用程序。了解和掌握SpringMVC的关键特性将使我们能够更加有效地开发和管理我们的Web应用程序。本文将介绍一些SpringMVC的重要概念

5g的三个特性是:1、高速率;在实际应用中,5G网络的速率是4G网络10倍以上。2、低时延;5G网络的时延大约几十毫秒,比人的反应速度还要快。3、广连接;5G网络出现,配合其他技术,将会打造一个全新的万物互联景象。

随着互联网的快速发展,编程语言也在不断演化和更新。其中,Go语言作为一种开源的编程语言,在近年来备受关注。Go语言的设计目标是简单、高效、安全且易于开发和部署。它具有高并发、快速编译和内存安全等特性,让它在Web开发、云计算和大数据等领域中有着广泛的运用。然而,目前Go语言也有不同的版本可供选择。在选择合适的Go语言版本时,我们需要考虑需求和特性两个方面。首

java的特性是:1、简单易学;2、面向对象,使得代码更加可重用和可维护;3、平台无关性,能在不同的操作系统上运行;4、内存管理,通过自动垃圾回收机制来管理内存;5、强类型检查,变量在使用之前必须先声明类型;6、安全性,可以防止未经授权的访问和恶意代码的执行;7、多线程支持,能提高程序的性能和响应能力;8、异常处理,可以避免程序崩溃;9、大量的开发库和框架;10、开源生态系统。

PHP8的五大亮点功能,让你的代码更高效!PHP(HypertextPreprocessor)是一种广泛使用的开源脚本语言,用于Web开发。它简单易学,可以与HTML嵌套使用,同时也支持面向对象编程。PHP8作为最新版本,具有许多令人兴奋的新特性和改进,以下是五个主要亮点功能,可以使你的代码更高效。一、JIT编译器(Just-In-TimeCompile

java三大特性是:1、面向对象,java最核心的特性之一,将现实世界中的事物抽象成类,并且用对象来描述和处理问题;2、平台无关性,java源代码经过编译后生成的是字节码,而不是机器码;3、高性能,通过即时编译和垃圾回收技术的应用,在运行时可以自动优化和处理性能问题。

PHP8带来的重大特性揭秘,让你的代码更强大2020年11月26日,PHP8正式发布,为全球的PHP开发者带来了一系列令人振奋的新特性。本文将带你揭秘PHP8带来的重大改进,让你的代码更加强大和高效。同时,为了更好地理解这些特性,我们将提供具体的代码示例。强类型定义PHP8引入了更加严格的类型定义机制。现在,开发者可以在函数的参数和返回值上指定具体的类型,包


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools

Notepad++7.3.1
Easy-to-use and free code editor

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.
