当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 35

jeArts / ak-vue
暂停

forked from 337547038 / ak-vue 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vue.config.js 7.76 KB
一键复制 编辑 原始数据 按行查看 历史
337547038 提交于 2019-10-22 13:57 . 优化表单相关组件
const path = require('path')
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
const webpack = require('webpack')
// const CopyWebpackPlugin = require('copy-webpack-plugin')
const Spritesmith = require('spritesmith')
const fs = require('fs')
// 不同环境接口url
const prodEnv = {
serve: {'VUE_APP_BASE_URL': '"/"'},
docs: {'VUE_APP_BASE_URL': '"/"'},
build: {'VUE_APP_BASE_URL': '"/"'},
buildDocs: {'VUE_APP_BASE_URL': '"/"'}
}
const original = JSON.parse(process.env.npm_config_argv).original[1] || 'serve' // 运行的命令名称npm run build=>build
const NODE_ENV = process.env.NODE_ENV === 'production'
let entry = 'src/main.js'
if (original === 'docs' || original === 'buildDocs') {
entry = 'docs/main.js'
}
// 合并图片,暂不作判断,每次重新生成
let sprites = []
const pathIcons = 'src/assets/icons'
fs.access(pathIcons, (err) => {
if (err) {
return
}
fs.readdir(pathIcons, (err, paths) => {
// 遍历目录找到所有png图片
if (err) {
throw err
}
paths.forEach(item => {
if (item.indexOf('.png') !== -1) {
sprites.push(pathIcons + '/' + item)
}
})
if (sprites.length > 0) {
/* eslint-disable */
Spritesmith.run({src: sprites, padding: 5}, handleResult = (err, result) => {
if (err) {
throw err
}
// 保存图片
fs.writeFile(path.resolve(__dirname + '/src/assets/images/sprites.png'), result.image, err => {
})
// 保存样式
let style = `[class*='sprites-']{display: inline-block;background: url(../images/sprites.png) no-repeat let top / ${result.properties.width}px ${result.properties.height}px}\r`
for (let key in result.coordinates) {
const name = key.replace('src/assets/icons/', '').replace('.png', '')
let obj = result.coordinates[key]
style += `.sprites-${name}{width: ${obj.width}px;height: ${obj.height}px;background-position: ${obj.x}px ${obj.y}px}\r`
}
fs.writeFile(path.resolve(__dirname + '/src/assets/scss/sprites.scss'), style, err => {
})
})
}
})
})
let publicPath = '/'
// 打包组件示例时使用相对路径
if (original === 'buildDocs') {
publicPath = './'
}
module.exports = {
publicPath: publicPath,
assetsDir: 'static',
outputDir: 'dist-' + original,
productionSourceMap: false,
lintOnSave: !NODE_ENV,
pages: {
index: {
entry: entry,
chunks: ['vendors', 'ak', 'index']
}
},
configureWebpack: (config) => {
let plugins = []
// 添加环境变量
plugins.push(
new webpack.DefinePlugin({
'process.env': prodEnv[original]
})
)
// 复制static静态资源
/* plugins.push(
new CopyWebpackPlugin([{
from: path.resolve(__dirname, 'static'),
to: 'static',
ignore: ['.*', '.svn', '**!/.svn/!**!/!*'] // ingore svn files
}])
) */
// 不需要重新打包集成的node_modules
// externals中的key是后面需要require的名字,value是第三方库暴露出来的方法名
config.externals = {
// 'vue-router': 'Router'
// 'vue': 'Vue',
// './cityData': 'cityData' // 联动城市数据,这里可以不打包而直接在html页面引入
}
if (NODE_ENV) {
if (original !== 'buildComponents') {
// 打包组件时不要拆分
config.optimization = {
splitChunks: {
cacheGroups: {
vendors: {
// 抽取来自 node_modules 文件夹下的第三方代码,优先级权重为10
name: 'vendors',
test: /[\\/]node_modules[\\/]/,
chunks: 'all',
priority: 10 // 优先级
},
common: {
// 抽取来自 packages 文件夹下的代码,优先级权重为5
// 提取公共组件,这里name要对应pages里的chunks,否则打包的脚本不会插入到html中
name: 'ak',
// test: /[\\/]src[\\/]components[\\/]/,
test: /[\\/]packages[\\/]/,
chunks: 'all',
priority: 5
}
}
}
}
}
if (original !== 'buildDocs') {
// 打包示例时不移除console.log
plugins.push(
new UglifyJsPlugin({
uglifyOptions: {
warnings: false,
compress: {
drop_console: true, // console
drop_debugger: false,
pure_funcs: ['console.log'] // 移除console
}
},
sourceMap: false,
parallel: true
})
)
}
} else {
// 为开发环境修改配置...
}
// 在html插入script
/* plugins.push(new AddAssetHtmlPlugin({
// dll文件位置
filepath: path.resolve(__dirname, './src/assets/1.js'),
// dll 引用路径
publicPath: './vendor',
// dll最终输出的目录
outputPath: './vendor'
})) */
config.plugins = [
...config.plugins,
...plugins
]
},
chainWebpack: config => {
// 移除 preload 插件 预加载
/* config.plugins.delete('prefetch-index')
config.plugins.delete('preload-index') */
// 添加html模板参数到htmlWebpackPlugin配置中,使用详见public/index.html
// 通过htmlWebpackPlugin.options.xxx引用
if (original !== 'buildComponents') {
config
.plugin('html-index') // pages多页面时要在html后面带上当前入口-index
.tap(args => {
args[0].publicDate = new Date().toLocaleString()
args[0].hash = true
return args
})
}
if (NODE_ENV) {
// config.optimization.delete('splitChunks')
}
// 配置【vue-markdown-loader】解析md格式的文件
config.module
.rule('md')
.test(/\.md/)
.use('vue-loader')
.loader('vue-loader')
.end()
.use('vue-markdown-loader')
.loader('vue-markdown-loader/lib/markdown-compiler')
.options({
raw: true,
preventExtract: true,
use: [
[
require('markdown-it-container'),
'demo',
{
validate: function (params) {
// return params.trim().match(/^demo\s+(.*)$/)
return params.match(/^demo\s+(.*)$/)
},
render (tokens, idx) {
if (tokens[idx].nesting === 1) {
// 1.获取第一行的内容使用markdown渲染html作为组件的描述
const markdownRender = require('markdown-it')()
let demoInfo = tokens[idx].info.trim().match(/^demo\s+(.*)$/)
let description = (demoInfo && demoInfo.length > 1) ? demoInfo[1] : ''
let descriptionHTML = description ? markdownRender.render(description) : ''
// 2.获取代码块内的html和js代码
let content = tokens[idx + 1].content
// 3.使用自定义开发组件【DemoBlock】来包裹内容并且渲染成案例和代码示例
return `
<demo-block>
<div class="source" slot="source">${content}</div>
${descriptionHTML}
<div class="highlight" slot="highlight">`
} else {
return `
</div>
</demo-block>\n`
}
}
}
],
[require('markdown-it-anchor'), {
level: 2,
permalink: true,
permalinkBefore: true
}],
[require('markdown-it-table-of-contents'), {
includeLevel: [2, 3],
containerClass: 'container-nav'
}]
]
})
}
}
JavaScript
1
https://gitee.com/arts1986/ak-vue.git
git@gitee.com:arts1986/ak-vue.git
arts1986
ak-vue
ak-vue
master

搜索帮助

53164aa7 5694891 3bd8fe86 5694891