加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
vue.config.js 2.64 KB
一键复制 编辑 原始数据 按行查看 历史
const fs = require('fs')
const path = require('path')
const spritesmithPlugin = require('webpack-spritesmith')
const spritesmithTasks = []
fs.readdirSync('src/assets/sprites').map(dirname => {
if (fs.statSync(`src/assets/sprites/${dirname}`).isDirectory()) {
spritesmithTasks.push(
new spritesmithPlugin({
src: {
cwd: path.resolve(__dirname, `src/assets/sprites/${dirname}`),
glob: '*.png'
},
target: {
image: path.resolve(__dirname, `src/assets/sprites/${dirname}.[hash].png`),
css: [
[path.resolve(__dirname, `src/assets/sprites/_${dirname}.scss`), {
format: 'handlebars_based_template',
spritesheetName: dirname
}]
]
},
customTemplates: {
'handlebars_based_template': path.resolve(__dirname, 'scss.template.handlebars')
},
// 样式文件中调用雪碧图地址写法
apiOptions: {
cssImageRef: `~${dirname}.[hash].png`
},
spritesmithOptions: {
algorithm: 'binary-tree',
padding: 10
}
})
)
}
})
module.exports = {
publicPath: '',
configureWebpack: {
resolve: {
modules: ['node_modules', 'assets/sprites']
},
plugins: [
...spritesmithTasks
]
},
pluginOptions: {
lintStyleOnBuild: true,
stylelint: {
fix: true
}
},
chainWebpack: config => {
const oneOfsMap = config.module.rule('scss').oneOfs.store
oneOfsMap.forEach(item => {
item.use('sass-resources-loader')
.loader('sass-resources-loader')
.options({
resources: [
'./src/assets/styles/resources/*.scss',
'./src/assets/sprites/*.scss'
]
})
.end()
})
config.module
.rule('svg')
.exclude.add(path.join(__dirname, 'src/assets/icons'))
.end()
config.module
.rule('icons')
.test(/\.svg$/)
.include.add(path.join(__dirname, 'src/assets/icons'))
.end()
.use('svg-sprite-loader')
.loader('svg-sprite-loader')
.options({
symbolId: 'icon-[name]'
})
.end()
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化