Aurelia javascript dependencies loading time [duplicate] - aurelia

I wrote a minimal test page to try out Aurelia.
http://www.andrewgolightly.com/
GitHub: https://github.com/magician11/ag-landingpage
My last test, showed it took 55 seconds to load the page with 135 requests.
It seems I need to bundle the jspm_packages directory first so that the 543KB gets downloaded at once.. and not in pieces.
So given I followed this example: http://aurelia.io/get-started.html
How do I bundle the packages? It's not clear to me from https://github.com/jspm/jspm-cli/wiki/Production-Workflows
And then what do I update in my index.html file? And I'll still need to include the jspm_packages folder as I reference it in the head, right?
<link rel="stylesheet" href="jspm_packages/github/twbs/bootstrap#3.3.2/css/bootstrap.min.css">
<link rel="stylesheet" href="jspm_packages/npm/font-awesome#4.3.0/css/font-awesome.min.css">
Thanks.
Update
The team is working on bundling..
From Rob Eisenberg: "We aren’t finished with our bundling support just yet. We’re working on it."

This question was posted at a very early time but we do have a strategy now in place that works with jspm and system.js loader for bundling. As a note it's not that the framework is slow it's that the loading of assets was taking a while early on due to the high number of requests (and that you probably didn't have gzip enabled)
I've copied this from my blog post on the subject - http://patrickwalters.net/my-best-practices-for-aurelia-bundling-and-minification/
Requirements
Understand that a jspm bundle command is used to let system.js, our module loader, know to load the bundle
Understand this only covers the JavaScript files (for now)
Create a new bundle
Open your terminal and navigate to your skeleton-navigation folder.
Open your config.js in your text editor
Run this command -
jspm bundle '*' + aurelia-skeleton-navigation/* + aurelia-bootstrapper + aurelia-http-client + aurelia-dependency-injection + aurelia-router dist/app-bundle.js --inject --minify
Breakdown
// Create a bundle
jspm bundle
// Bundle all of these paths
// from my config.js
'*' +
aurelia-skeleton-navigation/* +
aurelia-bootstrapper +
aurelia-http-client +
aurelia-dependency-injection +
aurelia-router
// Create the bundle here
// with this name
dist/app-bundle.js
// These modifiers tell the bundle
// to both minify and then inject
// the bundle
--inject
--minify
Additional notes on bundling
If you are serving in production you may want to look at setting baseUrl in your config.js like that
To unbundle and serve files individually use jspm unbundle
Since we used the --inject modifier system.js should pick up on our bundle and serve it without changing our script path in index.html
You can add more files by using + {filename} in the bundle area

2016 Update
The official toolkit for bundling aurelia applications can be installed via npm using npm install --save-dev aurelia-bundler.
Once installed, you can set up a gulp task for handling the bundle / unbundle process. A basic example of a task looks like this:
build/tasks/bundle.js
var gulp = require('gulp');
var bundler = require('aurelia-bundler');
var config = {
bundles: {
'dist/app-build': {
includes: [
'**/*.js'
],
options: {
minify: true
}
}
}
};
gulp.task('bundle', ['build', 'unbundle'], function() {
return bundler.bundle(config);
});
gulp.task('unbundle', function() {
return bundler.unbundle(config);
});
I've written a more in-depth article here: http://www.foursails.co/blog/aurelia-bundling/
The official documentation can be found here: https://github.com/aurelia/bundler

There is a GitHub repository that includes an r.js bundling strategy for the Aurelia AMD target build, as well as sample projects for using the bundle in Visual Studio with TypeScript (including an aurelia.d.ts TypeScript type definition file).
repo
bundling with r.js
aurelia.d.ts
using this strategy should dramatically reduce your load time as it will be loading one file instead of many files.

Related

Why when upgrading to Node.js 16.13.0 (with its nmp 8) I can't stop sass error output?

