When both an AngularJS and Angular app are running concurrently, CSS compilation may encounter issues

I've encountered an issue with my CSS while attempting to transition to a hybrid AngularJS/Angular application using angular-cli.

ERROR in ./src/styles.scss (./node_modules/@angular-devkit/build-angular/src/angular-cli-files/plugins/raw-css-loader.js!./node_modules/postcss-loader/src??embedded!../node_modules/sass-loader/dist/cjs.js??ref--15-3!./src/styles.scss)
Module build failed (from ./node_modules/postcss-loader/src/index.js):
SyntaxError

(2:4) Unknown word

  1 | //
> 2 | // Copyright 2017 Google Inc.
    |    ^
  3 | //
  4 | // Permission is hereby granted, free of charge, to any person obtaining a copy

In the past, I relied on webpack to manage my CSS/SCSS:

{
    test: /\.(css|scss)$/,
    use: [
        MiniCssExtractPlugin.loader,
        {
        loader: 'css-loader',
        options: {
            sourceMap: true
        }
        },
        {
        loader: 'sass-loader',
        options: {
            sourceMap: true,
            includePaths: ['./css', './node_modules']
        }
        },
        {
        loader: 'postcss-loader',
        options: {
            sourceMap: true,
            plugins: () => [
            postcssCustomProperties({
                importFrom: ['./css/variables.css']
            })
            ]
        }
        }
    ]
}

It appears that angular-cli's webpack build processes CSS differently from how my old AngularJS project did. I want to maintain a separation between my AngularJS project and the new Angular project. How can I incorporate all the existing CSS from my AngularJS project into the new setup?

Answer №1

If I understand correctly, you are looking to integrate CSS files from an AngularJS project into your Angular project. It's not clear whether you want them included in the application bundle or if you simply want both projects to coexist in a single distribution folder.

If you want to merge your AngularJS CSS files with Angular, here are a few options:

angular.json > styles You can add the styles directly in your angular.json file.

"styles": [
  "/some/styles/cssfile.css"
],

Utilize assets directory Simply place the files you need in the assets directory and they will be bundled as-is. Ensure that your angular.json is set up to include your assets directory (I'm not sure if this is the default behavior).

"assets": [
  "src/favicon.ico",
  "src/assets"
],

Alternative approaches

  • Add references to your files in the index.html of your new Angular app.
  • Import your CSS files directly into the main styles.scss file of your Angular project (@import 'some/ref').

Answer №2

Could you please provide the angular.json file? If the angular.json file is correctly configured with "styles":[ ] for Angular CLI, then loaders are not necessary. The error suggests that you may still be using the outdated webpack approach.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The issue arises when trying to style a scrollable table in Bootstrap with CSS

I have created a scrollable table using Bootstrap. The scrolling functionality works perfectly, but I am facing an issue with three black lines appearing under the thead tag. I am unsure how to remove them. If you have any suggestions on how to fix this pr ...

alter the input information using AngularJS

Every time I try to edit the entry, it takes me back to the form. However, once I hit enter, the null values are saved and I'm not sure why this is happening. I suspect that the issue lies in not pushing the entire object (including name, title, and ...

HTML/CSS: What could be causing the iframe to not scroll properly?

I am facing an issue with my website that has 3 iframes, none of them seem to be working properly. In Firefox, the scroll bars appear but do not function, while in Chrome, the scroll bars do not appear at all. Surprisingly, they work fine in IE 6. This pr ...

When running `npm install` and `ionic build`, not all node modules are installed

Currently facing some issues with node_modules while trying to build an existing Ionic app. Here is the package.json file: { "name": "My App", "private": true, "scripts": { "clean": "ionic-app-scripts clean", "build": "ionic-app-scripts buil ...

Implementing a dynamic Bootstrap 4 accordion feature within an Angular project

I have implemented a Bootstrap 4 accordion in my Angular project. Below is the structure of my accordion: <div id="accordion" class="accordion"> <div class="card mb-0"> ...

Automatic Form Saving in Angular 4

Seeking to create a form data autosave feature in Angular 4. The functionality should operate as follows: User modifies data in the form -> save request sent to DB. A timer is initiated for 2 seconds. During the 2-second window after the previous s ...

The variable $rootScope was not properly defined within the directive, causing it

angular.module('test', []) .directive('microFrontEnd', function($rootScope) { 'use strict'; $rootScope.show = true; return { restrict: 'E', templateUrl: '../template.html' ...

Enhance the functionality of your website by implementing a zoom feature

I am looking to dynamically change the CSS of a div using jQuery when it is clicked. The challenge I am facing is that there are multiple divs with the same class and I am unable to modify their classes as they are created dynamically using PHP. <div ...

Expand a list item to full width based on the number of items present

Is there a way to make dynamically added list items in a footer stretch across the width of their container? The footer is created in WordPress and the list items are actually widgets. Here is an example: Fiddle I can't manually set the width for e ...

What is the best way to customize the styles of md-input-container in Angular 2?

Below is the code snippet for a md-input-container using angular material design: <md-input-container> <input mdInput [placeholder]="'common.password' | translate" type="password" formControlName="password" (change)="onPasswordCh ...

Updating an object within an array during ng-repeat iteration through the use of ng-init directive

I am having trouble setting the position property on an element that is inside of an array being utilized by ng-repeat. <div ng-repeat="item in items track by $index" ng-init="pos = $index + 1; item.position = pos"> <span>{{pos}}</span> ...

Steps to call a controller function from a ui-grid cellTemplate

In my cellTemplate, I included a link that triggers a function in the controller when clicked. The function requires passing the item of the row that was clicked as an argument. ...

What is the best way to determine which component bears the responsibility?

My components are structured like this: <app-orders> <app-orders-list><div *ngFor="let order of orders"></div></app-orders-list> <app-pagination></app-pagination> <app-pagination-showby></app- ...

Formatting JSON with two fields

I attempted to organize JSON data based on city names using this fiddle code. Now, I am trying to group the data by city name and city code. Any suggestions or hints regarding the logic would be greatly appreciated. CurrentDataFormat = [{ "Id": 1 ...

Incorporating TypeScript basics into the if statement post compiling

As I delve into the Angular2 Quickstart, I stumbled upon a peculiar issue within app.component.js after compiling app.component.ts using tsc (version 1.8.2): if (d = decorators[i]) I am unable to pinpoint where I may have gone wrong in configuring the qu ...

Connection Among Angular Modules

I am currently encountering an issue with Dependency Injection between modules. One of my modules implements a directive that I need to utilize in other applications. To incorporate the dependency from this module into another app declaration, I used the ...

Object shifting as the window is resized

Check out the Umbrella image in the images section: Full-size window: . Reduced (ideal placement): I want my umbrella image to always display in the center of the screen, regardless of the size of the window. It should work when the window shrinks and ...

The image zoom function is malfunctioning when trying to adjust the image position

Having some trouble with a code for image zoom in/out. When I adjust the position of the image by applying margin left to either the image or the image container (#view), it affects the zoom functionality - causing the image to move to the left during zoom ...

Encountered an AngularJS issue when attempting to utilize a factory from a separate file

Hello, I am facing an issue with two AngularJS files. The first file is a controller and the second is a factory function, but it is resulting in an 'unpr' error. The factory file contains: var app = angular.module('basicApi',[]); app ...

Linking interconnected RxJs observables?

Currently, I am attempting to link observables together that rely on API calls (which are dependent on data from previous observables) in order to create an object. My process involves retrieving a roster that contains a manifest ID. Using that ID, I then ...