Using angular-ui-tinymce with JSPM - unable to load templates and plugins - jspm

I have the same problem that has already been documented on GitHub here. ui-tinymce references a number of dependencies which cannot be reached in my application.
GET http://localhost:8080/jspm_packages/github/tinymce/tinymce-dist#4.3.12/themes/modern/theme.min.js # angular.js:6084
tinymce.js:9426 Failed to load: /jspm_packages/github/tinymce/tinymce-dist#4.3.12/themes/modern/theme.min.js
I am able to use the workaround suggested in the github issue above, which changes the baseURL. This works fine in my development environment. However, when I run jspm bundle-sfx it does not pick up these dependencies and I am left in the same situation without templates or plugins.
What is the best way to address this? Can angular-ui-tinymce be broken down so that the dependent files are available in separate packages? Or should I just use gulp to get around this problem?

I tried using Gulp to concatenate the missing files, however this will not work because by default tinymce still expects the files to be at the relative locations which it uses in its own internal file structure.
I still think it would be helpful for Tinymce to provide separate packages for the most common themes, however I admit that there are a lot of themes and plugins so this would be a fair amount of work.
In the end the simplest thing to was to copy the theme and plugin files into the "correct" relative directories within my own source code. This way I can change the relative baseURL for tinymce and it will be correct when I run it in production as well as development environments.
This way I can run jspm bundle-sfx and it will bundle these files along with everything else. However you may have to import the files explicitly if you do not serve the area statically in your application. For example:
import 'sysadmin/app/tinymce/themes/modern/theme';

Related

How to deal with node_modules in PhpStorm

I have been setting up my development environment for my Laravel/AngularJS project. My IDE is JetBrains PhpStorm. I am wondering what are the best practices for configuring the IDE to deal with the node_modules (or bower_components or vendor for my PHP) folder, so that:
It is not included in the code inspection as far as the modules' internal code is concerned.
It is included in the code inspection as far as references in my own code to the modules is concerned.
It is included in Autocomplete or Code Navigation (Ctrl+click on methods)
To make it more clear: I want to be able to Ctrl+click on methods of my node modules and be redirected to the source code of these modules. I also want to be warned if I write a node module method wrong, or if it does not exist. Also autocomplete a method, when I press Ctrl+Space. But I don't want the internal code of my node modules to be included in code inspection, because it takes a lot of time to inspect all the modules, and they are supposed to be ok, so I don't need to inspect them.
I already tried two solutions:
Marking the folders as excluded: This does not work because the folders are totally excluded from the project and redirection and inspection does not work at all
Creating a specific Scope (in PhpStorm Settings), that includes all files except the node_modules folder, to use when I manually run Code Inspection: It is impossible to exclude the node_modules folder, because my IDE recognizes it as a module "I think" (it has [webapp] next to it in the Project explorer). I could however exclude bower_components and vendor.
Regardless my tries, what is the best way to deal with it?
As it's mentioned in help, PhpStorm auto-excludes node_modules folder from indexing for better performance, adding the direct dependencies listed in package.json to javascript libraries for completion, etc. So the best way to handle node_modules is relying on the IDE default procedures

Project too large

I'm just starting to learn Angular, I installed in my Ubuntu Linux:
Angular CLI: 7.1.4. and
Node: 10.14.2.
My question is, why one project is too large? I mean a simple "helloworld" is 334MB, I don't know why, Is it possible resize it? or delete any folder that is unnecessary? Or Is there something wrong with my installation? (how can I detect that?)
The bigger folder is node_modules, and when I create my projects, generates a lot of folders.
I was reading about "angular lazy loading", but I'm new.. It is not totally clear for me.
this is the folder spaces:
Please... I hope somebody can help me...
best regards
You might be using big bundles which are not needed, so you can break them up:
https://medium.com/#julienetienne/javascript-bundles-are-too-big-break-up-the-libraries-3be87d5ef487
In modern JavaScript, projects require modules that themselves require modules that require modules... resulting in node_modules directory with hundreds of dependencies. A 100Kb library might be included because someone needed one function from it. JavaScript is not compiled, so all that source tends to be rather big. This is an unfortunate, but unavoidable truth; your Angular project directories will be big, and there's nothing you can do about it. It is perfectly normal.
The good part: modern JavaScript deployment typically includes packing up those libraries with Webpack or Parcel or similar code bundlers. Most of them implement "tree shaking", which analyses the code to find only the functions that are potentially utilised starting from the entry point, and only bundle those, ignoring the rest. This means that 100Kb library whose one function is used is transformed into just that one function in the final distribution bundle.
Not all of the bundlers are equally good at it at this point. For example, Webpack cannot tree-shake the CommonJS modules, only ES6 ones.
You can remove node_modules folder when you are not going to use the app.
And, when you need work on the application, you can re-generate node_modules using the command: npm install
Those are just node-modules, they are needed for building the project, but not necessarily everything inside of them will be deployed to production. As Amadan said, there is a process of tree-shaking (filtering only used modules) and also in production you use the minified version of the same JS code (where for example whitespace is missing and variable-names are shortened), among other optimizations. A production-optimized Angular project should not be more than a 100KB for a hello-world application.
In the provided image I see packages like
selenium-webdriver
protractor
Those belong to dev-dependencies (see your package.json file) because they are used for testing. When building for production, no code from dev-dependencies should be included. The typescript package (which is nr.2 in size in your screenshot) will also not be present in production because types like string are only used for writing Typescript code, but the browser receives Javascript, which it is compiled to.

