stencil icon indicating copy to clipboard operation
stencil copied to clipboard

Allow generate new component with scss file instead of css

Open JeanOsorio opened this issue 6 years ago • 9 comments

Stencil version:

 @stencil/[email protected]

I'm submitting a:

[ ] bug report [x ] feature request [ ] support request => Please do not submit support requests here, use one of these channels: https://stencil-worldwide.herokuapp.com/ or https://forum.ionicframework.com/

Current behavior: Can generate a new component with scss file instead of css

Expected behavior: allow to generate a new component with a scss file and with the css file inside decorator

Steps to reproduce: npm run generate

✔ Component tag name (dash-case): … my-component ✔ Which additional files do you want to generate? › Stylesheet, Spec Test, E2E Test

$ stencil generate super-component

The following files have been generated:

  • src/components/component/my-component.tsx
  • src/components/component/my-component.css
  • src/components/component/my-component.spec.ts
  • src/components/component/my-component.e2e.ts

Related code:

import { Component, Prop, h } from '@stencil/core';
import { format } from '../../utils/utils';

@Component({
  tag: 'my-component',
  styleUrl: 'my-component.css', 
  shadow: true
})
export class MyComponent {
  /**
   * The first name
   */
  @Prop() first: string;

  /**
   * The middle name
   */
  @Prop() middle: string;

  /**
   * The last name
   */
  @Prop() last: string;

  private getText(): string {
    return format(this.first, this.middle, this.last);
  }

  render() {
    return <div>Hello, World! I'm {this.getText()}</div>;
  }
}

Other information: Here is the suggestion of simonhaenisch on slack https://stencil-worldwide.slack.com/archives/C79EANFL7/p1579693868137100

JeanOsorio avatar Jan 22 '20 19:01 JeanOsorio

I would like to make a PR for this feature, could someone asign me this issues. Thanks in advance

JeanOsorio avatar Jan 22 '20 19:01 JeanOsorio

Hi @JeanOsorio ,

Do you have npm install @stencil/sass --save-dev that was made to support this use case.

Please have at look a Plugins documentation https://stenciljs.com/docs/plugins

romulocintra avatar Jan 22 '20 19:01 romulocintra

Hello @romulocintra I’ve already install the sass plugin, all my components work with sass files, but I have to manually change from .css to .scss, so my proposal is to generate a component with a scss instead of css

JeanOsorio avatar Jan 22 '20 21:01 JeanOsorio

Personally I totally agree with @JeanOsorio. With the actual capabilities of StencilJS a thing as simple as create a new component using SASS from the beginning it is a no way man feature (not able to do so). Otherwise as @romulocintra states, it can process sass to css and then do whatever you please with ease, but it is a pain in the head to manually change each time from css to sass when creating a new compo.

Drohno avatar Jan 22 '20 22:01 Drohno

I believe the core architecture based on plugins intends to be optioned and pluggable, adding this probably would go against it and open different threads about:

  • Why not support sass/less/stylus +
  • Extra weight if you mean add the plugin to the core

Having this in generation process as option or parameter of the CLI would be more recommended, always checking if plugin exist or installed and probably accepting as many options as plugins. Or give support for custom templates

romulocintra avatar Jan 22 '20 22:01 romulocintra

That is @romulocintra exactly my point of view about this. If you have installed the sass pligin if stencil, your cli would have to have the new ability to create scss instead of css files

Drohno avatar Jan 22 '20 22:01 Drohno

You can use vscode Stencil tools in the meantime, you can configure the extensions.

max-scopp avatar Jan 24 '20 09:01 max-scopp

Just to be aware: The extension in VS generates e2e file inside the component folder ('npm run generate' creates 'test' folder and inside spec and e2e files).

diegolsarmiento avatar Mar 13 '21 20:03 diegolsarmiento

Hi all 👋

I think this could be a nice addition we add in the future. To feel effective, however, seems like we would need to make some related changes to how our started projects are created for this to be useful end-to-end. I'll put a label on here so this can get ingested into our backlog for future refinement. Keep an eye here for future updates!

tanner-reits avatar Sep 02 '22 19:09 tanner-reits

Implemented in https://github.com/ionic-team/stencil/pull/5857

christian-bromann avatar Jun 26 '24 16:06 christian-bromann

This was included in today's v4.19.0 release!

tanner-reits avatar Jun 26 '24 20:06 tanner-reits