-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
switching to vite !! + umd support -- #137
- Loading branch information
Showing
20 changed files
with
327 additions
and
290 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,3 @@ | ||
/dist/ | ||
/dist_demo/ | ||
/package/dist/ |
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,39 @@ | ||
module.exports = { | ||
root: true, | ||
extends: [ | ||
// https://eslint.vuejs.org/user-guide/#installation | ||
// add more generic rulesets here, such as: | ||
'eslint:recommended', | ||
'@vue/standard', | ||
// 'plugin:vue/vue3-recommended', | ||
'plugin:vue/recommended', // Use this if you are using Vue.js 2.x. | ||
|
||
], | ||
rules: { | ||
'space-before-function-paren': 'warn', | ||
'operator-linebreak': 'warn', | ||
'no-tabs': 'warn', | ||
'no-new': 'warn', | ||
eqeqeq: 'warn', | ||
indent: 'warn', | ||
quotes: 'warn', | ||
semi: 'warn', | ||
'vue/multi-word-component-names': 'off', | ||
'no-var': 'off', | ||
// ... | ||
'vue/multiline-html-element-content-newline': 'off', | ||
'vue/first-attribute-linebreak': 'off', | ||
'vue/max-attributes-per-line': 'off', | ||
'vue/order-in-components': 'off', | ||
'vue/attributes-order': 'off', | ||
'vue/html-indent': 'off', | ||
'no-irregular-whitespace': 'off', | ||
'no-mixed-operators': 'off', | ||
'no-unused-vars': 'off', | ||
'prefer-const': 'off', | ||
'comma-dangle': 'off', | ||
'max-len': 'off', | ||
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', | ||
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off' | ||
} | ||
} |
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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
.DS_Store | ||
node_modules*/ | ||
dist/ | ||
dist_demo/ | ||
package/ | ||
*.tgz | ||
npm-debug.log | ||
yarn-error.log |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// supports vite css.extract=false. | ||
// credits: @ruofee | ||
// https://github.com/vitejs/vite/issues/4345#issuecomment-1073734133 | ||
// https://github.com/ruofee/vue-dynamic-form-component/blob/vite/build/ViteSingleCssPlugin.js | ||
|
||
let packageNames = [] | ||
let viteConfig | ||
let IIFEcss | ||
|
||
// __notice__: this is for package.json without `type=module` | ||
// https://vitejs.dev/guide/build.html#library-mode | ||
// https://nodejs.org/api/packages.html#type | ||
let extMap = { | ||
cjs: '.js', | ||
es: '.mjs', | ||
umd: '.umd.js', | ||
} | ||
|
||
// 将 css 打包到 js 文件中 | ||
export default function () { | ||
return { | ||
apply: 'build', | ||
enforce: 'post', | ||
name: 'pack-css', | ||
configResolved (config) { | ||
viteConfig = config | ||
packageNames = viteConfig.build.lib.formats.map(format => { | ||
return viteConfig.build.lib.fileName + extMap[format] | ||
}) | ||
}, | ||
generateBundle (_, bundle) { | ||
const cssFileName = 'style.css' | ||
const { [cssFileName]: cssBundle } = bundle | ||
if (cssBundle) { | ||
IIFEcss = `(function() {try {var elementStyle = document.createElement('style');elementStyle.textContent = ${JSON.stringify( | ||
cssBundle.source | ||
)};document.head.appendChild(elementStyle);} catch(error) {console.error(error, 'unable to concat style inside the bundled file')}})()` | ||
delete bundle[cssFileName] | ||
} | ||
packageNames.forEach(packageName => { | ||
if (bundle[packageName]) { | ||
bundle[packageName].code += ';;' + IIFEcss + ';;' | ||
} | ||
}) | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>vue-at</title> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="demo/vite.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>Demo: vue-at</title> | ||
</head> | ||
<body> | ||
<div id="app"></div> | ||
<script src="dist/demo.js"></script> | ||
<script type="module" src="src/main.js"></script> | ||
</body> | ||
</html> |
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
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.