@analogjs/storybook-angular 2.0.0-alpha.17 → 2.0.0-alpha.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  Integration package for Storybook using Angular & Vite.
4
4
 
5
+ > This is a community integration not maintained by the Storybook team. If you have issues,
6
+ > file an issue in our [GitHub repo](https://github.com/analogjs/analog/issues).
7
+
5
8
  ## Setup
6
9
 
7
10
  If you don't have Storybook setup already, run the following command to initialize Storybook for your project:
@@ -22,33 +25,7 @@ npm install @analogjs/storybook-angular --save-dev
22
25
 
23
26
  ## Configuring Storybook
24
27
 
25
- Add the `zone.js` import to the top of the `.storybook/preview.ts` file.
26
-
27
- ```ts
28
- import 'zone.js';
29
- import { applicationConfig, type Preview } from '@analogjs/storybook-angular';
30
- import { provideNoopAnimations } from '@angular/platform-browser/animations';
31
-
32
- const preview: Preview = {
33
- decorators: [
34
- applicationConfig({
35
- providers: [provideNoopAnimations()],
36
- }),
37
- ],
38
- parameters: {
39
- controls: {
40
- matchers: {
41
- color: /(background|color)$/i,
42
- date: /Date$/i,
43
- },
44
- },
45
- },
46
- };
47
-
48
- export default preview;
49
- ```
50
-
51
- Next, update the `.storybook/main.ts` file to use the `StorybookConfig`. Also update the `framework` to use the `@analogjs/storybook-angular` package.
28
+ Update the `.storybook/main.ts` file to use the `StorybookConfig` type. Also update the `framework` to use the `@analogjs/storybook-angular` package.
52
29
 
53
30
  ```ts
54
31
  import { StorybookConfig } from '@analogjs/storybook-angular';
@@ -60,11 +37,13 @@ const config: StorybookConfig = {
60
37
  options: {},
61
38
  },
62
39
  };
40
+
41
+ export default config;
63
42
  ```
64
43
 
65
44
  Remove the existing `webpackFinal` config function if present.
66
45
 
67
- Next, update the Storybook builders in the `angular.json` or `project.json`.
46
+ Next, update the Storybook targets in the `angular.json` or `project.json`
68
47
 
69
48
  ```json
70
49
  "storybook": {
@@ -77,7 +56,61 @@ Next, update the Storybook builders in the `angular.json` or `project.json`.
77
56
 
78
57
  Remove any `webpack` specific options and remove the `browserTarget` option.
79
58
 
80
- Add the `/storybook-static` folder to your `.gitignore` file.
59
+ Add the `/storybook-static` folder to the `.gitignore` file.
60
+
61
+ ## Setting up CSS
62
+
63
+ To register global styles, add them to the `@analogjs/storybook-angular` builder options in the `angular.json` or `project.json`.
64
+
65
+ ```json
66
+ "storybook": {
67
+ "builder": "@analogjs/storybook-angular:start-storybook",
68
+ "options": {
69
+ // ... other options
70
+ "styles": [
71
+ "src/styles.css"
72
+ ],
73
+ "stylePreprocessorOptions": {
74
+ "loadPaths": ["libs/my-lib/styles"]
75
+ }
76
+ }
77
+ },
78
+ "build-storybook": {
79
+ "builder": "@analogjs/storybook-angular:build-storybook",
80
+ "options": {
81
+ // ... other options
82
+ "styles": [
83
+ "src/styles.css"
84
+ ],
85
+ "stylePreprocessorOptions": {
86
+ "loadPaths": ["libs/my-lib/styles"]
87
+ }
88
+ }
89
+ }
90
+ ```
91
+
92
+ ## Setting up Static Assets
93
+
94
+ Static assets are configured in the `.storybook/main.ts` file using the `staticDirs` array.
95
+
96
+ The example below shows how to add the `public` directory from `src/public` relative to the `.storybook/main.ts` file.
97
+
98
+ ```ts
99
+ import { StorybookConfig } from '@analogjs/storybook-angular';
100
+
101
+ const config: StorybookConfig = {
102
+ // other config, addons, etc.
103
+ framework: {
104
+ name: '@analogjs/storybook-angular',
105
+ options: {},
106
+ },
107
+ staticDirs: ['../public'],
108
+ };
109
+
110
+ export default config;
111
+ ```
112
+
113
+ See the [Storybook docs on images and assets](https://storybook.js.org/docs/configure/integration/images-and-assets) for more information.
81
114
 
82
115
  ## Running Storybook
83
116
 
@@ -95,27 +128,6 @@ Run the command for building the storybook.
95
128
  npm run build-storybook
96
129
  ```
97
130
 
98
- ## Using shared CSS paths
99
-
100
- To load shared CSS paths, configure them using `loadPaths` css option in the `viteFinal` function.
101
-
102
- ```ts
103
- import path from 'node:path';
104
- import { UserConfig, mergeConfig } from 'vite';
105
-
106
- export async function viteFinal(config: UserConfig) {
107
- return mergeConfig(config, {
108
- css: {
109
- preprocessorOptions: {
110
- scss: {
111
- loadPaths: `${path.resolve(__dirname, '../src/lib/styles')}`,
112
- },
113
- },
114
- },
115
- });
116
- }
117
- ```
118
-
119
131
  ## Using TypeScript Config Path Aliases
120
132
 
121
133
  If you are using `paths` in your `tsconfig.json`, support for those aliases can be added to the `vite.config.ts`.
@@ -134,11 +146,18 @@ Next, add the plugin to the `plugins` array in the `.storybook/main.ts`.
134
146
  import viteTsConfigPaths from 'vite-tsconfig-paths';
135
147
  import { UserConfig, mergeConfig } from 'vite';
136
148
 
137
- export async function viteFinal(config: UserConfig) {
138
- return mergeConfig(config, {
139
- plugins: [viteTsConfigPaths()],
140
- });
141
- }
149
+ import type { StorybookConfig } from '@analogjs/storybook-angular';
150
+
151
+ const config: StorybookConfig = {
152
+ // ... other config, addons, etc.
153
+ async viteFinal(config: UserConfig) {
154
+ return mergeConfig(config, {
155
+ plugins: [viteTsConfigPaths()],
156
+ });
157
+ },
158
+ };
159
+
160
+ export default config;
142
161
  ```
143
162
 
144
163
  ### With Nx
@@ -149,11 +168,18 @@ For Nx workspaces, import and use the `nxViteTsPaths` plugin from the `@nx/vite`
149
168
  import { nxViteTsPaths } from '@nx/vite/plugins/nx-tsconfig-paths.plugin';
150
169
  import { UserConfig, mergeConfig } from 'vite';
151
170
 
152
- export async function viteFinal(config: UserConfig) {
153
- return mergeConfig(config, {
154
- plugins: [nxViteTsPaths()],
155
- });
156
- }
171
+ import type { StorybookConfig } from '@analogjs/storybook-angular';
172
+
173
+ const config: StorybookConfig = {
174
+ // ... other config, addons, etc.
175
+ async viteFinal(config: UserConfig) {
176
+ return mergeConfig(config, {
177
+ plugins: [nxViteTsPaths()],
178
+ });
179
+ },
180
+ };
181
+
182
+ export default config;
157
183
  ```
158
184
 
159
185
  ## Using File Replacements
@@ -166,18 +192,25 @@ Import the plugin and set it up:
166
192
  import { replaceFiles } from '@nx/vite/plugins/rollup-replace-files.plugin';
167
193
  import { UserConfig, mergeConfig } from 'vite';
168
194
 
169
- export async function viteFinal(config: UserConfig) {
170
- return mergeConfig(config, {
171
- plugins: [
172
- replaceFiles([
173
- {
174
- replace: './src/one.ts',
175
- with: './src/two.ts',
176
- },
177
- ]),
178
- ],
179
- });
180
- }
195
+ import type { StorybookConfig } from '@analogjs/storybook-angular';
196
+
197
+ const config: StorybookConfig = {
198
+ // ... other config, addons, etc.
199
+ async viteFinal(config: UserConfig) {
200
+ return mergeConfig(config, {
201
+ plugins: [
202
+ replaceFiles([
203
+ {
204
+ replace: './src/one.ts',
205
+ with: './src/two.ts',
206
+ },
207
+ ]),
208
+ ],
209
+ });
210
+ },
211
+ };
212
+
213
+ export default config;
181
214
  ```
182
215
 
183
216
  Adding the replacement files to `files` array in the `tsconfig.app.json` may also be necessary.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@analogjs/storybook-angular",
3
- "version": "2.0.0-alpha.17",
3
+ "version": "2.0.0-alpha.19",
4
4
  "description": "Storybook Integration for Angular & Vite",
5
5
  "keywords": [
6
6
  "storybook",
@@ -38,12 +38,12 @@
38
38
  },
39
39
  "main": "src/index.js",
40
40
  "dependencies": {
41
- "@storybook/builder-vite": ">=8.6.0 || ^9.0.0 || next"
41
+ "@storybook/builder-vite": ">=8.6.0 || ^9.0.0"
42
42
  },
43
43
  "peerDependencies": {
44
- "@storybook/angular": ">=8.6.0 || ^9.0.0 || next",
44
+ "@storybook/angular": ">=8.6.0 || ^9.0.0",
45
45
  "@analogjs/vite-plugin-angular": "*",
46
- "storybook": ">=8.6.0 || ^9.0.0 || next",
46
+ "storybook": ">=8.6.0 || ^9.0.0",
47
47
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0"
48
48
  },
49
49
  "engines": {
package/preset.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { dirname, join } from 'node:path';
1
+ import { dirname, join, resolve } from 'node:path';
2
2
  import { createRequire } from 'node:module';
3
3
  import { core as PresetCore } from '@storybook/angular/dist/preset.js';
4
4
  const require = createRequire(import.meta.url);
@@ -21,7 +21,7 @@ export const viteFinal = async (config, options) => {
21
21
  .filter((plugin) => !plugin.name.includes('analogjs'));
22
22
 
23
23
  // Merge custom configuration into the default config
24
- const { mergeConfig } = await import('vite');
24
+ const { mergeConfig, normalizePath } = await import('vite');
25
25
  const { default: angular } = await import('@analogjs/vite-plugin-angular');
26
26
  // @ts-ignore
27
27
  const framework = await options.presets.apply('framework');
@@ -35,7 +35,9 @@ export const viteFinal = async (config, options) => {
35
35
  '@angular/platform-browser',
36
36
  '@angular/platform-browser/animations',
37
37
  'tslib',
38
- 'zone.js',
38
+ ...(options?.angularBuilderOptions?.experimentalZoneless
39
+ ? []
40
+ : ['zone.js']),
39
41
  ],
40
42
  },
41
43
  plugins: [
@@ -54,6 +56,7 @@ export const viteFinal = async (config, options) => {
54
56
  ? framework.options?.inlineStylesExtension
55
57
  : 'css',
56
58
  }),
59
+ angularOptionsPlugin(options, { normalizePath }),
57
60
  ],
58
61
  define: {
59
62
  STORYBOOK_ANGULAR_OPTIONS: JSON.stringify({
@@ -63,5 +66,67 @@ export const viteFinal = async (config, options) => {
63
66
  },
64
67
  });
65
68
  };
69
+
70
+ function angularOptionsPlugin(options, { normalizePath }) {
71
+ return {
72
+ name: 'analogjs-storybook-options-plugin',
73
+ config() {
74
+ const loadPaths =
75
+ options?.angularBuilderOptions?.stylePreprocessorOptions?.loadPaths;
76
+ const sassOptions =
77
+ options?.angularBuilderOptions?.stylePreprocessorOptions?.sass;
78
+
79
+ if (Array.isArray(loadPaths)) {
80
+ return {
81
+ css: {
82
+ preprocessorOptions: {
83
+ scss: {
84
+ ...sassOptions,
85
+ loadPaths: loadPaths.map(
86
+ (loadPath) =>
87
+ `${resolve(options.angularBuilderContext.workspaceRoot, loadPath)}`,
88
+ ),
89
+ },
90
+ },
91
+ },
92
+ };
93
+ }
94
+
95
+ return;
96
+ },
97
+ transform(code, id) {
98
+ if (
99
+ normalizePath(id).endsWith(
100
+ normalizePath(`${options.configDir}/preview.ts`),
101
+ )
102
+ ) {
103
+ const imports = [];
104
+ const styles = options?.angularBuilderOptions?.styles;
105
+
106
+ if (Array.isArray(styles)) {
107
+ styles.forEach((style) => {
108
+ imports.push(style);
109
+ });
110
+ }
111
+
112
+ const zoneless = options?.angularBuilderOptions?.experimentalZoneless;
113
+
114
+ if (!zoneless) {
115
+ imports.push('zone.js');
116
+ }
117
+
118
+ return {
119
+ code: `
120
+ ${imports.map((extraImport) => `import '${extraImport}';`).join('\n')}
121
+ ${code}
122
+ `,
123
+ };
124
+ }
125
+
126
+ return;
127
+ },
128
+ };
129
+ }
130
+
66
131
  export { addons, previewAnnotations } from '@storybook/angular/dist/preset.js';
67
132
  //# sourceMappingURL=preset.js.map
@@ -69,6 +69,56 @@
69
69
  "type": "boolean",
70
70
  "description": "Experimental: Use zoneless change detection.",
71
71
  "default": false
72
+ },
73
+ "styles": {
74
+ "type": "array",
75
+ "description": "Global styles to be included in the build.",
76
+ "default": [],
77
+ "items": {
78
+ "type": "string"
79
+ }
80
+ },
81
+ "stylePreprocessorOptions": {
82
+ "description": "Options to pass to style preprocessors.",
83
+ "type": "object",
84
+ "properties": {
85
+ "loadPaths": {
86
+ "description": "Paths to include.",
87
+ "type": "array",
88
+ "items": {
89
+ "type": "string"
90
+ }
91
+ },
92
+ "sass": {
93
+ "description": "Options to pass to the sass preprocessor.",
94
+ "type": "object",
95
+ "properties": {
96
+ "fatalDeprecations": {
97
+ "description": "A set of deprecations to treat as fatal. If a deprecation warning of any provided type is encountered during compilation, the compiler will error instead. If a Version is provided, then all deprecations that were active in that compiler version will be treated as fatal.",
98
+ "type": "array",
99
+ "items": {
100
+ "type": "string"
101
+ }
102
+ },
103
+ "silenceDeprecations": {
104
+ "description": " A set of active deprecations to ignore. If a deprecation warning of any provided type is encountered during compilation, the compiler will ignore it instead.",
105
+ "type": "array",
106
+ "items": {
107
+ "type": "string"
108
+ }
109
+ },
110
+ "futureDeprecations": {
111
+ "description": "A set of future deprecations to opt into early. Future deprecations passed here will be treated as active by the compiler, emitting warnings as necessary.",
112
+ "type": "array",
113
+ "items": {
114
+ "type": "string"
115
+ }
116
+ }
117
+ },
118
+ "additionalProperties": false
119
+ }
120
+ },
121
+ "additionalProperties": false
72
122
  }
73
123
  },
74
124
  "additionalProperties": false
@@ -105,6 +105,56 @@
105
105
  "type": "boolean",
106
106
  "description": "Experimental: Use zoneless change detection.",
107
107
  "default": false
108
+ },
109
+ "styles": {
110
+ "type": "array",
111
+ "description": "Global styles to be included in the build.",
112
+ "default": [],
113
+ "items": {
114
+ "type": "string"
115
+ }
116
+ },
117
+ "stylePreprocessorOptions": {
118
+ "description": "Options to pass to style preprocessors.",
119
+ "type": "object",
120
+ "properties": {
121
+ "loadPaths": {
122
+ "description": "Paths to include.",
123
+ "type": "array",
124
+ "items": {
125
+ "type": "string"
126
+ }
127
+ },
128
+ "sass": {
129
+ "description": "Options to pass to the sass preprocessor.",
130
+ "type": "object",
131
+ "properties": {
132
+ "fatalDeprecations": {
133
+ "description": "A set of deprecations to treat as fatal. If a deprecation warning of any provided type is encountered during compilation, the compiler will error instead. If a Version is provided, then all deprecations that were active in that compiler version will be treated as fatal.",
134
+ "type": "array",
135
+ "items": {
136
+ "type": "string"
137
+ }
138
+ },
139
+ "silenceDeprecations": {
140
+ "description": " A set of active deprecations to ignore. If a deprecation warning of any provided type is encountered during compilation, the compiler will ignore it instead.",
141
+ "type": "array",
142
+ "items": {
143
+ "type": "string"
144
+ }
145
+ },
146
+ "futureDeprecations": {
147
+ "description": "A set of future deprecations to opt into early. Future deprecations passed here will be treated as active by the compiler, emitting warnings as necessary.",
148
+ "type": "array",
149
+ "items": {
150
+ "type": "string"
151
+ }
152
+ }
153
+ },
154
+ "additionalProperties": false
155
+ }
156
+ },
157
+ "additionalProperties": false
108
158
  }
109
159
  },
110
160
  "additionalProperties": false
@@ -18,7 +18,9 @@ const renderAnnotations = {
18
18
  function setProjectAnnotations(projectAnnotations) {
19
19
  return (0, index_mjs_1.setProjectAnnotations)([
20
20
  renderAnnotations,
21
- projectAnnotations,
21
+ ...(Array.isArray(projectAnnotations)
22
+ ? projectAnnotations
23
+ : [projectAnnotations]),
22
24
  ]);
23
25
  }
24
26
  //# sourceMappingURL=testing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.js","sourceRoot":"","sources":["../../../../../packages/storybook-angular/src/lib/testing.ts"],"names":[],"mappings":";;;AAWA,wCAMC;AAOD,sDASC;;AAhCD,wEAAkH;AAMlH,qGAA+E;AAElE,QAAA,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC;AAExC,KAAK,UAAU,cAAc,CAClC,OAAuC,EACvC,OAAoB;IAEpB,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;IACxB,MAAM,iBAAiB,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,iBAAiB,GAAG;IACxB,MAAM,EAAN,cAAM;IACN,cAAc;CACf,CAAC;AAEF,SAAgB,qBAAqB,CACnC,kBAE2C;IAE3C,OAAO,IAAA,iCAA6B,EAAC;QACnC,iBAAiB;QACjB,kBAAkB;KACnB,CAAkD,CAAC;AACtD,CAAC"}
1
+ {"version":3,"file":"testing.js","sourceRoot":"","sources":["../../../../../packages/storybook-angular/src/lib/testing.ts"],"names":[],"mappings":";;;AAWA,wCAMC;AAOD,sDAWC;;AAlCD,wEAAkH;AAMlH,qGAA+E;AAElE,QAAA,MAAM,GAAG,iBAAiB,CAAC,MAAM,CAAC;AAExC,KAAK,UAAU,cAAc,CAClC,OAAuC,EACvC,OAAoB;IAEpB,OAAO,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;IACxB,MAAM,iBAAiB,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC3D,CAAC;AAED,MAAM,iBAAiB,GAAG;IACxB,MAAM,EAAN,cAAM;IACN,cAAc;CACf,CAAC;AAEF,SAAgB,qBAAqB,CACnC,kBAE2C;IAE3C,OAAO,IAAA,iCAA6B,EAAC;QACnC,iBAAiB;QACjB,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,kBAAkB,CAAC;YACnC,CAAC,CAAC,kBAAkB;YACpB,CAAC,CAAC,CAAC,kBAAkB,CAAC,CAAC;KAC1B,CAAkD,CAAC;AACtD,CAAC"}