As a result of upgrading to Node.js 16.13.0 with its nmp 8 I ran into a problem with Sass. I had to update gulp-sass to version 5.0.0, additionally install sass#1.43.4 and fix in gulpfile.js the sass require as sass = require('gulp-sass')(require('sass')).
So Sass got finally up and running with Node.js 16 and its nmp 8, but I ran into the problem of Breaking Change: Slash as Division.
https://sass-lang.com/documentation/breaking-changes/slash-div
I get Deprecation Warnings like:
Deprecation Warning: Using / for division is deprecated and will be removed in Dart Sass 2.0.0.
Recommendation: math.div(20em, 16)
More info and automated migrator: https://sass-lang.com/d/slash-div
╷
12 │ $fa-fw-width: (20em / 16);
│ ^^^^^^^^^
╵
node_modules\#fortawesome\fontawesome-free\scss\_variables.scss 12:25 #import
node_modules\#fortawesome\fontawesome-free\scss\fontawesome.scss 5:9 #import
assets\src\style\_variables.scss 6:9 #import
assets\src\style\main.scss 27:9 root stylesheet
Everything works, but the error output in the npm console annoys me a bit. How to fix it?
In my gulpfile.js, I use gulp-plumber#1.2.1. It prevents pipe breaking caused by errors from all gulp plugins.
plumber = require('gulp-plumber');
I have the function to build css:
// style build
function css_build () {
return gulp.src(path.src.style) // pass the string or the array of values pointed above if we want to pass several ones
// .pipe(cached('css_building'))
.pipe(plumber()) // gulp plugins bug tracking
.pipe(gulpif(devMode, sourcemaps.init())) // initialize source maps
.pipe(sass()) // scss -> css
.pipe(autoprefixer({ // add vendor prefixes to CSS
overrideBrowserslist: ['last 2 versions'], // last two versions recommended by plugin developers
cascade: false
}))
.pipe(gulp.dest(path.build.css)) // deploy temporary css
.pipe(rename({ suffix: '.min' })) // add prefixes to the deployed file
.pipe(cleanCSS({level: {1: {specialComments: 0}}})) // minify CSS and disable even special comments
.pipe(gulpif(devMode, sourcemaps.write('./'))) // write source maps
.pipe(gulp.dest(path.build.css)) // deploy final css
.pipe(browserSync.reload({ stream: true })); // browser-sync reload
}
And as a result of executing this task that kind of errors occur mentioned above.
So the question is how can I stop outputing these errors?
I'm not really going to rewrite third-party css libraries myself for it and use div() instead of / there :)
There is a super solution for solving this Deprecation Warning problem.
First uninstall nodejs from your projec & after use below command,
nmp i --legacy-peer-deps
That will be solve your problem.

How can I reduce the webpack bundle size for a Vue.js / Nuxt.js project incorporating AWS SDK?

Summary:
I have created projects, with Vue.js and Nuxt.js, where I have installed aws-amplify (which automatically installs aws-sdk) in order that I can implement authentication with AWS Cognito.
In both cases, this works very nicely, but the problems come when I build production versions.
In both cases, I end up with massive bundle sizes which (thanks to webpack-bundle-analyzer) I can immediately see are caused by the aws-sdk which appears to contain code to implement every AWS service, under the sun, despite the fact that I am only importing AWS Cognito's: "Auth" (import { Auth } from 'aws-amplify')
I have tried creating a custom AWS SDK for JavaScript, which only includes the service: AWS.CognitoIdentity, but despite incorporating that (presumably incorrectly), I still end up with the same bundle size (and aws-sdk files) when I build the projects.
As I say, this is happening in both Nuxt and Vue project, but in order to simplify this, I for now just want to find the solution to a very basic sample project created with Vue.
I think I must be doing something dumb, but I can't work out what that is.
Any help would be greatly appreciated! :-)
Steps to reproduce:
Create a basic Vue.js project with defaults. Run: vue create vue-aws-sdk-inv
[Note: Steps 2 - 4, are not crucial to reproduce issue, but install webpack-bundle-analyzer which provides useful extra info.]
In the new project, install webpack-bundle-analyzer. Run: npm install --save-dev webpack-bundle-analyzer
Create root file: vue.config.js
Add the following code to vue.config.js:
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
module.exports = {
configureWebpack: {
plugins: [new BundleAnalyzerPlugin()]
}
};
As a benchmark, build the project. Run: npm run build
At this stage, the project will build (with no console warnings) and webpack-bundle-analyzer will launch (in the browser) showing the file: chunk-vendors..js, at the top of the tree, containing a bunch of other .js files, all of acceptable size.
Install AWS Amplify (and by default aws-sdk). Run: npm i aws-amplify
Open src/components/HelloWorld.vue and add the following under the tag: import { Auth } from "aws-amplify";
Build the project. Run: npm run build
At this stage, the project will build WITH console warnings regarding the following files being too large:
File Size Gzipped
dist/js/chunk-vendors.013ac3f0.js 3055.78 KiB 550.49 KiB
dist/js/app.fa2a21c4.js 4.67 KiB 1.67 KiB
dist/css/app.53019c4c.css 0.33 KiB 0.23 KiB
If installed, webpack-bundle-analyzer should launch (in the browser) showing an inflated: chunk-vendors..js, due to a hefty: aws-sdk.
aws-sdk will include api: .json files and lib: .js files for every AWS service I can think of!
The attempt to rectify:
Navigate to: https://sdk.amazonaws.com/builder/js/
Clear all services.
Select just: AWS.CognitoIdentity
Download "Minified" aws-sdk-.js
Download "Default" aws-sdk-.min.js
[Note: the following are the steps I am guessing I'm getting wrong?...]
In the project, search the node_modules directory for aws-sdk.js and aws-sdk.min.js.
They were found in /node_modules/aws-sdk/dist
Replace both files with the downloaded files (renaming to aws-sdk.js and aws-sdk.min.js respectively.)
Build the project. Run: npm run build
Project will build with same console warnings and same massive aws-sdk, as before, containing all the same .js and .json files for a bunch of services that are not actually imported in the application.
Final pieces of analysis:
Remove aws-sdk.js and aws-sdk.min.js from project's: /node_modules/aws-sdk/dist
Build the project. Run: npm run build
Project is built without even referencing these files.
Rename /node_modules/aws-sdk to /node_modules/TEMP_aws-sdk and attempt to build the project.
Build fails, and this proves (I think) that I was at least trying to add the custom versions, of aws-sdk.js and aws-sdk.min.js, somewhere in the correct directory!
Source Code:
vue.config.js:
const BundleAnalyzerPlugin = require("webpack-bundle-analyzer")
.BundleAnalyzerPlugin;
module.exports = {
configureWebpack: {
plugins: [new BundleAnalyzerPlugin()]
}
};
src/components/HelloWorld.vue:
import { Auth } from "aws-amplify";
As said before, any help would be greatly appreciated! :-)
It looks like import { Auth } from "aws-amplify"; doesn't currently allow for tree shaking according to this issue.
Reading through several related issues, it appears that:
import Auth from '#aws-amplify/auth';
is the best you can currently do. I suspect that over time, the AWS team will figure out a way to better separate the internals.
For readers looking for a way to reduce bundle sizes for the aws-sdk package, see this section of the docs.
In my case:
import S3 from 'aws-sdk/clients/s3';
import AWS from 'aws-sdk/global';
cut the bundle size down by quite a lot. That gets it down to ~57k gz to use S3.
Also, for anyone using nuxt you can just run nuxt build -a to get the build analyzer.

