|
| 1 | +const fs = require('fs') |
| 2 | + |
1 | 3 | module.exports = (api, opts, rootOpts) => { |
2 | 4 | const helpers = require('./helpers')(api) |
3 | 5 |
|
@@ -43,22 +45,52 @@ module.exports = (api, opts, rootOpts) => { |
43 | 45 |
|
44 | 46 | if(styleBlockIndex === -1){ //no style block found |
45 | 47 | //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>`) |
48 | 50 |
|
49 | | - styleBlockIndex = src.length - 2 |
| 51 | + styleBlockIndex = srcLines.length - 2 |
50 | 52 | } |
51 | 53 | else{ |
52 | 54 | //check if has the attr lang="scss" |
53 | | - if(!src[styleBlockIndex].includes('lang="scss')){ |
| 55 | + if(!srcLines[styleBlockIndex].includes('lang="scss')){ |
54 | 56 | //if not, replace line with lang="scss" |
55 | | - src[styleBlockIndex] = '<style lang="scss">' |
| 57 | + srcLines[styleBlockIndex] = '<style lang="scss">' |
56 | 58 | } |
57 | 59 | } |
58 | 60 |
|
59 | 61 | const bootstrapImportString = `@import "~@/assets/scss/vendors/bootstrap-vue/index";` |
60 | | - src.splice(styleBlockIndex + 1, 0, bootstrapImportString) |
| 62 | + srcLines.splice(styleBlockIndex + 1, 0, bootstrapImportString) |
61 | 63 | }) |
| 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 | + } |
62 | 94 | } |
63 | 95 |
|
64 | 96 |
|
|
0 commit comments