Skip to content

Commit d07aea1

Browse files
committed
fix: inject bootstrap abstract
1 parent f767232 commit d07aea1

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

generator/index.js

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const fs = require('fs')
2+
13
module.exports = (api, opts, rootOpts) => {
24
const helpers = require('./helpers')(api)
35

@@ -43,22 +45,52 @@ module.exports = (api, opts, rootOpts) => {
4345

4446
if(styleBlockIndex === -1){ //no style block found
4547
//create it with lang scss
46-
src.push(`<style lang="scss">`)
47-
src.push(`</style>`)
48+
srcLines.push(`<style lang="scss">`)
49+
srcLines.push(`</style>`)
4850

49-
styleBlockIndex = src.length - 2
51+
styleBlockIndex = srcLines.length - 2
5052
}
5153
else{
5254
//check if has the attr lang="scss"
53-
if(!src[styleBlockIndex].includes('lang="scss')){
55+
if(!srcLines[styleBlockIndex].includes('lang="scss')){
5456
//if not, replace line with lang="scss"
55-
src[styleBlockIndex] = '<style lang="scss">'
57+
srcLines[styleBlockIndex] = '<style lang="scss">'
5658
}
5759
}
5860

5961
const bootstrapImportString = `@import "~@/assets/scss/vendors/bootstrap-vue/index";`
60-
src.splice(styleBlockIndex + 1, 0, bootstrapImportString)
62+
srcLines.splice(styleBlockIndex + 1, 0, bootstrapImportString)
6163
})
64+
65+
if(opts.injectAbstracts){
66+
//create/modify vue.config.js
67+
const vueConfigPath = api.resolve('./vue.config.js')
68+
if(!fs.existsSync(vueConfigPath)){
69+
const content = `module.exports = {\n}`
70+
fs.writeFileSync(vueConfigPath, content, { encoding: 'utf-8' })
71+
}
72+
73+
helpers.updateFile(vueConfigPath, srcLines => {
74+
let index = 0
75+
srcLines.splice(index, 0, `const bootstrapSassAbstractsImports = require('vue-cli-plugin-bootstrap-vue/sassAbstractsImports.js')`)
76+
77+
const bootstrapAbstractsContentLines = [
78+
"\tcss: {",
79+
"\t\tloaderOptions: {",
80+
"\t\t\tsass: {",
81+
"\t\t\t\tadditionalData: bootstrapSassAbstractsImports.join('\\n')",
82+
"\t\t\t},",
83+
"\t\t\tscss: {",
84+
"\t\t\t\tadditionalData: [...bootstrapSassAbstractsImports, ''].join(';\\n')",
85+
"\t\t\t}",
86+
"\t\t}",
87+
'\t}'
88+
]
89+
index = srcLines.length - 1
90+
srcLines.splice(index, 0, bootstrapAbstractsContentLines.join('\n'))
91+
92+
})
93+
}
6294
}
6395

6496

0 commit comments

Comments
 (0)