ASP.NET 5 Client Side Depdency Management - Bower - asp.net-mvc

I'm trying out the new ASP.NET 5 with MVC 6, and I'm using bower to manage all my client-side dependencies. Everything is working fine.
But I have a question: When I add a dependency (let's say jQuery). It adds both the /dist and /src along with bower configuration files to the /lib folder of wwwroot. How do I make it include just the compiled source for usage? (So I can reference it in my pages via /lib/jquery/jquery.js?

I have recently been playing in this space and following is something that I have tried:
Deleted the .bowerrrc file to enable installing in the default bower_components folder under the project folder rather than under wwwroor\lib as anything under wwwroot tends to get published.
Added "main-bower-files": "2.9.0" to package.json. This package gets all the files mentioned in the main property of each installed package's bower.json files.
Created a gulp task using the above package
gulp.task('copyMainFiles', function () {
return gulp.src(mainBowerFiles(), { base: 'bower_components' })
.pipe(gulp.dest('wwwroot/lib'));
});
Added a postrestore step to your application's project.json file
"scripts": {
"postrestore": "gulp copyMainFiles",
"prepublish": [ "npm install", "bower install", "gulp clean", "gulp min" ]
}
Updated my application's bower.json to copy files which are not listed in main (like some packages do not have min files as main files..ex: jQuery). The following settings are read by main-bower-files:
"overrides": {
"jquery": {
"main": [ "dist/jquery.js", "dist/jquery.min.js" ]
},
"hammer.js": {
"main": [ "hammer.js", "hammer.min.js" ]
},
"bootstrap": {
"main": [
"./dist/js/bootstrap.js",
"./dist/js/bootstrap.min.js",
"./dist/css/bootstrap.css",
"./dist/css/bootstrap.min.css"
]
}
}
Finally had to update the jquery-validation package to use 1.14.0 instead of 1.11.1 as the previous version does not dist folder and indeed no bower.json...

Related

electron-builder not including entire dependency in built version

Electron is giving me 'Error: Cannot find module './constructor/getOptions' when I open my executable. I tracked the error to a dependency I have which has the following file structure:
My issue is that in the built version of the program, the entire constructor folder is missing. The way I look at the built version is by using the command npx asar extract app.asar ./extracted to view the files. When I look at this dependency I only see index.js being listed there.
I have checked inside of the index.js to see if getOptions is being imported and it is. I have tried to import the file using relative and absolute path. I have also made sure that the dependency is not under devDependency as electron-builder ignores that. I'm not really sure what else to do. Does electron-builder have an option to go deeper into the file structure of a dependency?
Here is my package.json section for electron-builder:
"build": {
"productName": "MintAIO",
"appId": "aio.mint",
"win": {
"icon": "build/ic.png"
},
"mac": {
"target": "dmg",
"icon": "build/ic-mac.png"
}
}
For anyone who might come across this issue in the future, there is a bug with Asar where the directory name constructor is for some reason not included when being packaged. I'm not sure what other directory names this might cause this issue, but constructor is definitely one of them. To fix this, you can either rename that directory to something else, or specifically leave that one dependency unpacked using the asarUnpack option in the build config of electron.
you can try to include files on the build section for example
"build": {
"productName": "MintAIO",
"appId": "aio.mint",
"win": {
"icon": "build/ic.png"
},
"mac": {
"target": "dmg",
"icon": "build/ic-mac.png"
},
"files": [
"constructor/*"
]
}
I think this will do the trick ....

Electron-forge package generates an empty out folder

I am working on app with electron and electron-forge, this app is being built on a virtual machine with no internet connection, so I got electron binaries files, and set the electron_config_cache to the path where I located the new binaries as well as for cacheRoot for packagerConfig in the package.json file, the problem is that:
When I run yarn package (electron-forge package) I am getting Done with green check next to each step which had been called by yarn package .. but the out folder is empty, while it should has appName-win32-x64 folder which contains .exe.
so does anyone have an idea regarding this?
Be sure that your package.json has the correct settings, including the "main" attribute as well as build directories. It seems electron forge uses electron-packager as its packaging platform so:
Following these instructions:
From Electron forge,Electron forge - packager options, Electron-packager options
Without a forge.config.js file:
Add this to your package.json:
"config": {
"forge": {
"packagerConfig": {dir:"./path/to/your/dir"},
"makers": [
{
"name": "#electron-forge/maker-zip"
}
]
}
Or with a forge.config.js file:
In your package.json, make sure to have:
{
"name": "my-app",
"version": "0.0.1",
"config": {
"forge": "./forge.config.js"
}
}
In your forge.config.js:
{
packagerConfig: {dir:"./path/to/your/dir"},
electronRebuildConfig: { ... },
makers: [ ... ],
publishers: [ ... ],
plugins: [ ... ],
hooks: { ... },
buildIdentifier: 'my-build'
}
I think it is most probable that forge is just not pointed to the correct dir, add the dir setting shown above.
The problem was a virtual machine problem, nothing related to electron forge itself, the VM was not able to copy the content from the temp folder to the out folder, this can be solved by changing the temp folder

exclude files from build in electron via package.json

I am trying to build an electron app and during build creation exclude some files and folders.
I read similar topics and also bug thread on github but still cannot make it properly.
Final goal is to exclude all files with extension .py and folder named tests and all its subfolders.
However even simple example with one file with explicit name does not work. Can you please point me to my mistake?
Here is package.json
{
"name": "Build-Downloader",
"version": "0.1.0",
"main": "electron_main_win.js",
"scripts": {
"start": "electron ."
},
"dependencies": {
"axios": "^0.19.2",
"python-shell": "^1.0.8"
},
"build": {
"files": [
"!electron_backend.py"
]
}
}
and the command line I use to compile my package:
electron-packager ./ --platform=win32 --arch=x64 --electron-version=8.2.3 --out=electron_build --overwrite
Finally I found a solution on my own. I have already thrown a big stone to myself due to my stupidity :)
However I would like to share my knowledge in case somebody will need this info.
electron-packager supports only --ignore command line arguments with RegEx
Note: you may use as many ignores as you want
Note2: do not mix names electron-packager and electron-builder, builder supports package.json :)
So finally ultimate solution was:
electron-packager ./ --platform=win32 --arch=x64 --electron-version=8.2.3 --out=electron_build --overwrite --ignore="^.*\.py" --ignore="\/node_modules" --ignore="\/tests"