process.env.NODE_ENV is not working with webpack3 [duplicate]

I've got an existing code base in which Vue.js has performance problems. I also see this notice in the browser console:
so I guess an easy fix could be to put Vue into production mode.
In the suggested link I try to follow the instructions for webpack. We're on Webpack version 2.7 (current stable version is 4.20). In the instructions it says that in Webpack 3 and earlier, you’ll need to use DefinePlugin:
var webpack = require('webpack')
module.exports = {
// ...
plugins: [
// ...
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
}
So in my package.json I've got a build script defined:
To build for production I run yarn run build and it runs a build.js file (paste here) which in turn calls webpack.base.conf.js (paste here) and webpack.prod.conf.js (paste here).
As you can see in the paste I use the DefinePlugin as suggested by the docs.
I also found a file called vue-loader.conf.js (paste here) and to be sure I also added the DefinePlugin in there as well.
I can run yarn run build which ends without errors, but when serve the site over Apache and open the browser it still shows the notification that we're in development mode.
To be sure it actually uses the files created by webpack I completely removed the folder /public/webpack/ and checked that the webinterface didn't load correctly without the missing files and then built again to see if it loaded correctly after the command finished. So it does actually use the files built by this webpack process. But Vue is actually not created in production mode.
What am I doing wrong here?
The problem may be in your 'webpack.base.conf.js' as i suspected, thank you for sharing it, upon searching i've found an issue resolving your 'production not being detected' problem on github here
The solution requires that you change 'vue$': 'vue/dist/vue' to 'vue$': vue/dist/vue.min in production.
You will find the original answer as:
#ozee31 This alias 'vue$': 'vue/dist/vue' cause the problem, use vue/dist/vue.min in production environment.

How to do live reloading / automatic page refresh in elm?

I'm trying to learn elm programing language from here. And it bugs me to manually do page refresh with every little change.
I see that elm-reactor doesn't support live realoading anymore. But what can i do unthil the next release?
I usually use elm-live.
It is very simple and easy to use if you are just compiling Elm to js.
Solved! - gulp magic saves the day!
(this solution works only with Chrome) Here is what I did - based on this: ( Thanks janiczek !! :))
Inside your root directory add a new file named gulpfile.js
Paste this content inside:
gulpfile.js:
evar gulp = require('gulp');
var elm = require('gulp-elm');
var concat = require('gulp-concat');
var plumber = require('gulp-plumber');
var livereload = require('gulp-livereload');
var path = ['*.elm']; // here you adjust the path according with your needs.
// For ex: 'scr/**/*.elm' - maps to every folder and file nested inside the src folder.
gulp.task('elm-init', elm.init);
gulp.task('elm', ['elm-init'], function(){
return gulp.src(path)
.pipe(plumber())
.pipe(elm())
.pipe(concat('elmapp.compiled.js'))
.pipe(gulp.dest('js'))
.pipe(livereload());
});
gulp.task('default',['watch']);
gulp.task('watch', function(){
livereload.listen();
gulp.watch(path,['elm']);
});
You must have gulp installed globally if not run:
npm install gulp -g
Install the gulp dependencies:
npm install gulp-elm gulp-concat gulp-plumber gulp-livereload
Install this extension: (chrome only)
run elm-reactor and open your page in Chrome.
From inside your terminal, at root directory (or wherever your gulpfile.js is) run: gulp
With the elm page tab open, Press LiveReload button on the Chorme Extension. like below and make sure it says:
You are good to go! :)
Elm compiler doesn't like .js files around, so you will still see 2 errors. Ignore them. For me , everything else works as expected.

