I am working on a project containing a Vuex module and an abstract components that users can extend from.
I would love to publish this on NPM to clean up my codebase and pull this away from my project as a solid well tested module. I have specified the main file in
package.json
import AbstractFilter from './src/components/filters/abstract/AbstractFilter.vue';
import Search from './src/store/modules/search';
module.exports = {
AbstractFilter,
Search
};
build
libraryTarget: 'umd'
Universal Module Definition
externals: {}
dist
The best way probably will be to build the module and set main
in your package.json
to my_dist/my_index.js
. Otherwise every project that will use your module will have to add it to include
which is tedious.
You will also want your webpack build to follow UMD (Universal Module Definition). For that you must set libraryTarget
to umd
:
...
output: {
filename: 'index.js',
library:'my_lib_name',
libraryTarget: 'umd'
},
...
Also a good thing will be to add Vue
to externals
so that you didn't pack extra 200kb of vue library.
externals: {
vue: 'vue'
},
resolve: {
alias: {
'vue$': 'vue/dist/vue.esm.js'
}
}
If you need an existing example of how to pack a vue.js component, you can take a look in one of the modules I maintain:
https://github.com/euvl/vue-js-popover
Particularly webpack.config.js
and package.json
will be interesting for you.