mirror of
https://github.com/storybookjs/storybook.git
synced 2025-04-06 15:31:16 +08:00
Merge pull request #4343 from tomepejo/master
[improvement] Add support for sass type files
This commit is contained in:
commit
db8be4b156
28
app/angular/src/server/angular-cli_config.js
vendored
28
app/angular/src/server/angular-cli_config.js
vendored
@ -2,7 +2,12 @@ import path from 'path';
|
||||
import fs from 'fs';
|
||||
import { logger } from '@storybook/node-logger';
|
||||
import { TsconfigPathsPlugin } from 'tsconfig-paths-webpack-plugin';
|
||||
import { isBuildAngularInstalled, normalizeAssetPatterns } from './angular-cli_utils';
|
||||
import {
|
||||
isBuildAngularInstalled,
|
||||
normalizeAssetPatterns,
|
||||
filterOutStylingRules,
|
||||
getAngularCliParts,
|
||||
} from './angular-cli_utils';
|
||||
|
||||
function getTsConfigOptions(tsConfigPath) {
|
||||
const basicOptions = {
|
||||
@ -27,20 +32,6 @@ function getTsConfigOptions(tsConfigPath) {
|
||||
return basicOptions;
|
||||
}
|
||||
|
||||
function getAngularCliParts(cliWebpackConfigOptions) {
|
||||
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
|
||||
const ngCliConfigFactory = require('@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs');
|
||||
|
||||
try {
|
||||
return {
|
||||
cliCommonConfig: ngCliConfigFactory.getCommonConfig(cliWebpackConfigOptions),
|
||||
cliStyleConfig: ngCliConfigFactory.getStylesConfig(cliWebpackConfigOptions),
|
||||
};
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function getAngularCliWebpackConfigOptions(dirToSearch) {
|
||||
const fname = path.join(dirToSearch, 'angular.json');
|
||||
|
||||
@ -107,12 +98,9 @@ export function applyAngularCliWebpackConfig(baseConfig, cliWebpackConfigOptions
|
||||
|
||||
const { cliCommonConfig, cliStyleConfig } = cliParts;
|
||||
|
||||
// Don't use storybooks .css/.scss rules because we have to use rules created by @angular-devkit/build-angular
|
||||
// Don't use storybooks styling rules because we have to use rules created by @angular-devkit/build-angular
|
||||
// because @angular-devkit/build-angular created rules have include/exclude for global style files.
|
||||
const rulesExcludingStyles = baseConfig.module.rules.filter(
|
||||
rule =>
|
||||
!rule.test || (rule.test.toString() !== '/\\.css$/' && rule.test.toString() !== '/\\.scss$/')
|
||||
);
|
||||
const rulesExcludingStyles = filterOutStylingRules(baseConfig);
|
||||
|
||||
// cliStyleConfig.entry adds global style files to the webpack context
|
||||
const entry = {
|
||||
|
32
app/angular/src/server/angular-cli_utils.js
vendored
32
app/angular/src/server/angular-cli_utils.js
vendored
@ -23,6 +23,24 @@ function getAssetsParts(resolvedAssetPath, assetPath) {
|
||||
};
|
||||
}
|
||||
|
||||
function isStylingRule(rule) {
|
||||
const { test } = rule;
|
||||
|
||||
if (!test) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(test instanceof RegExp)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return test.test('.css') || test.test('.scss') || test.test('.sass');
|
||||
}
|
||||
|
||||
export function filterOutStylingRules(config) {
|
||||
return config.module.rules.filter(rule => !isStylingRule(rule));
|
||||
}
|
||||
|
||||
export function isBuildAngularInstalled() {
|
||||
try {
|
||||
require.resolve('@angular-devkit/build-angular');
|
||||
@ -32,6 +50,20 @@ export function isBuildAngularInstalled() {
|
||||
}
|
||||
}
|
||||
|
||||
export function getAngularCliParts(cliWebpackConfigOptions) {
|
||||
// eslint-disable-next-line global-require, import/no-extraneous-dependencies
|
||||
const ngCliConfigFactory = require('@angular-devkit/build-angular/src/angular-cli-files/models/webpack-configs');
|
||||
|
||||
try {
|
||||
return {
|
||||
cliCommonConfig: ngCliConfigFactory.getCommonConfig(cliWebpackConfigOptions),
|
||||
cliStyleConfig: ngCliConfigFactory.getStylesConfig(cliWebpackConfigOptions),
|
||||
};
|
||||
} catch (e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function normalizeAssetPatterns(assetPatterns, dirToSearch, sourceRoot) {
|
||||
if (!assetPatterns || !assetPatterns.length) {
|
||||
return [];
|
||||
|
@ -31,7 +31,7 @@ export function webpack(config, { configDir }) {
|
||||
exclude: /\.async\.html$/,
|
||||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
test: /\.s(c|a)ss$/,
|
||||
use: [require.resolve('raw-loader'), require.resolve('sass-loader')],
|
||||
},
|
||||
],
|
||||
|
Loading…
x
Reference in New Issue
Block a user