Getting the path of a node module in a view

I'm a beginner using NodeJS. I'm using a plugin for video-js called videojs-playlist. The docs say to include it like this:
<script src="path/to/video.js/dist/video.js"></script>
<script src="path/to/videojs-playlist/dist/videojs-playlist.js"></script>
What exactly is the path/to supposed to be if not root/node_modules or something like that? How am I supposed to access those files from an ejs view? I have installed both video-js and videojs-playlist using npm.
Right now I get redirect errors on my page because it's not finding the file from the paths I've tried.
If the path doesn't have a / at the beginning, then the path is relative to the file the <script> tag is in; otherwise, it is relative to the site root -- which may mean different things depending on if/how you are bundling/deploying your javascript.
For a simple case, if you have the script tags in an index.html, and you copied video.js to the same directory as index.html, you would reference by:
<script src="video.js">
If you are using Node to test things out on your personal machine, you could reference a file relative to your HTML file and node_modules directory; however, this wouldn't really be the best in the context of deploying and managing a real application.
Node gives you require() to import modules from dependencies you've installed without needing to specify their exact location and directory structure, but it looks like this particular plugin may not have given you that convenience here.
It looks like you are in need of a bundler. One widely-used and well-documented bundler is webpack, but there are others such as parcel and FuseBox. These can all serve your needs.
These tools are most likely what the videojs-playlist README on GitHub is referring to when they say:
Include videojs-playlist on your website using the tool(s) of your choice.
Among other features, these tools can take a file from one of your node_modules dependencies, and "bundle" relative your javascript application (however you desire), so that you don't have to carry around some pre-installed giant node_modules directory everywhere with you -- you only take what you need with you and structure it the way you want.

How to use Faker.js in NPM-based browser project?

I use npm as a package manager for my web frontend projects. I have a need to generate some fake data locally within JavaScript in a project. Faker.js seems to be the perfect library to do so.
Most libraries, when I install them with npm, either have usable js files at the root of the installed files or provide a dist or similar folder with the .js files that I can reference, e.g. <script src="node_modules/angular/angular.min.js"></script> Faker.js however does not include this.
The documentation for faker simply includes this line: <script src = "faker.js" type = "text/javascript"></script> Clearly this will not work since the package doesn't even install a file called faker.js anywhere. My assumption is that you're expected to either use it with Node.js (non web frontend) projects or you're expected to build it somehow to get the faker.js file.
One tutorial I found online says you can npm install faker and then use <script src="node_modules/faker/build/build/faker.js">. But I also do not have a build folder. The tutorial didn't give any instructions on building the faker.js file.
Can someone shed some light on how this works? I have actually seen at least one other package (jQuery) that is similar and does not include a compiled usable browser version in the distribution. In past projects I've simply downloaded a compiled .js file and included it in my source control, but I'd like to try to avoid that if at all possible!
(Please don't answer with "just use a CDN" - I am working in an environment with specific policy requirements that HTML on the production server may not directly reference any off-site assets or scripts, but it is OK to pull in those libraries and self-host them. Frustrating, yes, but I don't get to make the rules.)

Moodle Atto 'plugin not found'

I've been trying to use the Atto plugin template (https://github.com/justinhunt/moodle-atto_newtemplate) to try and create my own Atto plugin. I've made the changes outlined in the README, and got shifter to run via npm. It appears to generate the build folder that matches the other plugins.
I'm able to see the plugin in configuration, and it's showing up in the Atto Toolbar Settings, but, when I pop open a text editor, I don't get an icon, and the console logs moodle-editor_atto-editor: Plugin 'testplugin' could not be found - skipping initialisation
I've found a few references in the docs that shifter is no longer used, and grunt is the new way to go, but I can't find any actual docs on this, and no gruntfile seems to exist anywhere.
Has anyone come across this before? What am I missing?
You will need to run shifter on your YUI code for it to work - the usual way of doing that, for Moodle 2.9 and above is to use grunt - see https://docs.moodle.org/dev/Grunt for more details.
Not sure if this was ever resolved. The template is really helpful and it also comes with lib, db, and version PHP scripts. The string that you use as the plugin name has to be consistent throughout these scripts, as well as in your JS file. By default, it is set to atto_NEWTEMPLATE. Did you perhaps change this string to atto_testplugin in one place but not in all the others?

Resources