Skip to content

Commit

Permalink
feat: use rollup
Browse files Browse the repository at this point in the history
  • Loading branch information
test123456789012345 committed Jul 21, 2020
1 parent 614a3df commit 4826959
Show file tree
Hide file tree
Showing 4 changed files with 1,609 additions and 635 deletions.
7 changes: 6 additions & 1 deletion package.json
Expand Up @@ -18,7 +18,12 @@
"test": "base test"
},
"dependencies": {
"@dword-design/base-config-component": "^1.0.0"
"@dword-design/base-config-component": "^1.1.0",
"@dword-design/functions": "^1.1.3",
"@dword-design/rollup-config-component": "^1.0.0",
"execa": "^4.0.3",
"fs-extra": "^9.0.1",
"get-package-name": "^1.1.0"
},
"devDependencies": {
"@dword-design/base": "^6.10.0"
Expand Down
42 changes: 42 additions & 0 deletions src/entry.js
@@ -0,0 +1,42 @@
import { endent } from '@dword-design/functions'

export default endent`
// Import vue components
import * as components from '.';
// install function executed by Vue.use()
const install = function installVueIcon(Vue) {
if (install.installed) return;
install.installed = true;
Object.entries(components).forEach(([componentName, component]) => {
Vue.component(componentName, component);
});
};
// Create module definition for Vue.use()
const plugin = {
install,
};
// To auto-install on non-es builds, when vue is found
// eslint-disable-next-line no-redeclare
/* global window, global */
if ('false' === process.env.ES_BUILD) {
let GlobalVue = null;
if (typeof window !== 'undefined') {
GlobalVue = window.Vue;
} else if (typeof global !== 'undefined') {
GlobalVue = global.Vue;
}
if (GlobalVue) {
GlobalVue.use(plugin);
}
}
// Default export is library as a whole, registered via Vue.use()
export default plugin;
// To allow individual component use, export components
// each can be registered via Vue.component()
export * from '.';
`
28 changes: 26 additions & 2 deletions src/index.js
@@ -1,8 +1,32 @@
import componentConfig from '@dword-design/base-config-component'
import execa from 'execa'
import { outputFile, remove } from 'fs-extra'
import getPackageName from 'get-package-name'
import P from 'path'

import entry from './entry'

export default {
...componentConfig,
packageConfig: {
main: 'dist/index.js',
commands: {
...componentConfig.commands,
prepublishOnly: async () => {
try {
await outputFile(P.join('src', 'entry.js'), entry)
await remove('dist')
await execa(
getPackageName(require.resolve('rollup')),
[
'--config',
require.resolve('@dword-design/rollup-config-component'),
],
{
env: { NODE_ENV: 'production', stdio: 'inherit' },
}
)
} finally {
await remove(P.join('src', 'entry.js'))
}
},
},
}

0 comments on commit 4826959

Please sign in to comment.