I'm quite new in Vue and maybe my issue is trivial.
What I have to do:
I want to create a Vue component that I can put in a NPM private repo and import it into other projects with a sth like bundle.js file
TLDR:
can't import vue component building by vue-cli-service build --target lib/wc. Importing component I have sth silimar to "export 'HelloWorld' was not found in '../node_modules/hello-world'
long version:
I have asked questions and projects as much as I could. All projects are built by vue-cli without any additional changes.
create new default project vue create hello-world
by default we havefirst component here - src/component/HelloWorld, and for this example this is component which we want to export
using vue-cli-service try to make exportable file.
3a. vue-cli-service build --target lib --name vue-test ./src/components/index.js where index.js is
import Vue from 'vue';
import HelloWorld from './HelloWorld.vue';
const Components = {
HelloWorld,
};
Object.keys(Components).forEach((name) => {
Vue.component(name, Components[name]);
});
export default Components;
3b. or directly vue file vue-cli-service build --target wc --name vue-test 'src/components/HelloWorld.vue'
in both scenarios vue-cli-service generates me file in to /dist folder and I want to believe this file are correct
in both scenarios I can't import this component to another vue project using import {HelloWorld} from 'path/to/folder/or/file'; or require('path/to/folder/or/file'). It seems like bundle files haven't exported member.
what I doing wrong? Should use build --target wc or build --target lib?
If You don't want to create new app to reproduce this issue U can download repo from https://github.com/okosowski/vueTest (project started using vue cli).
git clone
npm install
npm run build-bundle-lib or npm run build-bundle-lib
npm link or simply copy file to exiting vue project
try to import/display HelloWorld
I will be grateful for any help!!!
thanks
node v10.14.2
npm 6.4.1
vue-Cli 2.9.6 (the same on 3.3.0)
other used version in https://github.com/okosowski/vueTest/blob/master/package.json
I was facing the same exact problem while using vue-cli to build and test my Vue component. Fortunately I was able to find the solution after reporting it as a bug to vue-cli issue tracker on GitHub. Turned out there was nothing wrong with the common.js file nor was it a bug.
Anyway... long story short, the existing project you are trying to import into is unable to resolve symlinks (because this is what happens when you use npm link). In order to solve your problem, you need to add the following into vue.config.js in the root folder of the project you are importing into:
// vue.config.js
module.exports = {
chainWebpack: config => config.resolve.set('symlinks', false)
}
Hope this helps. For more info, check out these links:
My issue report in the vue-cli tracker
Webpack configuration: resolve.symlinks
Related
I want to use tailwind typeahead vue plugin in nuxt. i have added the package using npm install vue-tailwindcss-typeahead .
then i created a file in plugins folder. tailwind-typeahead.js with following code
import Vue from 'vue'
import VueTailwindcssTypeahead from 'vue-tailwindcsscss-typeahead'
Vue.use(VueTailwindcssTypeahead)
and included the plugin file in nuxt.config.js
{ src: './plugins/tailwind-typeahead.js' }
But i am getting this error
This dependency was not found: friendly-errors 01:44:37
friendly-errors 01:44:37
* vue-tailwindcsscss-typeahead in ./plugins/tailwind-typeahead.js friendly-errors 01:44:37
friendly-errors 01:44:37
To install it, you can run: npm install --save vue-tailwindcsscss-typeahead
for reference here is the link of package
https://github.com/basarozcan/vue-tailwindcss-typeahead
You do have a typo in your plugin: vue-tailwindcsscss-typeahead.
You probably meant to write vue-tailwindcss-typeahead .
The rest is fine and it's the way to go if you want your code to be globally available in your Nuxt app. If you only want it local, import it in the component itself.
I have a project with two packages:
components/
apps/
Both are built using #vue/cli, and I'm using yarn workspaces to manage dependencies.
Everything is working, except Hot Module Replacement when running the app.
components/package.json: main: dist/components.umd.js
app/package.json: components are a dependency, I import like import MyComponent from 'components'
In dev mode I run two tasks in parallel:
components: vue-cli-service build --target lib --watch
app: vue-cli-service serve
I want to change MyComponent in components/src/ and have it hot reload in the dev server.
However, I can only see the changes when I refresh the page.
I know the Vue cli splits source and vendor js bundles, so I thought this may be the cause of the problem?
Does anyone have any suggestions?
I am quite unfamiliar with npm, (I develop in python) and most of the time I just do what the tutorial says. But now I am stuck. I tried Tailwindcss in combination wit 'Vue 3' and followed the install steps from the website:website tailwind+Vue 3
npm init #vitejs/app my-project
cd my-project
npm install
npm install -D tailwindcss#latest postcss#latest autoprefixer#latest
npx tailwindcss init -p
And after adding some HTML and running:
npm run dev
everything works fine in the browser.
But then Iwant to build it for using in production I use
npm run build
and after some processing my dist folder is filled with an index.html and assets.
And here starts my problem. I was expecting that I could copy these files to my server and that it should serve my site. But All I see is a blank page.
I can't find the answer anywhere or others with same problems so I think its something stupid I just don't know. But what is it?
Hope someone can help me...
Try this, maybe something will work
https://dev.to/vonagedev/using-tailwind-css-with-vue-js-b1b
Webpack (and Vue-loader which is a Webpack loader for Vue.js components) can be configured to use PostCSS which is a Webpack loader for CSS.
It will look for the configuration inside a postcss.config.js file and can build the app with CSS from packages you add.
And, configure it using this code.
// postcss.config.js
const autoprefixer = require('autoprefixer');
const tailwindcss = require('tailwindcss');
module.exports = {
plugins: [
tailwindcss,
autoprefixer,
],
};
The demo app is also generated without any CSS assets. Instead, it uses CSS inside the components (which is fine). To include Tailwind CSS, create a CSS asset using your editor or the commands below.
# mkdir -p for making parents they don't exist
mkdir -p src/assets/styles/
touch src/assets/styles/index.css
Now add this code, which adds the various packages of the Tailwind CSS library.
/* src/assets/styles/index.css */
#tailwind base;
#tailwind components;
#tailwind utilities;
```
I am creating a stencil project which uses an npm package inside it, is there any options to add an npm package inside stencil project. Any suggestions I searching for a solution for quite a while.
This is how i use ck-editor in angular
<ck-editor name="editor" #myEditor [(ngModel)]="templateSetValue.template_content"
(change)="handleEditorData($event)">
</ck-editor>
Is it possible to use the same is stencil project
https://www.npmjs.com/package/ngx-ckeditor
Not sure if I understood the question correctly, but to add a package from npm in your Stencil.js project, you can just install it, like you would in any other node project:
npm install <some-package>
For example nprogress:
npm install nprogress #types/nprogress
and then import it in your code like
import nprogress from 'nprogress';
nprogress.start();
// ...
I have a Vue app that is using link-module-alias in some places like this:
import MyPage from '#/components/MyPage'
In main.js of that app, I am exporting the entire app as a variable.
export const VueApp = () => {
var app = new Vue({
render: h => h(App)
}).$mount('#app')
return app
}
This app gets built and published to NPM. I can require it in another Vue app, and just put VueApp() on the main page to reproduce the site.
In the root folder of that project, I ran:
npm link
...as we want to set up a dev environment for development of project that is going to consume the NPM package eventually.
In a new project, I consume the local NPM package with this command:
npm link myapp
After that, I can see all the source code in the node_modules/myapp folder.
Running the app, I get an error:
These dependencies were not found
#/components/MyPage in /Users/<username>/source/myapp/src/index.js
I believe I need to add a resolve to a webpack.config.js for the # character. I don't have a webpack.config.js, but I do have a vue.config.js.
I'm just not sure how to add the resolve to vue.config.js.
From Vue CLI docs:
Symbolic Links in node_modules
If there're dependencies installed by npm link or yarn link, ESLint (and sometimes Babel as well) may not work > properly for those symlinked dependencies. It is because webpack resolves symlinks to their real locations by default, thus breaks ESLint / Babel config lookup.
A workaround for this issue is to manually disable symlinks resolution in webpack:
// vue.config.js
module.exports = {
chainWebpack: (config) => {
config.resolve.symlinks(false)
}
}
Warning:
Disabling resolve.symlinks may break hot module reloading if your dependencies are installed by third-party npm clients that utilized symbolic links, such ascnpm or pnpm.
You'll need to create <project-root>/vue.config.js if it doesn't already exist.