I'm creating a wordpress package which uses acf (Advanced Custom Fields) to get and set the data.
Additional data about the usage:
First in your project's config.php file you set the settings for the composer package. Then in wordpress you can call the block "photoplayer". You can give the block some data and the data is accessible in the composer package.
But now comes my problem. The frontend needs to be in vuejs since this is a composer package and vue is a peerdependency vue isn't accessible because it's in the vendor folder. A hacky way which you don't want to do ever is to install the npm packages inside the package in the vendor folder (this will cause more problems because vue uses singleton). So I choose to make a vue package for this with npm.
Now I've just created the frontend inside a npm package, but how will i get the composer packages data to the npm package in the frontend?
I've thought of an API, but I think that that solution is to overcomplex for such a problem.
Here's a solution to this problem:
Requirements:
main project
npm package (in my case created in vue)
composer package
Here you'll find on how to create and use a local npm package.
Here you'll find on how to create and use a local composer package
First you'll need to install your local packages:
npm i path/to/package/package-name.tgz
composer require path/to/package/
The npm package exports a component:
import MyVueComponent from "./MyVueComponent.vue";
export { MyVueComponent }
This makes it so that we can mount this vue component to the projects createapp:
import { createApp } from 'vue'
import { MyVueComponent } from "my/package";
const app = createApp({})
app.component('MyVueComponent', MyVueComponent)
app.mount('#app')
Now you can use the MyVueComponent as a custom html tag within your #app. Now in the composer package we create a template file something like template.php will do you can name it however you like. Within this template we call the vue component:
<my-vue-component
:name-of-property="'Data you want to provide'"
:name-of-second-prop="'More data'"
></my-vue-component>
Now I've passed some data to the props of the vue component. You can learn how to use props in vue here.
In my case showcasing the template is easily done using ACF and wordpress, but rendering a composer template file is a little out of scope here.
Related
Like in python i install a package using
pip install django
inside a virtualenv,
Then it puts all the files in site-packages folder. and then i can import the package using
from django.core import mail
But i can easily browse the code of django/core in site-packages
Similarly if I install a package using npm can i see the source of that
Eg:
import React, { useEffect } from "react";
Now i want to see the react file and go through the React and useEffect
Is it possible
I do not have background in Python. So, can't explain or compare in Python way. But, yes! You can read or go through the source code in most of the cases.
Now, talking about the specific example you mentioned in question - React. Things are little complicated as we're talking about one of the popular library. You may wouldn't find React.js or react.js file directly. But, that doesn't mean you can read the source code. Let's do it.
Create an application that has react as dependency (You can create an application using create-react-app).
In this application, you'll have node_modules folder. Within this node_modules, you'll have folder after the name of dependency e.g. react. Go inside this folder.
You'll find the package.json file. Open it and look for main. The main is an entry point of the program/package. It mentioned index.js. So, let's open the index.js file.
If you open the index.js, you'll see that based on environment, they're requiring the react.production.min.js or react.development.js file. Open this react.development.js file from cjs folder.
In this file, do a search for useEffect. You will find a function with the same name.
But, I wouldn't recommended you to read the code in this way, if you're planning for React. You may try this solution. Also, if you're planning to read the source code as starting point, why not start with simple and easy to read packages? And don't forget that if not all then most of the packages are there on GitHub and on NPM website, you'll see the link for the Repository.
I was recently using a react pakage and importing like so:
import ReactRegionSelect from 'react-region-select';
Now how does react know in my case where to import react-region-select from ?
I.E. if i were building the plugin react-region-select, which can be found HERE.
do i need to build it in a way that webpack or guld or node knows where to pick it from , considering it will be in node_modules ?
or is it just because in my package.json file i have the property name: 'react-region-select', that webpack, gulp or node knows where to pick it from ?
It checks node_modules folder by default.
You would need to publish to npm to use it in another project remotely.
Yes, using the name. NPM uses the published name to download the module under the same name when resolving dependancies.
https://webpack.js.org/concepts/module-resolution/#module-paths
https://webpack.js.org/configuration/resolve/#resolvemodules
I have a package which is published to npm and we are successfully using the package in our angular2 applications by defining the dependency in package.json as
"dependencies": {
"somesharedmodule": "^1.0.21",
}
and in our components as import {SharedService} from 'somesharedmodule'.
Now we dont want to make the library public(not interested to make private library too).My question is - i have a module in some folder of my local system.Can i use this module in my application without making the package published in npm. can somebody please guide me the alternatives to use a module in my application without publishing it?
Not clear what exactly you want to do... Bu there are lots of options:
npm link https://docs.npmjs.com/cli/link
use github private repo:
"dependencies": {
"ng2-resource": "https://github.com/{nickName}/{repoName}.git"
}
link your IDE to use local folder as node_modules
manually copy/paste library into project's node_modules
I want to build a web client using react.js and semantic ui. There is a node package to use semantic-ui with react.js; semantic ui react. I have already installed this package on my computer following the instructions on react.semantic-ui.com/usage, but upon testing the with a simple webpage.
I think I have this issue because I failed to use this last instruction:
import '.../semantic/dist/semantic.min.css';. The semantic folder has been generated in my project main folder, but the dist folder and the semantic.min.css have not been generated yet. Where and how should I use this?
NB: I also tried adding this <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.2/semantic.min.css"></link> to my index.html page and the page was style as expected. I don't want to use this option as I cannot change the them with it.
First - install css npm install semantic-ui-css --save
Then - import in at the index.js page (the very top level)
import 'semantic-ui-css/semantic.min.css';
First, use one of below package managers to install semantic UI react package.
For npm users:
npm install semantic-ui-react
For yarn users:
yarn add semantic-ui-react
Then add this import line to your index.js
import 'semantic-ui-css/semantic.min.css'
That's all.
For npm user:
npm i semantic-ui-react semantic-ui-css
semantic-ui-css is a package dependency of Semantic-ui-react (SUIR) and is the css only distribution with a unique theme. Semantic-ui is written in Less and provides a larger and finer control (per component) over the production of the final stylesheet (dist/semantic.min.css).
It delivers several themes easy to derive to create your own, and a proper picture about how to keep a big and complex css well organized and not invasive with less.
in node v12, the installation of sui-css may fail,
complaining that ReferenceError: primordials is not defined. See
https://stackoverflow.com/a/58394828/1874016.
You can also
git clone https://github.com/semantic-org/semantic-ui
apply the patch above in here.
and yarn install
Note the default semantic.min.css size is 628Kb and you probably don't need the styling for all the components it has.
npm install sematic-ui-react sematic-ui-css --save
In your root file probably src/index.js add
import 'semantic-ui-css/semantic.min.css';
Some common layouts can be found [here ]:(https://semantic-ui.com/usage/layout.html)
I need to parse the response HTML in my custom api, so I tried to use cheerio module. Although, I'm getting the error:
Cannot find module 'cheerio'
What do I have to do to add other npm modules?
To install additional Node modules you'll need to first turn on Script Source Control for your mobile service (go to the Dashboard and look on the right side under "Quick Glance"). Once you've done that, you can clone the repository your scripts are in locally and then install Node modules and push your changes back to your Mobile Service. You can do this by editing the package.json file or using npm install with the --save parameter to edit the json file for you. For more information, check out this post: http://blogs.msdn.com/b/azuremobile/archive/2014/01/20/support-for-package-json-in-azure-mobile-services.aspx.