-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: vue build --target multi-wc [pattern]
- Loading branch information
Showing
11 changed files
with
91 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
entry-multi-wc.js |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import Vue from 'vue' | ||
import wrap from '@vue/web-component-wrapper' | ||
import Component from '~entry' | ||
|
||
window.customElements.define( | ||
process.env.CUSTOM_ELEMENT_NAME, | ||
wrap(Vue, Component) | ||
) |
12 changes: 0 additions & 12 deletions
12
packages/@vue/cli-service/lib/commands/build/entry-web-component.js
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
packages/@vue/cli-service/lib/commands/build/generateMultiWcEntry.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
|
||
const camelizeRE = /-(\w)/g | ||
const camelize = str => { | ||
return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '') | ||
} | ||
|
||
const hyphenateRE = /\B([A-Z])/g | ||
const hyphenate = str => { | ||
return str.replace(hyphenateRE, '-$1').toLowerCase() | ||
} | ||
|
||
module.exports = function generateMultiWebComponentEntry (prefix, files) { | ||
const filePath = path.resolve(__dirname, 'entry-multi-wc.js') | ||
const content = ` | ||
import Vue from 'vue' | ||
import wrap from '@vue/web-component-wrapper' | ||
${files.map(file => { | ||
const basename = path.basename(file).replace(/\.(jsx?|vue)$/, '') | ||
const camelName = camelize(basename) | ||
const kebabName = hyphenate(basename) | ||
return ( | ||
`import ${camelName} from '~root/${file}'\n` + | ||
`window.customElements.define('${prefix}-${kebabName}', wrap(Vue, ${camelName}))\n` | ||
) | ||
}).join('\n')}`.trim() | ||
fs.writeFileSync(filePath, content) | ||
return filePath | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters