Skip to content

Commit 9f5fee3

Browse files
authored
Option to allow use a scss config (#23)
* Enhancement: add option to use a scss config * fix: move webpack mod * fix: eslint import/no-extraneous-dependencies * refactor: update app in scss option * refactor: update app in scss option * fix: rename scss/_custom.scss file * comment all variables * fix: bootstrap variables import * fix: remove polyfill from dev deps to deps (eslint error)
1 parent 7e0e87a commit 9f5fee3

File tree

7 files changed

+1373
-8
lines changed

7 files changed

+1373
-8
lines changed

generator/helpers.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ module.exports = function (api) {
5353

5454
content = lines.join('\n')
5555
fs.writeFileSync(mainPath, content, { encoding: 'utf8' })
56+
},
57+
58+
//TODO: refactor since is equal to updateMain
59+
updateApp(callback){
60+
const appPath = api.resolve('./src/App.vue')
61+
62+
let content = fs.readFileSync(appPath, { encoding: 'utf8' })
63+
let lines = content.split(/\r?\n/g)
64+
lines = callback(lines)
65+
66+
content = lines.join('\n')
67+
fs.writeFileSync(appPath, content, { encoding: 'utf8' })
5668
}
5769
}
5870
}

generator/index.js

Lines changed: 38 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,30 @@ module.exports = (api, opts, rootOpts) => {
33

44
api.extendPackage({
55
dependencies: {
6-
'bootstrap-vue': '^2.17.3'
7-
},
8-
devDependencies: {
6+
'bootstrap-vue': '^2.17.3',
97
'bootstrap': '^4.5.2',
108
'popper.js': '^1.16.1',
11-
'portal-vue': '^2.1.7',
9+
'portal-vue': '^2.1.7'
10+
},
11+
devDependencies: {
1212
'sass': '^1.26.11',
1313
'sass-loader': '^10.0.2',
1414
}
1515
})
1616

1717
if (opts.usePolyfill) {
1818
api.extendPackage({
19-
devDependencies: {
19+
dependencies: {
2020
'@babel/polyfill': '^7.11.5',
2121
'mutationobserver-shim': '^0.3.7'
2222
}
2323
})
2424
}
2525

2626
// Render bootstrap-vue plugin file
27-
api.render({
28-
'./src/plugins/bootstrap-vue.js': './templates/default/src/plugins/bootstrap-vue.js'
29-
}, opts)
27+
const templateName = opts.useScss ? 'scss' : 'default'
28+
api.render(`./templates/${templateName}`)
29+
3030

3131
// adapted from https://github.com/Akryum/vue-cli-plugin-apollo/blob/master/generator/index.js#L68-L91
3232
api.onCreateComplete(() => {
@@ -39,6 +39,36 @@ module.exports = (api, opts, rootOpts) => {
3939
return src
4040
})
4141

42+
if(opts.useScss){
43+
44+
45+
//Modify App.vue (import bootstrap styles)
46+
helpers.updateApp(src => {
47+
let styleBlockIndex = src.findIndex(line => line.match(/^<style/))
48+
49+
if(styleBlockIndex === -1){ //no style block found
50+
//create it with lang scss
51+
src.push(`<style lang="scss">`)
52+
src.push(`</style>`)
53+
54+
styleBlockIndex = src.length - 2
55+
}
56+
else{
57+
//check if has the attr lang="scss"
58+
if(!src[styleBlockIndex].includes('lang="scss')){
59+
//if not, replace line with lang="scss"
60+
src[styleBlockIndex] = '<style lang="scss">'
61+
}
62+
}
63+
64+
const bootstrapImportString = `@import "~@/assets/scss/vendors/bootstrap-vue/index";\n`
65+
src.splice(styleBlockIndex + 1, 0, bootstrapImportString)
66+
67+
return src
68+
})
69+
}
70+
71+
4272
// Add polyfill
4373
if (opts.usePolyfill) {
4474
helpers.updateBabelConfig(cfg => {

0 commit comments

Comments
 (0)