如何将项目html文件中依赖的css打包,@vue/cli 4.4.5怎么把项目打包成单一html文件,不要css,js等文件?...

需求是将vue项目打包成可以直接单独打开的html文件,类似直接保存的网页。

bVcHQ3a

把css、js文件嵌入到html中,可以直接通过分享html文件打开。求解

`// vue.config.js

const path = require('path');

const IS_PROD = ['production', 'prod'].includes(process.env.NODE_ENV);

const resolve = (dir) => path.join(__dirname, dir);

var HtmlWebpackInlineSourcePlugin = require('html-webpack-inline-source-plugin');

module.exports = {

publicPath: process.env.NODE_ENV === 'production' ? '/site/vue-demo/' : '/', // 公共路径

indexPath: 'index.html', // 相对于打包路径index.html的路径

outputDir: process.env.outputDir || 'dist', // 'dist', 生产环境构建文件的目录

assetsDir: 'static', // 相对于outputDir的静态资源(js、css、img、fonts)目录

lintOnSave: false, // 是否在开发环境下通过 eslint-loader 在每次保存时 lint 代码

runtimeCompiler: true, // 是否使用包含运行时编译器的 Vue 构建版本

productionSourceMap: !IS_PROD, // 生产环境的 source map

parallel: require("os").cpus().length > 1, // 是否为 Babel 或 TypeScript 使用 thread-loader。该选项在系统的 CPU 有多于一个内核时自动启用,仅作用于生产构建。

pwa: {}, // 向 PWA 插件传递选项。

chainWebpack: config => {config.resolve.symlinks(true); // 修复热更新失效

// 如果使用多页面打包,使用vue inspect --plugins查看html是否在结果数组中

config.plugin("html").tap(args => {

// 修复 Lazy loading routes Error

args[0].chunksSortMode = "none";

return args;

});

config.resolve.alias // 添加别名

.set('@', resolve('src'))

.set('@assets', resolve('src/assets'))

.set('@components', resolve('src/components'))

.set('@views', resolve('src/views'))

.set('@store', resolve('src/store'));

},

css: {extract: IS_PROD,

requireModuleExtension: false,// 去掉文件名中的 .module

loaderOptions: {

// 给 less-loader 传递 Less.js 相关选项

less: {

// `globalVars` 定义全局对象,可加入全局变量

globalVars: {

primary: '#333'

}

}

}

},

devServer: {overlay: { // 让浏览器 overlay 同时显示警告和错误

warnings: true,

errors: true

},

host: "localhost",

port: 8080, // 端口号

https: false, // https:{type:Boolean}

open: false, //配置自动启动浏览器

hotOnly: true, // 热更新

proxy: {

}

},

plugins: [new HtmlWebpackPlugin({

inlineSource: '.(js|css)$' // embed all javascript and css inline

}),

new HtmlWebpackInlineSourcePlugin()

]

}

`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值