My issue is JSPM / SystemJS manually inserting CSS dependencies (namely Angular Material's CSS) when I have a different pipeline for those (Gulp + SASS).
How can I tell JSPM to not import CSS files or interpret CSS dependencies in any way? I found only this discussion - https://github.com/jspm/jspm-cli/issues/791 - but it did not help me at all.
Seems that JSPM prefers local package overrides rather than turning off CSS features completely.
The culprit of my original issue is Angular Material's package.json, which contains the following JSPM configuration:
"shim": {
"angular-material": {
"deps": [ "./angular-material.css!" ]
}
}
So what really solved my issue was to override that configuration:
jspm install angular-material -o '{ shim: {} }'
Related
How can i import bootstrap.css,jquery and JavaScript in my angular components and how can convert html webpage to angular webpage
Style.css
// Globally declaration for styles
#import url("./assets/css/bootstrap.css");
You can install bootstrap using npm.
npm install bootstrap --save
and then set the path in angular.json file as
"styles": [
"src/styles.css",
"node_modules/bootstrap/dist/css/bootstrap.min.css",
]
This will do the work.
$ ionic cordova plugin add cordova-plugin-http
$ npm install --save #ionic-native/http
The implementation is:
constructor(private https: HTTP ) {
}
this.https.get('http://ionic.io', {}, {})
.then(data => {
this.httpData =data;
console.log(data.status);
})
.catch(error => {
console.log(error.status);
});
And I get this error:
[20:49:03] console.warn: Native: tried calling HTTP.get, but the HTTP plugin is not installed.
[20:49:03] console.warn: Install the HTTP plugin: 'ionic plugin add cordova-plugin-http'
If you do not want to modify the ionic-native plugin like suggested by #alpere or if the solution does not work you can always use the cordova plugin without ionic-native. To do so tell typescript that the http handle exists by adding the following somewhere below your imports:
declare var http;
And then use it like this:
http.get(
'https://ionic.io/',
{},
{},
response => {
console.log(response.status);
},
response => {
console.error(response.error);
},
);
Note that there is no need of this because cordova plugins are defined on a global scope. The downside of using plugins without the ionic-native wrapper is that you loose the nice type annotations, promise callbacks and in some cases you will have to trigger angular change-detection yourself.
The Ionic Native HTTP changed the cordova plugin they are using since the old one hasn't been updated for a while. During the change the reference to the plugin has't been updated so it's broken.
(See: https://github.com/silkimen/cordova-plugin-advanced-http/issues/8)
You can fix it by changing the old referenced plugin to new one:
(After the commit also updating the plugin will fix the issue)
in #ionic-native/plugins/http/index.ts:
change:
pluginRef: 'cordovaHTTP',
to:
pluginRef: 'cordova.plugin.http',
See commit:
https://github.com/ionic-team/ionic-native/commit/49ee0d85a304770a9a3bd3e04eb9609e6d565b67
It may be caused by any of these three issues:
The plugin is not installed;
You ran the code on a browser (or other limited environment); or
The platform is not ready (You called your code before the plugin was loaded).
The master branch of ionic already fixed pluginRef: 'cordova.plugin.http',
problem,
Still if the problem persists or you don't want to change the source files try these steps, it worked for me.
remove existing builds
rm -rf node_modules/ platforms/ plugins/ www/
update ionic native to latest build :
npm i --save ionic-native#latest
(please check with other plugin dependencies as well if its a problem try isolating packages via virtual environment setup - https://github.com/ekalinin/nodeenv ) :
add all your plugins required and http plugin ::
ionic cordova plugin add cordova-plugin-advanced-http
Then finally your plugins required and http plugin
npm install #ionic-native/http
Now your upon builds iOS or android should detect all the plugins
Ionic3 Cordova SSL pinning example
https://github.com/sijovijayan/SSL-pinning-with-ionic-cordova-example
In this example, you will get an idea about how implement SSL Pinning and How to Generate .cer file
try to run below command as suggested in error message to install HTTP plugin
ionic plugin add cordova-plugin-http
I would switch to Angular's HTTP instead of Cordova HTTP. Advantage: Does not require any plugin.
package.json:
"dependencies": {
...
"#angular/http": "4.1.3",
...
}
app.module.ts:
import { Http, HttpModule } from '#angular/http';
...
#NgModule({
declarations: [
MyApp,
],
imports: [
...
HttpModule,
...
]...
calling .ts-class:
import { Http } from '#angular/http';
...
constructor(... , public http: Http, ...) {
//Example: .get for a JSON and map it:
this.http.get(url).map(res => res.json()).subscribe(data => {
this.data = data;
});
}
Answer to first Comment:
As you seem to need SSL Pinning and I did not find an easy way in Angular HTTP yet, i saw that your command of adding the cordova plugin differs a little from the one from the documentation:
You wrote:
ionic cordova plugin add cordova-plugin-http
Now the command seems to be:
ionic cordova plugin add cordova-plugin-advanced-http
(https://ionicframework.com/docs/native/http/)
As you can see there, it supports your needs with methods like enableSSLPinning(enable).
If you are running the app from your pc, you might get such error.
Try using ionicdev
Ionic native plugins depend on the device features. So because of this plugins like http, contacts or camera would not work on your browser. An Example of such error is
Native: tried calling HTTP.post, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator
So try to get ionic's app for developing app here https://play.google.com/store/apps/details?id=io.ionic.devapp
I had the same problem. And I managed to get rid of that error simply by declaring the Angular's HTTP module.
In app/app.modules.ts
import { HttpClientModule } from '#angular/common/http';
#NgModule({
imports: [
// import HttpClientModule after BrowserModule.
HttpClientModule,
],
})
Even if I don't use Angular's Module, this solved my problem.
Have you ever try to call plugin after the platform ready then check platform?
async checkVersion() {
const ready = !!await this.platform.ready();
if (ready && this.platform.is('cordova')) {
// try to add your code here
}
}
you have to remove code from ngoninit and add it in ionviewdidenter
ionViewDidEnter(){
//your code here
}
Problem and question
I've always had problems with CSS code, so now I always use SaSS code. But my question is: how can I use SaSS for an ASP.NET MVC application?
I've tried
I've tried tried to use a Gulp task for this. I've used these commands
npm init
npm install --save gulp
npm install --save gulp-sass
Here is my package.json file:
{
"name": "markeonline",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Hein Pauwelyn",
"license": "ISC",
"dependencies": {
"gulp": "^3.9.1",
"gulp-sass": "^3.1.0"
}
}
Here is the gulpfile.js
var gulp = require("gulp"),
sass = require("gulp-sass");
// other content removed
gulp.task("sass", function () {
return gulp.src('./**/*.scss')
.pipe(sass())
.pipe(gulp.dest(project.webroot + './MarkeOnline.Website/Content/css'));
});
Here is my project structure:
This code gives me the following error if I use the command below:
gulp sass
ReferenceError: project is not defined
[17:50:58] ReferenceError: project is not defined
at Gulp.<anonymous> (D:\Documenten\Howest\Semester 4\05 - Project\MarkeOnlinebis\Project Execution\MarkeOnline\gulpfile.js:9:23)
at module.exports (D:\Documenten\Howest\Semester 4\05 - Project\MarkeOnlinebis\Project Execution\MarkeOnline\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (D:\Documenten\Howest\Semester 4\05 - Project\MarkeOnlinebis\Project Execution\MarkeOnline\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (D:\Documenten\Howest\Semester 4\05 - Project\MarkeOnlinebis\Project Execution\MarkeOnline\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (D:\Documenten\Howest\Semester 4\05 - Project\MarkeOnlinebis\Project Execution\MarkeOnline\node_modules\orchestrator\index.js:134:8)
at C:\Users\hein_\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at _combinedTickCallback (internal/process/next_tick.js:67:7)
at process._tickCallback (internal/process/next_tick.js:98:9)
at Module.runMain (module.js:592:11)
at run (bootstrap_node.js:394:7)
events.js:160
throw er; // Unhandled 'error' event
^
Error: node_modules\node-sass\test\fixtures\depth-first\_vars.scss
Error: Undefined variable: "$import-counter".
on line 1 of node_modules/node-sass/test/fixtures/depth-first/_vars.scss
>> $import_counter: $import_counter + 1;
-----------------^
at options.error (D:\Documenten\Howest\Semester 4\05 - Project\MarkeOnlinebis\Project Execution\MarkeOnline\node_modules\node-sass\lib\index.js:291:26)
Try Web Compiler plugin instead this is what I use to compile SCSS in MVC.
A Visual Studio extension that compiles LESS, Sass, JSX, ES6 and CoffeeScript files.
You can use another way easier I think.
Step 1
Go with this steps
in your NuGet Manager.
Add Microsoft.AspNet.Web.Optimization
Add BundleTransformer.SassAndScss
Add LibSassHost.Native.win-x64 if you use system 64 bit.
LibSassHost.Native.win-x86
Step2
In BundleConfig.cs add this code in RegisterBundles methode.
var nullBulider = new NullBuilder();
var nullOrderer = new NullOrderer();
BundleResolver.Current = new CustomBundleResolver();
var commonStyleBundle = new CustomStyleBundle("~/Bundle/sass");
commonStyleBundle.Include("~/css/main.scss");
commonStyleBundle.Orderer = nullOrderer;
bundles.Add(commonStyleBundle);
Step 3
Add CSS folder in your project and add main.scss file sheet inside.
Step 4
In your view, you need to use System.Web.Optimization.
#using System.Web.Optimization
And link your style sheet
#Styles.Render("~/Bundle/sass").
Step 5
In Global.asax we need to add this line in Application_Start().
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
Or maybe you will find it already in your class if you use MVC templet.
And that is it your main.scss its work.
This is how you can add Sass to your Mvc app:
Download WebCompiler:
https://marketplace.visualstudio.com/items?itemName=MadsKristensen.WebCompiler&ssr=false#qna
Double click on the Vsix file to install it.
Right click on solution, Manage Nuget Packages
Download bootstrap.sass package (version 4 or above)
Right click on the bootstrap.scss file under Content folder you need and select Web Compiler - Compile File
The bootstrap.css file will be generated.
You can select any scss file to compile.
You can see the configuration (list of files to be compiled) in the compilerconfig.json file in the root folder.
Add the css file to the bundle.
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap/main.css",
"~/Content/site.css"));
If you need to customize bootstrap, add a main.scss file in the same folder as bootstrap.scss. Then compile it using Web Compiler.
main.scss:
/* import the necessary Bootstrap files */
#import "_functions.scss";
#import "_variables.scss";
/* make changes to the !default Bootstrap variables */
$body-color: green;
/* finally, import Bootstrap to set the changes! */
#import "bootstrap.scss";
This example includes all the files, but make sure you only add the files you need to make the css smaller.
I would like to use https://github.com/MrRio/jsPDF in my ember project.
I wanted to import jsPDF as dependency, therefore I started this way:
bower install git#github.com:MrRio/jsPDF.git --save
Unfortunately, I cannot install files from plugins directory, because "plugins/*" directory is ignored in bower.json file.
I have tried overriding it this way, but without success.
"overrides": {
"jspdf": {
"ignore": [
"**/.*",
"libs",
"CNAME",
"jspdf.js",
"examples/jspdf.PLUGINTEMPLATE.js",
"todo.txt",
"wscript.py",
"build.sh",
"test",
"tools"
]
}
}
Could you please help me?
I just added a jsPDF plugins package to bower.
You can add all the plugins via
bower install jsPDF-plugins --save
bower.json can specify which files should be ignored:
ignore [array]: An array of paths not needed in production that you want Bower to ignore when installing your package.
Which paths are ignored by default?
From the source:
json.ignore = mout.array.combine(json.ignore || [], [
'**/.*',
'node_modules',
'bower_components',
config.directory,
'test',
'tests'
]);
Apparently all dotfiles are ignored, as are the bower_components, node_modules, test, and tests directories. I don't know what config.directory is.
Update: I just published a package, and the test directory was not ignored. Apparently I've misunderstood the source code. I'd love clarification from a Bower contributor.
Files which are listed in ignore property will not be installed by bower.
So, if you have a this kind of structure:
style.css
index.html
bower.json
script.js
and a bower.json file:
{
"ignore": [ "./script.js" ]
}
script.js will not be installed within this component.