-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: first implementation of generator
- Loading branch information
Showing
14 changed files
with
438 additions
and
5 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
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,3 @@ | ||
current node | ||
last 2 versions and > 2% | ||
ie > 10 |
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,5 @@ | ||
const devPresets = ["@vue/babel-preset-app"]; | ||
const buildPresets = ["@babel/preset-env"<% if (ts) { -%>, "@babel/preset-typescript"<% } -%>]; | ||
module.exports = { | ||
presets: (process.env.NODE_ENV === "development" ? devPresets : buildPresets), | ||
}; |
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,125 @@ | ||
// rollup.config.js | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import vue from 'rollup-plugin-vue'; | ||
import alias from '@rollup/plugin-alias'; | ||
import commonjs from '@rollup/plugin-commonjs'; | ||
import resolve from '@rollup/plugin-node-resolve'; | ||
import replace from '@rollup/plugin-replace'; | ||
import babel from '@rollup/plugin-babel'; | ||
<% if (version === 3) { -%> | ||
import PostCSS from 'rollup-plugin-postcss'; | ||
<% } -%> | ||
import { terser } from 'rollup-plugin-terser'; | ||
import minimist from 'minimist'; | ||
|
||
// Get browserslist config and remove ie from es build targets | ||
const esbrowserslist = fs.readFileSync('./.browserslistrc') | ||
.toString() | ||
.split('\n') | ||
.filter((entry) => entry && entry.substring(0, 2) !== 'ie'); | ||
|
||
const argv = minimist(process.argv.slice(2)); | ||
|
||
const projectRoot = path.resolve(__dirname, '..'); | ||
|
||
const baseConfig = { | ||
input: 'src/entry.<% if (ts) {%>ts<% } else { %>js<% } %>', | ||
plugins: { | ||
preVue: [ | ||
alias({ | ||
entries: [ | ||
{ | ||
find: '@', | ||
replacement: `${path.resolve(projectRoot, 'src')}`, | ||
}, | ||
], | ||
}), | ||
], | ||
replace: { | ||
'process.env.NODE_ENV': JSON.stringify('production'), | ||
}, | ||
vue: { | ||
<% if (version === 2) { -%> | ||
css: true, | ||
template: { | ||
isProduction: true, | ||
}, | ||
<% } -%> | ||
}, | ||
postVue: [ | ||
resolve({ | ||
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'], | ||
}), | ||
<% if (version === 3) { -%> | ||
// Process only `<style module>` blocks. | ||
PostCSS({ | ||
modules: { | ||
generateScopedName: '[local]___[hash:base64:5]', | ||
}, | ||
include: /&module=.*\.css$/, | ||
}), | ||
// Process all `<style>` blocks except `<style module>`. | ||
PostCSS({ include: /(?<!&module=.*)\.css$/ }), | ||
<% } -%> | ||
], | ||
babel: { | ||
exclude: 'node_modules/**', | ||
extensions: ['.js', '.jsx', '.ts', '.tsx', '.vue'], | ||
babelHelpers: 'bundled', | ||
}, | ||
}, | ||
}; | ||
|
||
// ESM/UMD/IIFE shared settings: externals | ||
// Refer to https://rollupjs.org/guide/en/#warning-treating-module-as-external-dependency | ||
const external = [ | ||
// list external dependencies, exactly the way it is written in the import statement. | ||
// eg. 'jquery' | ||
'vue', | ||
]; | ||
|
||
// UMD/IIFE shared settings: output.globals | ||
// Refer to https://rollupjs.org/guide/en#output-globals for details | ||
const globals = { | ||
// Provide global variable names to replace your external imports | ||
// eg. jquery: '$' | ||
vue: 'Vue', | ||
}; | ||
|
||
// Customize configs for individual targets | ||
const buildFormats = []; | ||
if (!argv.format || argv.format === 'es') { | ||
const esConfig = { | ||
...baseConfig, | ||
input: 'src/entry.esm.<% if (ts) {%>ts<% } else { %>js<% } %>', | ||
external, | ||
output: { | ||
file: 'dist/<%-componentName%>.esm.js', | ||
format: 'esm', | ||
exports: 'named', | ||
}, | ||
plugins: [ | ||
replace(baseConfig.plugins.replace), | ||
...baseConfig.plugins.preVue, | ||
vue(baseConfig.plugins.vue), | ||
...baseConfig.plugins.postVue, | ||
babel({ | ||
...baseConfig.plugins.babel, | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: esbrowserslist, | ||
}, | ||
], | ||
], | ||
}), | ||
commonjs(), | ||
], | ||
}; | ||
buildFormats.push(esConfig); | ||
} | ||
|
||
// Export config | ||
export default buildFormats; |
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,24 @@ | ||
<% if (version === 3) { -%> | ||
import { createApp } from "vue"; | ||
import Dev from "./serve.vue"; | ||
|
||
const app = createApp(Dev); | ||
app.mount("#app"); | ||
<% } else { | ||
if (ts) { -%> | ||
import Vue, { VNode } from "vue"; | ||
<% } else { -%> | ||
import Vue from "vue"; | ||
<% } -%> | ||
import Dev from "./serve.vue"; | ||
|
||
Vue.config.productionTip = false; | ||
|
||
new Vue({ | ||
<% if (ts) { -%> | ||
render: (h): VNode => h(Dev), | ||
<% } else { -%> | ||
render: (h) => h(Dev), | ||
<% } -%> | ||
}).$mount("#app"); | ||
<% } -%> |
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,17 @@ | ||
<script<% if (ts) { %> lang="ts"<% } %>> | ||
<% if (version === 3) { -%> | ||
import { defineComponent } from "vue"; | ||
<% } else { -%> | ||
import Vue from "vue"; | ||
<% } -%> | ||
export default <% if (version === 3) {%>defineComponent<% } else { %>Vue.extend<% } %>({ | ||
name: "ServeDev", | ||
}); | ||
</script> | ||
|
||
<template> | ||
<div id="app"> | ||
Hello, World | ||
</div> | ||
</template> |
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,81 @@ | ||
{ | ||
"name": "<%-npmName>", | ||
"version": "0.0.1", | ||
"description": "", | ||
"main": "dist/<%-npmName%>/esm.js", | ||
"browser": "dist/<%-npmName%>/esm.js", | ||
"module": "dist/<%-npmName%>/esm.js", | ||
<% if (ts) { -%> | ||
"types": "<%-npmName%>.d.ts", | ||
<% } -%> | ||
"files": [ | ||
"dist/*", | ||
<% if (ts) { -%> | ||
"<%-npmName%>.d.ts", | ||
<% } -%> | ||
"src/**/*.vue" | ||
], | ||
"sideEffects": false, | ||
"scripts": { | ||
"serve": "vue-cli-service serve dev/serve.<% if (ts) { %>ts<% } else { %>js<% } %>", | ||
"build": "cross-env NODE_ENV=production rollup --config build/rollup.config.js", | ||
"build:ssr": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format cjs", | ||
"build:es": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format es", | ||
"build:unpkg": "cross-env NODE_ENV=production rollup --config build/rollup.config.js --format iife" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@babel/core": "^7.12.10", | ||
"@babel/preset-env": "^7.12.11", | ||
<% if (ts) { -%> | ||
"@babel/preset-typescript": "^7.12.7", | ||
<% } -%> | ||
"@rollup/plugin-alias": "^3.1.1", | ||
"@rollup/plugin-babel": "^5.2.2", | ||
"@rollup/plugin-commonjs": "^17.0.0", | ||
"@rollup/plugin-node-resolve": "^11.0.1", | ||
"@rollup/plugin-replace": "^2.3.4", | ||
"@vue/cli-plugin-babel": "^4.5.10", | ||
<% if (ts) { -%> | ||
"@vue/cli-plugin-typescript": "^4.5.10", | ||
<% } -%> | ||
"@vue/cli-service": "^4.5.10", | ||
<% if (version === 3) { -%> | ||
"@vue/compiler-sfc": "^3.0.5", | ||
<% } -%> | ||
"cross-env": "^7.0.3", | ||
"minimist": "^1.2.5", | ||
<% if (version === 3) { -%> | ||
"postcss": "^8.2.3", | ||
<% } -%> | ||
"rollup": "^2.36.1", | ||
<% if (version === 3) { -%> | ||
"rollup-plugin-postcss": "^4.0.0", | ||
<% } -%> | ||
"rollup-plugin-terser": "^7.0.2", | ||
<% if (version === 3) { -%> | ||
"rollup-plugin-vue": "^6.0.0", | ||
<% } else { -%> | ||
"rollup-plugin-vue": "^5.1.9", | ||
<% } -%> | ||
<% if (ts) { -%> | ||
"typescript": "^3.8.3", | ||
<% } -%> | ||
<% if (version === 3) { -%> | ||
"vue": "^3.0.5" | ||
<% } else { -%> | ||
"vue": "^2.6.12", | ||
"vue-template-compiler": "^2.6.12" | ||
<% } -%> | ||
}, | ||
"peerDependecies": { | ||
<% if (version === 3) { -%> | ||
"vue": "^3.0.5" | ||
<% } else { -%> | ||
"vue": "^2.6.12" | ||
<% } -%> | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
} | ||
} |
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,11 @@ | ||
import Vue, { VNode } from "vue"; | ||
|
||
declare global { | ||
namespace JSX { | ||
interface Element extends VNode {} | ||
interface ElementClass extends Vue {} | ||
interface IntrinsicElements { | ||
[elem: string]: any | ||
} | ||
} | ||
} |
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,11 @@ | ||
declare module "*.vue" { | ||
<% if (version === 3) { -%> | ||
import { DefineComponent } from "vue"; | ||
|
||
const Component: DefineComponent<{}, {}, any>; | ||
export default Component; | ||
<% } else { -%> | ||
import Vue from "vue"; | ||
export default Vue; | ||
<% } -%> | ||
} |
Oops, something went wrong.