I’m working on a project created with Vue Cli 3 and I’ve been working with Vue web components.
I need to create a loader file (called loader.js) that will require different libraries.
require(‘.node_modules/…/…/library.js’);
require(‘.node_modules/…/…/script.js’);
I use this command to compile the web component:
vue-cli-service build --target wc --name widget ./src/components/widget.vue
What I need at this point it that when build the web component, webpack also process the loader.js file and bundle all the require
inside the dist folder.
I’m new working with webpack and I don’t know how can I resolve this. I’ve tried to use the CopyWebpackPlugin but it only copied the loader.js file and does’nt include the require files.
module.exports = {
plugins: [
new CopyWebpackPlugin(
[
{
from: 'src/loader.js',
to: '.',
},
],
),
],
}
How can I solve this?
src/loader.js
isn't referenced anywhere in your component, it won't be bundled. Remove theCopyWebpackPlugin
config, and importsrc/loader.js
from your component file. – Osmiumloader.js
file and then executed the "vue-cli-service build ..." command. – Frizzle