electron-forge how to specify a source directory for packaging?

I've rigged create-react-app with the electron-forge app and now I need to somehow specify the build folder produced from the CRA for the packaging. That folder should also be served.
Would such a thing be possible with electron-forge?
I understand are you asking how to tell electron-forge which directory to find your source files in for packaging the app.
If so, see: https://github.com/electron-userland/electron-packager/blob/master/docs/api.md
where it describes the options of the
"config": {
"forge": {
object in your package.json file
inside they there is this package config object:
"electronPackagerConfig": {
"dir": "./src",
where you can specify your source folder.
Also, BTW: there you can specify files/file-regexs to be ignored in packaging:
"ignore": [".idea", ".gitignore"]
electron-forge has no option to specify input folder (project's root folder will be used):
Specify ignore option to skip folders/files;
Use main key in
package.json to specify correct start script.
For example, package.json for vue project:
{
"name": "project",
"version": "1.0.0",
"main": "index.js",
...
"config": {
"forge": {
"packagerConfig": {
"ignore": [
"^/[.]vs$",
"^/public$",
"^/src$",
"^/[.]browserslistrc$",
"^/[.]editorconfig$",
"^/tsconfig[.]json$",
"[.](cmd|user|DotSettings|njsproj|sln)$"
]
},
...
}
},
...
}

Bower hangs after checkout step of Install command.

I'm a github enterprise user and I'm using bower to point an internal repository to manage dependencies.
I have set up a repo and included a bower.json file in the root directory. It looks like this:
{
"name": "Axis",
"main": "Axis.js",
"version": "0.0.0",
"authors": [
"Nick Randall"
],
"description": "Chart Axis",
"keywords": [
"d3",
"d3.chart",
"axis"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
],
"dependencies": {
"d3": "~3.4.6",
"d3.chart": "~0.2.0",
"lodash": "~2.4.1"
}
}
I'm trying to install the repo above as a dependency in a new project using "bower install Org/Axis" and the process hangs after the "Checkout" step. Am I doing something wrong or is this a bug?
My .bowerrc file looks like this:
{
"shorthand-resolver": "https://git.company.com/{{owner}}/{{package}}'.git"
}
and this is the response I get from the command line:
bower Axis#* not-cached https://git.company.com/Org/Axis.git#*
bower Axis#* resolve https://git.company.com/Org/Axis.git#*
bower Axis#* checkout v1.1.1
after that it just hangs there and never progresses.
About a year ago, there was an issue with bower hanging due to problems with the version of unzip. To see if your hanging may have the same cause you might try to install one of the dependencies individually. If an individual install doesn't hang you may have the same issue as before -- it occurred in the presence of certain combinations of node version and bower version. To try and load individually, consider for example:
bower install https://github.com/lodash/lodash.git
It turns out that this was a dumb mistake. I had my .bowerrc in the wrong location. Once I moved it to the root of my project, everything started working. I hope this helps somebody else!

Resources