Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use "styleIncludePaths" ? #1073

Closed
Eusen opened this issue Sep 10, 2018 · 20 comments
Closed

How to use "styleIncludePaths" ? #1073

Eusen opened this issue Sep 10, 2018 · 20 comments

Comments

@Eusen
Copy link

Eusen commented Sep 10, 2018

Type of Issue

[?] Bug Report

Description

"styleIncludePaths": {
          "description": "Any additional paths that should be used to resolve style imports",
          "type": "array",
          "items": {
            "type": "string"
          }
}

I found this schema, but no matter how I try, it doesn't work.
My lib dir structure is like this:

/lib/module/src/styles/index.scss
/lib/module/ng-package.json

And I add styleIncludePaths in ng-packge.json like this:

"lib": {
    "entryFile": "src/public_api.ts",
    "styleIncludePaths": [
      "styles/index.scss" // and I have tried "index.scss" , "src/styles/index.scss", but nothing happened.
    ]
}

How To Reproduce

No error, but nothing happened.

Expected Behaviour

How do I use it?
If it doesn't work anyway, can u add a "staticAssetsPaths" schema, like angular.json's architect.build.options.assets ?
I think not only me, many developers need to include static resources in the package, such as font icons. I now use Python to do this.

Version Information

$ node_modules/.bin/ng-packagr --version
ng-packagr: latest
@angular/*: latest
typescript: 2.9.2
rxjs: latest
node: latest
npm/yarn: latest
@alan-agius4
Copy link
Member

alan-agius4 commented Sep 10, 2018 via email

@Eusen
Copy link
Author

Eusen commented Sep 10, 2018

image

I got this error.

this is my angular.json:
image
and this is my ng-package.json:
image

@Eusen
Copy link
Author

Eusen commented Sep 10, 2018

image
image
I add aot prop failed too,

@Eusen
Copy link
Author

Eusen commented Sep 10, 2018

hello? Is anyone here?

@alan-agius4
Copy link
Member

You need to follow the angular cli schema for libraries. https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_ng_packagr/src/build/schema.json

Those changes need to be added to ng-packagr.json

@Eusen
Copy link
Author

Eusen commented Sep 11, 2018

The problem has not been solved yet. Why closed?
image
If I just add this just like:
style-include-paths.md
It didn't work either!

@Eusen
Copy link
Author

Eusen commented Sep 11, 2018

If I write something wrong, can you point it out for me?

@zjl1985
Copy link

zjl1985 commented Oct 22, 2018

I also encountered the same problem....

@chenTeacher
Copy link

我想你没有理解stylePreprocessorOptions是什么,它就是一个帮助你省略路径的作用:
// 相对路径工作
@import '../you-style-paths/variables';
在添加
"stylePreprocessorOptions": {
"includePaths": [
"src/you-style-paths"
]
},

你只需要这么写
@import 'variables';
同理你在开发包的时候不想写这么长串的路径时,可以这么写 "styleIncludePaths": ["./src/assets/styles"],然后打包的时候cli会帮你匹配路径。这个是我的理解。
我想你是想将资源文件一起打包出来吧,很不幸 ng-packagr 不支持,或者我还没有找到方案。

@zjl1985
Copy link

zjl1985 commented Jan 3, 2019

我想你没有理解stylePreprocessorOptions是什么,它就是一个帮助你省略路径的作用:
// 相对路径工作
@import '../you-style-paths/variables';
在添加
"stylePreprocessorOptions": {
"includePaths": [
"src/you-style-paths"
]
},

你只需要这么写
@import 'variables';
同理你在开发包的时候不想写这么长串的路径时,可以这么写 "styleIncludePaths": ["./src/assets/styles"],然后打包的时候cli会帮你匹配路径。这个是我的理解。
我想你是想将资源文件一起打包出来吧,很不幸 ng-packagr 不支持,或者我还没有找到方案。

谢谢你,我解决了,是在打包之后,又加了一个脚本把我的资源文件加入到dist里面

// scripts\build\copy-style.js
const path = require('path');
const fs = require('fs-extra');

const sourcePath = path.resolve(__dirname, '../../src/app/package');
const targetPath = path.resolve(__dirname, '../../dist');


console.log('---------------copy style folder-----------------------');
fs.copySync(path.resolve(sourcePath, 'style'), path.resolve(targetPath, 'style'));
console.log('---------------done-----------------------');

package.json package后会执行

"postpackage": "node ./scripts/build/copy-style.js"

@renyaoxiang
Copy link

我想你没有理解stylePreprocessorOptions是什么,它就是一个帮助你省略路径的作用:
// 相对路径工作
@import '../you-style-paths/variables';
在添加
"stylePreprocessorOptions": {
"includePaths": [
"src/you-style-paths"
]
},

你只需要这么写
@import 'variables';
同理你在开发包的时候不想写这么长串的路径时,可以这么写 "styleIncludePaths": ["./src/assets/styles"],然后打包的时候cli会帮你匹配路径。这个是我的理解。
我想你是想将资源文件一起打包出来吧,很不幸 ng-packagr 不支持,或者我还没有找到方案。

谢谢你,我解决了,是在打包之后,又加了一个脚本把我的资源文件加入到dist里面

脚本代码怎么写?

@zjl1985
Copy link

zjl1985 commented Mar 18, 2019

我想你没有理解stylePreprocessorOptions是什么,它就是一个帮助你省略路径的作用:
// 相对路径工作
@import '../you-style-paths/variables';
在添加
"stylePreprocessorOptions": {
"includePaths": [
"src/you-style-paths"
]
},

你只需要这么写
@import 'variables';
同理你在开发包的时候不想写这么长串的路径时,可以这么写 "styleIncludePaths": ["./src/assets/styles"],然后打包的时候cli会帮你匹配路径。这个是我的理解。
我想你是想将资源文件一起打包出来吧,很不幸 ng-packagr 不支持,或者我还没有找到方案。

谢谢你,我解决了,是在打包之后,又加了一个脚本把我的资源文件加入到dist里面

脚本代码怎么写?

// scripts\build\copy-style.js
const path = require('path');
const fs = require('fs-extra');

const sourcePath = path.resolve(__dirname, '../../src/app/package');
const targetPath = path.resolve(__dirname, '../../dist');


console.log('---------------copy style folder-----------------------');
fs.copySync(path.resolve(sourcePath, 'style'), path.resolve(targetPath, 'style'));
console.log('---------------done-----------------------');

package.json package后会执行

"postpackage": "node ./scripts/build/copy-style.js"

@renyaoxiang
Copy link

renyaoxiang commented Mar 19, 2019

我想你没有理解stylePreprocessorOptions是什么,它就是一个帮助你省略路径的作用:
// 相对路径工作
@import '../you-style-paths/variables';
在添加
"stylePreprocessorOptions": {
"includePaths": [
"src/you-style-paths"
]
},

你只需要这么写
@import 'variables';
同理你在开发包的时候不想写这么长串的路径时,可以这么写 "styleIncludePaths": ["./src/assets/styles"],然后打包的时候cli会帮你匹配路径。这个是我的理解。
我想你是想将资源文件一起打包出来吧,很不幸 ng-packagr 不支持,或者我还没有找到方案。

谢谢你,我解决了,是在打包之后,又加了一个脚本把我的资源文件加入到dist里面

脚本代码怎么写?

// scripts\build\copy-style.js
const path = require('path');
const fs = require('fs-extra');

const sourcePath = path.resolve(__dirname, '../../src/app/package');
const targetPath = path.resolve(__dirname, '../../dist');


console.log('---------------copy style folder-----------------------');
fs.copySync(path.resolve(sourcePath, 'style'), path.resolve(targetPath, 'style'));
console.log('---------------done-----------------------');

package.json package后会执行

"postpackage": "node ./scripts/build/copy-style.js"

不好意思,忘记说了,我使用了less,会有图片、字体资源。我希望构建的时候,我可以看到less的效果,拷贝的时候也可以拷贝less相应的css和图片、字体资源,有办法吗?

@Eusen
Copy link
Author

Eusen commented Mar 19, 2019

@renyaoxiang 你这就有点强人所难了。本身这个工具就不支持这样做。

@renyaoxiang
Copy link

@renyaoxiang 你这就有点强人所难了。本身这个工具就不支持这样做。

但是我需要这个需求啊,
就不能有一个俩者皆得的方案吗?

@Eusen
Copy link
Author

Eusen commented Mar 20, 2019

@renyaoxiang 你这就有点强人所难了。本身这个工具就不支持这样做。

但是我需要这个需求啊,
就不能有一个俩者皆得的方案吗?

你可以用webpack打包试试,自己写个配置。或者rollup也行。

@zjl1985
Copy link

zjl1985 commented Mar 20, 2019

我想你没有理解stylePreprocessorOptions是什么,它就是一个帮助你省略路径的作用:
// 相对路径工作
@import '../you-style-paths/variables';
在添加
"stylePreprocessorOptions": {
"includePaths": [
"src/you-style-paths"
]
},

你只需要这么写
@import 'variables';
同理你在开发包的时候不想写这么长串的路径时,可以这么写 "styleIncludePaths": ["./src/assets/styles"],然后打包的时候cli会帮你匹配路径。这个是我的理解。
我想你是想将资源文件一起打包出来吧,很不幸 ng-packagr 不支持,或者我还没有找到方案。

谢谢你,我解决了,是在打包之后,又加了一个脚本把我的资源文件加入到dist里面

脚本代码怎么写?

// scripts\build\copy-style.js
const path = require('path');
const fs = require('fs-extra');

const sourcePath = path.resolve(__dirname, '../../src/app/package');
const targetPath = path.resolve(__dirname, '../../dist');


console.log('---------------copy style folder-----------------------');
fs.copySync(path.resolve(sourcePath, 'style'), path.resolve(targetPath, 'style'));
console.log('---------------done-----------------------');

package.json package后会执行

"postpackage": "node ./scripts/build/copy-style.js"

不好意思,忘记说了,我使用了less,会有图片、字体资源。我希望构建的时候,我可以看到less的效果,拷贝的时候也可以拷贝less相应的css和图片、字体资源,有办法吗?

我这写的就是copy文件啊,你有啥想copy的就是写就行了

又不是只能写一个

@juanslingerURUIT
Copy link

juanslingerURUIT commented May 17, 2019

@Eusen I have an example working using styleIncludePaths.

Have two libraries, style and component. Could integrate styles library with component library.

The architect is something like this.

  • libraries
    • components
      • component-1
        • component-1.scss
      • ng-package.json
    • styles
      • scss
        • components
          • component-1.scss

File ng-package.json
"styleIncludePaths": ["../styles/scss"]

By this, the component library will search at styles/scss so inside component-1.scss I added @import 'components/component-1'.

This worked for me!

Let me know if you have an issue.

@maxmumford
Copy link

Note that the path is relative to the library you're compiling - this is particularly relavent if you're using a nrwl monorepo structure!

@github-actions
Copy link

This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
This action has been performed automatically by a bot.

@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

7 participants