0

I am creating an NPM Angular library and would like to have a css folder and custom fonts available in the final build, so I can only import scss files into applications that will install this library directly into their scss files.

Library structure:

src/
--lib/
----styles/
------variables.scss
------custom.scss
----components/
--public_api.ts
--test.ts
package.json

import should be like that in scss file?

@import '~@mylib/styles/variables.scss'

I'm trying to copy the css folder to build by myself in script that generates the build.

Something like:

ng build lib && cp /styles dist/lib/styles && npm pack

Haven't success yet.

I don't even know if that's a good practice, but it is that i think it'll work

2
  • and??????? did you try anything? Commented Aug 9, 2019 at 16:55
  • I'm trying to copy the css folder to build by myself in script that generates the build. Something like: " ng build lib && cp /styles dist/lib/styles && npm pack ". Haven't success yet. Commented Aug 9, 2019 at 17:07

2 Answers 2

1

Got it

I keep not knowing if it's the best practice, but it works.

Place this on scripts in package.json, then use npm run build-mylib to build and pack your library.

    "build-mylib": "ng build mylib && npm run cp-styles && npm run cp-assets && cd dist/mylib/ && npm pack",
    "cp-styles": "cpx \"./projects/mylib/src/lib/styles/**/*\" \"./dist/mylib/styles\"",
    "cp-assets": "cpx \"./projects/mylib/src/lib/assets/**/*\" \"./dist/mylib/assets\""
Sign up to request clarification or add additional context in comments.

Comments

0

you can also write a gulp task to do it for you, it would just reduce the number of scripts you run during compiling, but all those tasks would be done in the gulp file. This will go in gulpfile.js

gulp.task('copyStyles ', function() {
    return gulp.src('./projects/mylib/src/lib/styles/**/*\')
        .pipe(gulp.dest('./dist/mylib/styles\'));
});

and in your package.json > scripts

"pack-lib": "ng build lib && gulp copyStyles && npm pack"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.