Why does the alpha version of Aurelia load slowly?

I wrote a minimal test page to try out Aurelia.
http://www.andrewgolightly.com/
GitHub: https://github.com/magician11/ag-landingpage
My last test, showed it took 55 seconds to load the page with 135 requests.
It seems I need to bundle the jspm_packages directory first so that the 543KB gets downloaded at once.. and not in pieces.
So given I followed this example: http://aurelia.io/get-started.html
How do I bundle the packages? It's not clear to me from https://github.com/jspm/jspm-cli/wiki/Production-Workflows
And then what do I update in my index.html file? And I'll still need to include the jspm_packages folder as I reference it in the head, right?
<link rel="stylesheet" href="jspm_packages/github/twbs/bootstrap#3.3.2/css/bootstrap.min.css">
<link rel="stylesheet" href="jspm_packages/npm/font-awesome#4.3.0/css/font-awesome.min.css">
Thanks.
Update
The team is working on bundling..
From Rob Eisenberg: "We aren’t finished with our bundling support just yet. We’re working on it."
This question was posted at a very early time but we do have a strategy now in place that works with jspm and system.js loader for bundling. As a note it's not that the framework is slow it's that the loading of assets was taking a while early on due to the high number of requests (and that you probably didn't have gzip enabled)
I've copied this from my blog post on the subject - http://patrickwalters.net/my-best-practices-for-aurelia-bundling-and-minification/
Requirements
Understand that a jspm bundle command is used to let system.js, our module loader, know to load the bundle
Understand this only covers the JavaScript files (for now)
Create a new bundle
Open your terminal and navigate to your skeleton-navigation folder.
Open your config.js in your text editor
Run this command -
jspm bundle '*' + aurelia-skeleton-navigation/* + aurelia-bootstrapper + aurelia-http-client + aurelia-dependency-injection + aurelia-router dist/app-bundle.js --inject --minify
Breakdown
// Create a bundle
jspm bundle
// Bundle all of these paths
// from my config.js
'*' +
aurelia-skeleton-navigation/* +
aurelia-bootstrapper +
aurelia-http-client +
aurelia-dependency-injection +
aurelia-router
// Create the bundle here
// with this name
dist/app-bundle.js
// These modifiers tell the bundle
// to both minify and then inject
// the bundle
--inject
--minify
Additional notes on bundling
If you are serving in production you may want to look at setting baseUrl in your config.js like that
To unbundle and serve files individually use jspm unbundle
Since we used the --inject modifier system.js should pick up on our bundle and serve it without changing our script path in index.html
You can add more files by using + {filename} in the bundle area
2016 Update
The official toolkit for bundling aurelia applications can be installed via npm using npm install --save-dev aurelia-bundler.
Once installed, you can set up a gulp task for handling the bundle / unbundle process. A basic example of a task looks like this:
build/tasks/bundle.js
var gulp = require('gulp');
var bundler = require('aurelia-bundler');
var config = {
bundles: {
'dist/app-build': {
includes: [
'**/*.js'
],
options: {
minify: true
}
}
}
};
gulp.task('bundle', ['build', 'unbundle'], function() {
return bundler.bundle(config);
});
gulp.task('unbundle', function() {
return bundler.unbundle(config);
});
I've written a more in-depth article here: http://www.foursails.co/blog/aurelia-bundling/
The official documentation can be found here: https://github.com/aurelia/bundler
There is a GitHub repository that includes an r.js bundling strategy for the Aurelia AMD target build, as well as sample projects for using the bundle in Visual Studio with TypeScript (including an aurelia.d.ts TypeScript type definition file).
repo
bundling with r.js
aurelia.d.ts
using this strategy should dramatically reduce your load time as it will be loading one file instead of many files.