bundleconfig.json configured, but bundles not being created in ASP.NET Core 3.1 - asp.net-mvc-3

Using the Bundle and minify static assets in ASP.NET Core page as a guide, I've created a bundleconfig.json in my project root and set it up to create the css and script bundles I want to create. The page seems to imply that while 3rd party tools like Gulp or Grunt can be used, they are not required for basic purposes and I should be able to "Build the application" and then find the bundled .min files created, but they are not there after I build. I tried simplifying my config to just bundle two CSS files together but it still doesn't create the output file. Here are my bundleconfig.json contents:
[
{
"outputFileName": "wwwroot/css/tlgsso.min.css",
"inputFiles": [
"wwwroot/css/application.css",
"wwwroot/css/site.css"
]
}
]
I have been assuming this is meant to work simply by having a file named "bundleconfig.json" in the root. As has frequently been the case, all I can find is information on ASP.NET Core 1-2.0. Am I missing something needed to trigger the bundling & minification?

I needed to install the BundlerMinifier.Core NuGet package. Then it worked.

Related

How to install node modules but commit only relevant styles

So, I am setting up a new site and my project's folder structure looks like this now.
foo.com/
index.php
assets/
css/
img/
js/
vendor/
I have added vendor/ for js/css libraries that I must install to keep them separate, since I want anyone who installs my project to install those in vendor from package.json - most libraries contain too many files 99% which I don't want to push to production.
Now once the project is finished, I would like to push the code to production with only the necessary js/css files.
This is where the problem comes. For example, if I install bulma css using:
yarn add bulma --modules-folder ./assets/vendor
It will dump all bulma-related files which are almost 70 into /vendor/bulma/ but I will only be needing one or two css files afterwards, since I will compiles the sass file to css as:
sass vendors/bulmna/style.scss assets/css/style.css
So my questions is: I am assuming this is how every developer does it and there are no documentations I can find that suggest how to do it. Is it safe to ignore the /vendor directory? What if I install vue, font-awesome, bootstrap .. how can I only fetch the files I need but not everything in /vendors folder?
Your question is actually quite broad - however, I'll try to list as much as possible.
Lets say you're building a project from scratch and needed to include vuejs, jquery, fontawesome but only need to include a couple of files.
The issue you're hitting here is module dependency with respect to npm modules. (and there are many different tools that you can use to manage versions on your library dependencies as well as ensuring they are included into your project, i.e. package managers).
Ok - now from here, you may say to yourself
but I only need say, one icon from fontawesome in your final build (dist) and I don't want to commit all my modules into source control
Again, this is where you omit node_modules and other dependent libraries from source control (i.e. include node_modules your .gitignore)
To reiterate
You can install the required library,
add node_modules to .gitignore ,
bundle those libraries into a vendor single file to be consumed by your users (can be via browserify/webpack/rollup/gulp/grunt/yarn etc).
generate bundle within npm script
Now you may ask further -
Why would I use any of those tools? - they're distracting me from simply copy/pasting vendor libaries into my source control.
Build tools were created to
streamline the developer pipeline so that you DONT have to copy/paste vendor libaries into a vendor folder.
ensures that all files are bundled to the client automatically
allows you to keep track/restrict library version updates/ when required via package.json
allows you to add other build steps (such as minification, md5hash versioning, compression, code splitting, asset management to name a few).
Now lets break down the original question here:
How to ensure other developers get everything they need when cloning the repository
how do I ensure I can provide only the necessary files to the end user (if I only use specific parts of vendor libaries?)
1. How to ensure developers get what they need
Again, to reiterate above, adding devDependancies and .gitignoring allows you to only add the necessary files to your project.
2. How can I ensure clients get what they need without bloating request files?
This is where build tools such as webpack, browserify, gulp, grunt, rollup, attempt to achieve. This is because with some libraries that exceed in file size of 200kb minified, you may need to separate these files into different client requests (and as such, not demand the user to request one large file, which was symtomatic of browserify projects).
The second technique you will need to be aware of, is with specific libraries, you can use import mdn link where you can require one function/class from a dependant library (which further reduces file size).
Another technique is using less import statements (which can extract less functions/styles similar to above, but this isn't currently supported in SCSS). for SCSS, you're basically left with copy/pasting the necessary styles into your base scss and that'll save you space as well.
EDIT
How to create a bundle from npm install libaries
From the comments you've mentioned above (about not wanting to include a tool into your workflow, there's no point outlining any one particular strategy - you can find answers/tutorials online about how to setup gulp/browserify/webpack for your particular needs).
However, As you are currently using yarn - I'll go into details about that.
Firstly, yarn is a package manager (like npm). All it does with the --modules-folder is install the package into the specified folder, that's all. So we don't really care about that (since it's doing the same thing as npm). (i.e. your vendor folder is the same as node_modules in many respects).
We could use
webpack
gulp
grunt
rollup
browserify
brunch
(All build tools that essentially allow you to bundle all those packages into a single entry point to be packaged to the client).
I won't go into how, because that is a process you can find online, and from the above comments, I can tell you don't particularly care either.
What you are looking for is a zero-config javascript build tool. (Extremely out of the scope of your original question, and i'll only answer that in a separate Q&A).
I'd try Googling on "tree shaking CSS" to see if that gives you something.
Maybe something like: https://github.com/jacobp100/es-css-modules
Rollup plugin may be useful. It works for js, with postcss, the link says it works with css also.
https://code.lengstorf.com/learn-rollup-css
Have a look at Pancake. It has been built specifically for the purpose of moving only those files out of the node_modules folder that you need. I wrote an article about it here: https://medium.com/dailyjs/npm-and-the-front-end-950c79fc22ce
(probably not an answer but a good tip)
PS: I am the author of both, the article and the tool so with clear bias :)

How to Make a precompiled build of Orchard CMS

I use Orchard CMS 1.10.1.
What is the best way to make a precompiled build of Orchard CMS?
All you need to do is open a command prompt, go to the root directory of your Orchard project and run the command build precompiled.
This command will build the entire Orchard solution and prepare all the files that you need to deploy to IIS. You will find those files in the build\Precompiled folder. This folder will contain only the binary files of your application and the configuration/manifest files (such as Module.txt, placement.info, etc). Those are the files you need to run your application in production. Specifically, there will be no source code files in the build\Precompiled directory.
Additionally the configuration files are tweaked for maximum performance. For example dynamic compilation and file monitoring is disabled. However, the view files are not precompiled and I'm not sure if that is even possible with Orchard.

Is it possible to reference typescript files in other projects without adding projects to the solution?

In large scale software, it's a good idea to break code into projects.
For example, have a framework project which contains all base classes in some project called Company.Framework and some other projects which uses those shared codes like Company.ProductA, Company.ProductB.
Is it possible to reference .ts files in other projects, for example just referencing its dll, not adding the project, so the framework project can be hidden from the business developers.
The question is how to reference .ts files in other projects without adding those projects to the solution. For example just by adding their dlls.
I'm sure you know this, but Typescript files (.TS) get compiled to Javascript files (.JS). Neither the Typescript files nor the generated Javascript files end up inside the DLL. The DLL contains server-side code only, and the Typescript/Javascript is client-side code.
So, trying to add a reference from your ProductA project to the DLL from the Framework project is not going to pull in any Typescript files that were in your Framework project.
As long as the final rendered HTML page includes the tags for both the generated Javascript from both ProjectA as well as Framework, then everything will work fine, even if the two projects have no connection between them. If what you're really after is Visual Studio Intellisense for the Framework classes while you're coding in Typescript in ProjectA, then you should do as #WedneyYuri and #DavidSherret suggested, which is to add the .d.ts file from your Framework project into your ProjectA project.
Managing Dependencies
The simplest solution is to use a package manager like bower:
On terminal: Create an empty folder and start an empty bower repository:
$ bower init
For each definition file use this command:
$ bower install [URL] --save-dev
Example for jQuery definition file:
$ bower install https://raw.githubusercontent.com/borisyankov/DefinitelyTyped/master/jquery/jquery.d.ts --save-dev
Thanks to the bower you can use any URL here. For more information visit the bower documentation.
Compilation
Create a file (name isn't important) definitions.d.ts in the same folder where you ran the command $ bower init.
For each installed definition file you must add manually a new line in this file:
example after adding jQuery and angularjs:
/// <reference path="jquery.d/index.ts" />
/// <reference path="angular.d/index.ts" />
Now, in your project you only need to include references to the definitions.d.ts file
Running the code
For the code to work you need the .js files. In development environment I use the bower to manage the dependencies in a separate folder and I manually add the .js files in html. In production use any tool to concatenate them.
TSD (TypeScript Definition manager for DefinitelyTyped)
In the near future the package manager will have option to install modules from anywhere. It's not ready, but it is a goal.
The goal of TSD future is to seamlessly support any TypeScript
definition files, from any source. By default, you should still be
able to search the definitely typed repository and install from there.
However, more focus will be trained onto support independent
definitions, specifically ones bundled with modules.
https://github.com/DefinitelyTyped/tsd/issues/150

Asset precompile missing standalone javascript / css

I have that sneaking feeling I'm missing something obvious:
I ran
RAILS_ENV=production bundle exec rake assets:precompile
to precompile my assets before pushing to Heroku. Looking in /public/assets shows that application.js and application.css manifests successfully compiled, but none of my standalone files precompiled:
admin.js.coffee
blog.js.coffee.erb
[ ... several more similarly named ... ]
twitter.js.coffee.erb
and
admin.css.less
home.css.less
public.css.less
are all missing from /public/assets.
I thought that Rails would precompile the application.js/.css files, plus anything else that doesn't end in js/css:
The default matcher for compiling files includes application.js,
application.css and all files that do not end in js or css:
[ /\w+\.(?!js|css).+/, /application.(css|js)$/ ]
from: http://guides.rubyonrails.org/asset_pipeline.html#precompiling-assets
I don't want to have to manually update config.assets.precompile every time an asset file name changes. Am I missing something that will make Rails precompile these assets?
Update
Based on #Richard Hulse's answer below, I tested it out by created a separate manifest file for a standalone asset (i.e. I renamed twitter.js.coffee.erb to twitter-include.js.coffee.erb and added twitter.js with a single //= require pulling in the renamed original). This seems to work.
There must be a cleaner way than this, and it seems to contradict the Rails guide quoted above. The guide says the only files that won't be compiled are .js or .css files not named application. What I'm see is only .js or .css being directly compiled (i.e. not via a manifest) - nothing else.
Two things:
If these files are included in your application manifests, then they are included in the site's application files.
There should be a line in both application manifests: require_tree, that will pick up all the assets automatically for your. Is that in these files?
Edit in reply to edit:
The way I would structure this is have two sets of manifests. The standard ones (application.css/.js) are for public. The admin set are for admin pages. Include all the stuff you want in admin.js/.css manifests and add those files to the precompile array:
config.assets.precompile += ['admin.js', 'admin.css']
This would allow you to share code between the two groups. For example you can include jquery in both, but jquery_ujs in admin only. In your admin section layout just include the admin manifests instead of the application manifests.
In practice you will then add new files to the application or admin manifests as you develop the site, and you won't have to change the precompile configuration.
Once you get to the point of adding lots of assets, an admin section and so on, it is expected that things will get more complex and that you have to be explicit about what is included in manifests and the order (as opposed to require_tree).

Best way to configure build directory structure for a windows application

I am writing a small application at the moment and am trying to organise my build output to be a little closer to the finished product. The application is made up of a number of different projects. There is a core library that contains most of the functionality, a GUI app and a command line app that both reference the Core Dll, and a number of Plugin Dlls that are loaded at runtime and implement different data sources, these all reference core.dll, these also may include some other third party dlls. There are also a number of peripheral files such as a readme. And finally the core.dll and the datasource plugins are unit tested.
I would like to configure my build so that everything is output into directories as I would expect it to be when installed. I want debug and release builds to be built into different directories but otherwise have the same directory structure. I only want tests to be built for debug builds, and want them to be runnable, but seperated (I guess all test dlls would get output into a seperate directory). Here is how I imagine the structure will be.
Code/
solutions etc here
Debug/
Project.Core.dll
Project.Gui.exe
Project.Cli.exe
readme.txt
lib/
ThirdParty1.dll
ThirdParty2.dll
DataSource/
DataSource1.dll
DataSource2.dll
Tests/
Project.Core.Tests.dll
DataSource1.Tests.dll
Release/
same as Debug but without tests.
Is there any way of getting a solution to build like this? I'm beginning to think it will be difficult to build the plugins and the app all from one solution, and probably not even wise, but as they will all be distributed together it would be nice. I am open to using Nant or another build tool if that will make it simpler.
It is possible. Just modify OutputPath tag manually in each .csproj in both Debug and Release file to something like this
<OutputPath>..\$(Configuration)\any_subdirs</OutputPath>
You can disable tests building for Release using Configuration manager.
Modifying each project every time you create a new one is annoying.
Here's the solution:
Locate the real vs project, it'll be somewhere under ("%programfiles(x86)%\Microsoft Visual Studio 10.0\Common7\IDE\ProjectTemplates*")
Copy it locally somewhere.
Extract it.
Edit the contents making changes that better suit your project layout style. Make sure you update the project name, the name is what you see when looking for the project in the new project dialogue box. It's xml tag is Name, you'll find it in the {something}.vstemplate file.
Compress the content again. (Note: the contents must NOT be in a sub folder, so /* and NOT /{somefolder}/*).
Place your custom project under ("%USERPROFILE%\Documents\Visual Studio 2010\Templates\ProjectTemplates*").
Add a new project is Visual Studio, selecting your custom one, and enjoy!

Resources