Vue2多入口,独立打包配置

提示:Vue2多入口,独立打包配置

文章目录

  • 前言
  • 一、修改
  • 二、打包和效果预览
  • 三、具体操作的文件
  • 四、代码包
  • 总结


前言

需求:富文本编辑器

一、修改

在这里插入图片描述

1、复制:index.html文件并改名share.html。

路径:工程文件夹/index.html
在这里插入图片描述

2、复制main.js文件并改名share.js

路径:工程文件夹/src/main.js
在这里插入图片描述

3、复制App.vue文件并改名Share.vue

路径:工程文件夹/src/App.vue
在这里插入图片描述

4、复制build.js文件并改名share.build.js

路径:工程文件夹/build/build.js
在这里插入图片描述

const webpackConfig = require('./webpack.share.prod.conf')

5、复制webpack.base.conf.js文件并改名webpack.share.base.conf.js

路径:工程文件夹/build/webpack.base.conf.js
在这里插入图片描述

 entry: {share: './src/share.js'},

6、复制webpack.prod.conf.js文件并改名webpack.share.prod.conf.js

路径:工程文件夹/build/webpack.prod.conf.js
在这里插入图片描述
在这里插入图片描述

const baseWebpackConfig = require('./webpack.share.base.conf')
new HtmlWebpackPlugin({filename: process.env.NODE_ENV === 'testing'? 'share.html': config.build.share,template: 'share.html',inject: true,minify: {removeComments: true,collapseWhitespace: true,removeAttributeQuotes: true// more options:// https://github.com/kangax/html-minifier#options-quick-reference},// necessary to consistently work with multiple chunks via CommonsChunkPluginchunksSortMode: 'dependency'}),
new webpack.optimize.CommonsChunkPlugin({name: 'share',async: 'vendor-async',children: true,minChunks: 3}),

7、修改package.json

在这里插入图片描述

"share": "node build/share.build.js"

二、打包和效果预览

npm run build

在这里插入图片描述
dist文件夹下起个服务
在这里插入图片描述
效果
在这里插入图片描述

npm run share

在这里插入图片描述
dist文件夹下起个服务
在这里插入图片描述
在这里插入图片描述

三、具体操作的文件

在这里插入图片描述
复制index.html文件并改名share.html。

路径:工程文件夹/index.html

<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>分享页</title></head><body><div id="app"></div><!-- built files will be auto injected --></body>
</html>

复制main.js文件并改名share.js

路径:工程文件夹/src/main.js

import Vue from 'vue'
import Share from './Share.vue'
import router from './router'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';Vue.use(ElementUI);Vue.config.productionTip = falsenew Vue({el: '#app',router,components: { Share },template: '<Share/>'
})

复制App.vue文件并改名Share.vue

路径:工程文件夹/src/App.vue

<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>分享页</title></head><body><div id="app"></div><!-- built files will be auto injected --></body>
</html>

复制App.vue文件并改名Share.vue

路径:工程文件夹/src/App.vue

<!DOCTYPE html>
<html><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1.0"><title>分享页</title></head><body><div id="app"></div><!-- built files will be auto injected --></body>
</html>

复制build.js文件并改名share.build.js

路径:工程文件夹/build/build.js

'use strict'
require('./check-versions')()process.env.NODE_ENV = 'production'const ora = require('ora')
const rm = require('rimraf')
const path = require('path')
const chalk = require('chalk')
const webpack = require('webpack')
const config = require('../config')
const webpackConfig = require('./webpack.share.prod.conf')const spinner = ora('building for production...')
spinner.start()rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {if (err) throw errwebpack(webpackConfig, (err, stats) => {spinner.stop()if (err) throw errprocess.stdout.write(stats.toString({colors: true,modules: false,children: false, // If you are using ts-loader, setting this to true will make TypeScript errors show up during build.chunks: false,chunkModules: false}) + '\n\n')if (stats.hasErrors()) {console.log(chalk.red('  Build failed with errors.\n'))process.exit(1)}console.log(chalk.cyan('  Build complete.\n'))console.log(chalk.yellow('  Tip: built files are meant to be served over an HTTP server.\n' +'  Opening index.html over file:// won\'t work.\n'))})
})

在这里插入图片描述
复制webpack.base.conf.js文件并改名webpack.share.base.conf.js

路径:工程文件夹/build/webpack.base.conf.js

'use strict'
const path = require('path')
const utils = require('./utils')
const config = require('../config')
const vueLoaderConfig = require('./vue-loader.conf')function resolve (dir) {return path.join(__dirname, '..', dir)
}const createLintingRule = () => ({test: /\.(js|vue)$/,loader: 'eslint-loader',enforce: 'pre',include: [resolve('src'), resolve('test')],options: {formatter: require('eslint-friendly-formatter'),emitWarning: !config.dev.showEslintErrorsInOverlay}
})module.exports = {context: path.resolve(__dirname, '../'),entry: {share: './src/share.js'},output: {path: config.build.assetsRoot,filename: '[name].js',publicPath: process.env.NODE_ENV === 'production'? config.build.assetsPublicPath: config.dev.assetsPublicPath},resolve: {extensions: ['.js', '.vue', '.json'],alias: {'vue$': 'vue/dist/vue.esm.js','@': resolve('src'),}},module: {rules: [// ...(config.dev.useEslint ? [createLintingRule()] : []),{test: /\.vue$/,loader: 'vue-loader',options: vueLoaderConfig},{test: /\.js$/,loader: 'babel-loader',include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]},{test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,loader: 'url-loader',options: {limit: 10000,name: utils.assetsPath('img/[name].[hash:7].[ext]')}},{test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,loader: 'url-loader',options: {limit: 10000,name: utils.assetsPath('media/[name].[hash:7].[ext]')}},{test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,loader: 'url-loader',options: {limit: 10000,name: utils.assetsPath('fonts/[name].[hash:7].[ext]')}}]},node: {// prevent webpack from injecting useless setImmediate polyfill because Vue// source contains it (although only uses it if it's native).setImmediate: false,// prevent webpack from injecting mocks to Node native modules// that does not make sense for the clientdgram: 'empty',fs: 'empty',net: 'empty',tls: 'empty',child_process: 'empty'}
}

在这里插入图片描述
复制webpack.prod.conf.js文件并改名webpack.share.prod.conf.js

路径:工程文件夹/build/webpack.prod.conf.js

'use strict'
const path = require('path')
const utils = require('./utils')
const webpack = require('webpack')
const config = require('../config')
const merge = require('webpack-merge')
const baseWebpackConfig = require('./webpack.share.base.conf')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')const env = process.env.NODE_ENV === 'testing'? require('../config/test.env'): require('../config/prod.env')const webpackConfig = merge(baseWebpackConfig, {module: {rules: utils.styleLoaders({sourceMap: config.build.productionSourceMap,extract: true,usePostCSS: true})},devtool: config.build.productionSourceMap ? config.build.devtool : false,output: {path: config.build.assetsRoot,filename: utils.assetsPath('js/[name].[chunkhash].js'),chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')},plugins: [// http://vuejs.github.io/vue-loader/en/workflow/production.htmlnew webpack.DefinePlugin({'process.env': env}),new UglifyJsPlugin({uglifyOptions: {compress: {warnings: false}},sourceMap: config.build.productionSourceMap,parallel: true}),// extract css into its own filenew ExtractTextPlugin({filename: utils.assetsPath('css/[name].[contenthash].css'),// Setting the following option to `false` will not extract CSS from codesplit chunks.// Their CSS will instead be inserted dynamically with style-loader when the codesplit chunk has been loaded by webpack.// It's currently set to `true` because we are seeing that sourcemaps are included in the codesplit bundle as well when it's `false`, // increasing file size: https://github.com/vuejs-templates/webpack/issues/1110allChunks: true,}),// Compress extracted CSS. We are using this plugin so that possible// duplicated CSS from different components can be deduped.new OptimizeCSSPlugin({cssProcessorOptions: config.build.productionSourceMap? { safe: true, map: { inline: false } }: { safe: true }}),// generate dist index.html with correct asset hash for caching.// you can customize output by editing /index.html// see https://github.com/ampedandwired/html-webpack-pluginnew HtmlWebpackPlugin({filename: process.env.NODE_ENV === 'testing'? 'share.html': config.build.share,template: 'share.html',inject: true,minify: {removeComments: true,collapseWhitespace: true,removeAttributeQuotes: true// more options:// https://github.com/kangax/html-minifier#options-quick-reference},// necessary to consistently work with multiple chunks via CommonsChunkPluginchunksSortMode: 'dependency'}),// keep module.id stable when vendor modules does not changenew webpack.HashedModuleIdsPlugin(),// enable scope hoistingnew webpack.optimize.ModuleConcatenationPlugin(),// split vendor js into its own filenew webpack.optimize.CommonsChunkPlugin({name: 'vendor',minChunks (module) {// any required modules inside node_modules are extracted to vendorreturn (module.resource &&/\.js$/.test(module.resource) &&module.resource.indexOf(path.join(__dirname, '../node_modules')) === 0)}}),// extract webpack runtime and module manifest to its own file in order to// prevent vendor hash from being updated whenever app bundle is updatednew webpack.optimize.CommonsChunkPlugin({name: 'manifest',minChunks: Infinity}),// This instance extracts shared chunks from code splitted chunks and bundles them// in a separate chunk, similar to the vendor chunk// see: https://webpack.js.org/plugins/commons-chunk-plugin/#extra-async-commons-chunknew webpack.optimize.CommonsChunkPlugin({name: 'share',async: 'vendor-async',children: true,minChunks: 3}),// copy custom static assetsnew CopyWebpackPlugin([{from: path.resolve(__dirname, '../static'),to: config.build.assetsSubDirectory,ignore: ['.*']}])]
})if (config.build.productionGzip) {const CompressionWebpackPlugin = require('compression-webpack-plugin')webpackConfig.plugins.push(new CompressionWebpackPlugin({asset: '[path].gz[query]',algorithm: 'gzip',test: new RegExp('\\.(' +config.build.productionGzipExtensions.join('|') +')$'),threshold: 10240,minRatio: 0.8}))
}if (config.build.bundleAnalyzerReport) {const BundleAnalyzerPlugin = require('webpack-bundle-analyzer').BundleAnalyzerPluginwebpackConfig.plugins.push(new BundleAnalyzerPlugin())
}module.exports = webpackConfig


在这里插入图片描述
修改package.json

路径:工程文件夹/build/webpack.prod.conf.js

{"name": "test-vue","version": "1.0.0","description": "A Vue.js project","author": "duyunlong1 <duyunlong1@xdf.cn>","private": true,"scripts": {"dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js","start": "npm run dev","build": "node build/build.js","share": "node build/share.build.js"},"dependencies": {"FileReader": "^0.10.2","element-ui": "^2.15.13","source-picker": "^1.0.3","test-npm-package-self": "^1.0.19","vue": "^2.5.2","vue-router": "^3.0.1"},"devDependencies": {"autoprefixer": "^7.1.2","babel-core": "^6.22.1","babel-eslint": "^8.2.1","babel-helper-vue-jsx-merge-props": "^2.0.3","babel-jest": "^21.0.2","babel-loader": "^7.1.1","babel-plugin-dynamic-import-node": "^1.2.0","babel-plugin-syntax-jsx": "^6.18.0","babel-plugin-transform-es2015-modules-commonjs": "^6.26.0","babel-plugin-transform-runtime": "^6.22.0","babel-plugin-transform-vue-jsx": "^3.5.0","babel-preset-env": "^1.3.2","babel-preset-stage-2": "^6.22.0","babel-register": "^6.22.0","chalk": "^2.0.1","chromedriver": "^2.27.2","copy-webpack-plugin": "^4.0.1","cross-spawn": "^5.0.1","css-loader": "^0.28.0","eslint": "^4.15.0","eslint-config-standard": "^10.2.1","eslint-friendly-formatter": "^3.0.0","eslint-loader": "^1.7.1","eslint-plugin-import": "^2.7.0","eslint-plugin-node": "^5.2.0","eslint-plugin-promise": "^3.4.0","eslint-plugin-standard": "^3.0.1","eslint-plugin-vue": "^4.0.0","extract-text-webpack-plugin": "^3.0.0","file-loader": "^1.1.4","friendly-errors-webpack-plugin": "^1.6.1","html-webpack-plugin": "^2.30.1","jest": "^22.0.4","jest-serializer-vue": "^0.3.0","nightwatch": "^0.9.12","node-notifier": "^5.1.2","optimize-css-assets-webpack-plugin": "^3.2.0","ora": "^1.2.0","portfinder": "^1.0.13","postcss-import": "^11.0.0","postcss-loader": "^2.0.8","postcss-url": "^7.2.1","rimraf": "^2.6.0","selenium-server": "^3.0.1","semver": "^5.3.0","shelljs": "^0.7.6","uglifyjs-webpack-plugin": "^1.1.1","url-loader": "^0.5.8","vue-jest": "^1.0.2","vue-loader": "^13.3.0","vue-style-loader": "^3.0.1","vue-template-compiler": "^2.5.2","webpack": "^3.6.0","webpack-bundle-analyzer": "^2.9.0","webpack-dev-server": "^2.9.1","webpack-merge": "^4.1.0"},"engines": {"node": ">= 6.0.0","npm": ">= 3.0.0"},"browserslist": ["> 1%","last 2 versions","not ie <= 8"]
}

在这里插入图片描述

四、代码包

上传了源码文件

总结

踩坑路漫漫长@~@

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/595067.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Android studio BottomNavigationView 应用设计

一、新建Bottom Navigation Activity项目&#xff1a; 二、修改bottom_nav_menu.xml: <itemandroid:id"id/navigation_beijing"android:icon"drawable/ic_beijing_24dp"android:title"string/title_beijing" /><itemandroid:id"i…

Excel 插件:ASAP Utilities Crack

ASAP Utilities是一款功能强大的 Excel 插件&#xff0c;填补了 Excel 的空白。在过去的 20 年里&#xff0c;我们的加载项已经发展成为世界上最受欢迎的 Microsoft Excel 加载项之一。 ASAP Utilities 中的功能数量&#xff08;300 多个&#xff09;可能看起来有点令人眼花缭乱…

PNG图片导入Abaqus建模:Abaqus Image To Part 2D插件

插件介绍 Abaqus Image To Part 2D - AbyssFish 插件可将图像导入Abaqus内并通过对网格单元集进行材料指定&#xff0c;实现基于图像的模型部件生成。 插件支持JPEG、JPG、PNG、GIF、TIFF、BMP、PCX、ICO等多种图像格式&#xff0c;兼容彩图、灰度图、二值图像等类型&#x…

一起学docker(六)| Dockerfile自定义镜像 + 微服务模块实战

DockerFile 是什么 Dockerfile是用来构建Docker镜像的文本文件&#xff0c;是由一条条构建镜像所需的指令和参数构成的脚本。 构建步骤 编写Dockerfile文件docker build命令构建镜像docker run运行镜像 Dockerfile构建过程 基础知识 每个保留字指令都必须为大写字母且后面…

5.云原生安全之ingress配置域名TLS证书

文章目录 cloudflare配置使用cloudflare托管域名获取cloudflare API Token在cloudflare中配置SSL/TLS kubesphere使用cert-manager申请cloudflare证书安装证书管理器创建Secret资源创建cluster-issuer.yaml创建cert.yaml申请证书已经查看申请状态 部署harbor并配置ingress使用证…

Alibaba Cloud Linux镜像操作系统超详细测评!兼容CentOS

Alibaba Cloud Linux是基于龙蜥社区OpenAnolis龙蜥操作系统Anolis OS的阿里云发行版&#xff0c;针对阿里云服务器ECS做了大量深度优化&#xff0c;Alibaba Cloud Linux由阿里云官方免费提供长期支持和维护LTS&#xff0c;Alibaba Cloud Linux完全兼容CentOS/RHEL生态和操作方式…

PET塑料粘接时,要求强力粘接性能,那么怎么选胶呢?

聚对苯二甲酸乙二醇酯 简称PET。 需要强力粘接塑料PET时&#xff0c;可以选择以下几种胶水&#xff1a; 1.环氧树脂胶 具有较高的强度&#xff0c;硬度和耐久性&#xff0c;能够有效地粘合PET材料。但是&#xff0c;对于某些特殊环境和温度条件&#xff0c;可能需要选择耐高…

QT_01 安装、创建项目

QT - 安装、创建项目 1. 概述 1.1 什么是QT Qt 是一个跨平台的 C图形用户界面应用程序框架。 它为应用程序开发者提供建立艺术级图形界面所需的所有功能。 它是完全面向对象的&#xff0c;很容易扩展&#xff0c;并且允许真正的组件编程。 1.2 发展史 1991 年 Qt 最早由奇…

聊聊分布式会话及实现方案

鲁大猿&#xff0c;寻找精品资料&#xff0c;帮你构建Java全栈知识体系 http://www.jiagoujishu.cn 基础概念 Session Cookie 会话方案比较简单&#xff0c;这里我在网上找了点资料&#xff0c;再回顾下基础吧。 为什么要产生Session http协议本身是无状态的&#xff0c;客户…

数据结构——二叉树四种遍历的实现

目录 一、树的概念 1、树的定义 1&#xff09;树 2&#xff09;空树 3&#xff09;子树 2、结点的定义 1&#xff09;根结点 2&#xff09;叶子结点 3&#xff09;内部结点 3、结点间关系 1&#xff09;孩子结点 2&#xff09;父结点 3&#xff09;兄弟结点 4、树…

图像分割 分水岭法 watershed

版权声明&#xff1a;本文为博主原创文章&#xff0c;转载请在显著位置标明本文出处以及作者网名&#xff0c;未经作者允许不得用于商业目的。 本文的C#版本请访问&#xff1a;图像分割 分水岭法 watershed&#xff08;C#&#xff09;-CSDN博客 Watershed算法是一种图像处理算…

Linux mcd命令教程:如何在MS-DOS文件系统中切换工作目录(附实例教程和注意事项)

Linux mcd命令介绍 mcd是mtools工具的指令&#xff0c;它用于在MS-DOS文件系统中切换工作目录。如果不加任何参数&#xff0c;它将显示当前所在的磁盘和工作目录。 Linux mcd命令适用的Linux版本 mcd命令在所有主流的Linux发行版中都可以使用&#xff0c;包括但不限于Ubuntu…

Flink 的时间属性及原理解析

Flink的API大体上可以划分为三个层次&#xff1a;处于最底层的ProcessFunction、中间一层的DataStream API和最上层的SQL/Table API&#xff0c;这三层中的每一层都非常依赖于时间属性。时间在Flink中的地位如下图所示&#xff1a; 时间属性是流处理中最重要的一个方面&#…

python flask图书管理系统带文档

python flask图书管理系统带文档。功能&#xff1a;登录&#xff0c;图书的增删改查&#xff0c;读者管理&#xff0c;借阅记录&#xff0c;有文档。 技术&#xff1a;python3,flask,mysql,html。 包含源码数据库文件文档。 源码下载地址&#xff1a; https://download.csd…

芯课堂 | MCU之TIMER精准延时

引言 华芯微特公司SWM系列单片机提供的TIMER个数和功能有些微差别&#xff0c;为了让您更加简单的使用这一功能&#xff0c;下面小编将以SWM190为例&#xff0c;给大家展示如何使用SWM系列产品的TIMER功能。 TIMER精准延时 一、TIMER简介 TIMER是一种定时器工具&#xff0c;…

实例:NodeJS 操作 Kafka

本人是C#出身的程序员&#xff0c;c#很简单就能实现&#xff0c;有需要的可以加我私聊。但是就目前流行的开发语言&#xff0c;尤其是面向web方向应用的&#xff0c;我感觉就是Nodejs最简单了。下面介绍&#xff1a; 本文将会介绍在windows环境下启动Kafka&#xff0c;并通过n…

滑动窗口最大值(力扣239题)

单调递减队列&#xff1a; 在解决题目之前&#xff0c;我们先来了解一下单调递减队列&#xff0c;它其实就是在队列的基础上多加了一些限制&#xff0c;如下图&#xff1a; 要求队列中的元素必须按从大到小的顺序排列。 如果向单调递减队列中加入数字 1&#xff0c;可以直接加入…

一起玩儿物联网人工智能小车(ESP32)——25. 利用超声波传感器测量距离

摘要&#xff1a;本文介绍如何利用超声波传感器测量障碍物的距离 测量距离是智能小车经常要用到的功能&#xff0c;今天就来介绍一个最常用的测量距离的传感器——超声波传感器。 超声波传感器的测距原理是利用超声波发射器向某个方向发射超声波&#xff0c;与此同时&#xff…

【Emgu.CV教程】第22篇 、色彩处理之ApplyColorMap()伪色彩应用

这篇文章讲的内容比较轻松&#xff0c;技术含量比较低。从我个人的角度讲&#xff0c;ApplyColorMap()函数实现了类似PhotoShop的一些酷炫效果&#xff0c;既把原始彩色图转换为21种风格各异的彩色图像&#xff0c;比如秋天风格、热力图风格等等&#xff0c;但是&#xff0c;在…

【Java期末】学生成绩管理系统

诚接计算机专业编程任务(C语言、C、Python、Java、HTML、JavaScript、Vue等)10/15R&#xff0c;如有需要请私信我&#xff0c;或者加我的企鹅号&#xff1a;1404293476 本文资源下载地址&#xff1a;https://download.csdn.net/download/weixin_47040861/88697244 —————…