@financial-times/dotcom-build-sass
TypeScript icon, indicating that this package has built-in type declarations

11.2.1 • Public • Published

@financial-times/dotcom-build-sass

This package exports a Webpack plugin to configure it with a way to load and generate CSS files from Sass source code.

Getting started

This package is compatible with Node 12+ and is distributed on npm.

npm install --save-dev @financial-times/dotcom-build-sass

After installing the package you must add it to the list of plugins in your project's webpack.config.js configuration file:

+ const { PageKitSassPlugin } = require('@financial-times/dotcom-build-sass')

module.exports = {
  plugins: [
+    new PageKitSassPlugin()
  ]
}

Once setup, this plugin will enable you to use Sass files (.scss and .sass) as entry points into your source code.

const { PageKitSassPlugin } = require('@financial-times/dotcom-build-sass')

module.exports = {
   entry: {
      styles: path/to/styles.scss
   },
   plugins: [new PageKitSassPlugin()]
}

Scope

This plugin adds a rule to the Webpack configuration to handle .scss files. It first uses the sass-loader to transpile Sass source code, then sends the output through to the postcss-loader for optimisations, and finally the css-loader. The mini-css-extract-plugin is added to generate .css files and the webpack-fix-style-only-entries to clean up any empty JavaScript bundles.

Sass has been configured to find packages installed with npm by looking in the 'node_modules/@financial-times' directories. It can be configured to look in additional locations by passing the relevant paths to the plugin as absolute paths.

new PageKitSassPlugin({ includePaths: [path.resolve('./path-to-sass-files')] })

Please note that by default Sass will resolve all bare @import statements from the current working directory rather than relative to the file being processed. This means it will not find dependencies in nested node_modules directories.

PostCSS is configured with the Autoprefixer and cssnano transforms.

The CSS loader has @import and url() resolution disabled as these should be handled by Sass.

Options

Option Type Default Description
webpackImporter Boolean false See https://github.com/webpack-contrib/sass-loader#webpackimporter
additionalData String '' https://webpack.js.org/loaders/sass-loader/#additionaldata
includePaths String[] [] See https://sass-lang.com/documentation/js-api#includepaths
implementation sass|sass-embedded sass See https://webpack.js.org/loaders/sass-loader/#implementation

additionalData replaces prependData as of sass-loader v9. prependData is still supported in this package, but is deprecated.

Sass build monitoring

Sass build times are stored locally and remotely, where your project sets relevant API keys. Alternatively, you may turn both these features off using environment variable.

  • Local reporting: A running total of your local Sass build times are stored in a temporary file on your machine. This statistic is reported periodically for your interest, along with a prompt to support FT efforts to move away from Sass.
  • Alongside this, your local Sass build times are sent to the biz-ops metrics api, provided the below environment variables are set.
Environment Variable Required Default Description
FT_SASS_STATS_NOTICE no throttle How often to log Sass statistics out to terminal. One of throttle, never, always
FT_SASS_STATS_NOTICE_THROTTLE_SECONDS no 1800 How many seconds to wait between logging Sass statistics out to terminal.
FT_SASS_STATS_NOTICE_THROTTLE_PERCENTAGE no 30 A percentage increase in total Sass build time in which to log out statistics to the terminal regardless of time.
FT_SASS_STATS_MONITOR no off Set to on to send Sass build time statistics to biz-ops metrics api Requires FT_SASS_BIZ_OPS_API_KEY and FT_SASS_BIZ_OPS_SYSTEM_CODE.
FT_SASS_BIZ_OPS_API_KEY no `` A Biz-Ops Metrics API Key for your system.
FT_SASS_BIZ_OPS_SYSTEM_CODE no `` The biz-ops system code of your project. Use page-kit if your system does not have a biz-ops code yet.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
11.1.0-beta.00pre-release
0.6.50maintenance
11.2.1164latest

Version History

VersionDownloads (Last 7 Days)Published
11.2.1164
11.2.01
11.1.016
11.1.0-beta.00
11.0.58
11.0.46
11.0.31
11.0.20
11.0.10
11.0.01
11.0.0-beta.00
10.3.273
10.3.10
10.3.00
10.2.020
10.1.031
9.5.12
10.0.10
10.0.06
9.5.01
10.0.0-beta.01
9.4.11
9.4.015
9.3.410
8.2.62
9.3.334
9.3.20
9.3.10
9.3.00
9.2.10
9.2.00
9.1.10
9.1.00
9.0.31
9.0.20
9.0.10
8.2.50
8.2.40
8.2.30
9.0.0-beta.160
8.2.20
9.0.0-beta.150
9.0.0-beta.140
9.0.0-beta.130
9.0.0-beta.120
9.0.0-beta.110
9.0.0-beta.100
9.0.0-beta.90
9.0.0-beta.80
9.0.0-beta.70
8.2.18
9.0.0-beta.61
8.2.00
9.0.0-beta.50
9.0.0-beta.40
9.0.0-beta.30
9.0.0-beta.20
9.0.0-beta.10
8.1.04
8.0.00
7.3.51
7.3.45
7.3.30
7.3.20
7.3.10
7.3.00
7.2.78
7.2.60
7.2.50
7.2.40
7.1.40
7.1.30
7.1.10
7.1.00
7.0.00
6.0.21
6.0.10
6.0.00
5.1.00
5.0.00
4.2.00
4.1.00
4.0.00
3.0.00
2.6.20
2.6.10
2.6.00
2.5.20
2.5.10
2.4.00
2.3.00
2.2.10
2.2.07
2.1.10
2.1.0-pre.10
2.1.00
2.0.20
2.0.10
2.0.00
1.1.00
1.0.00
0.8.10
0.8.00
0.7.30
0.7.20
0.6.50
0.7.10
0.7.00
0.7.0-beta.20
0.7.0-beta.10
0.6.30
0.6.20
0.6.10
0.6.00
0.5.80
0.5.70
0.5.60
0.5.51
0.4.50
0.5.40
0.4.40
0.5.30
0.5.20
0.4.30
0.4.20
0.5.10
0.5.00
0.5.0-beta.30
0.5.0-beta.20
0.5.0-beta.10
0.4.10
0.3.50
0.3.40
0.3.30
0.3.20
0.3.10
0.3.00
0.2.30
0.2.20
0.2.10
0.2.00
0.1.40
0.1.30
0.1.20
0.1.10
0.1.00
0.0.40
0.0.30
0.0.20
0.0.10
0.0.1-test.20
0.0.1-test.10

Package Sidebar

Install

npm i @financial-times/dotcom-build-sass

Weekly Downloads

371

Version

11.2.1

License

MIT

Unpacked Size

197 kB

Total Files

9

Last publish

Collaborators

  • robgodfrey
  • robertboulton
  • seraph2000
  • hamza.samih
  • notlee
  • emmalewis
  • aendra
  • the-ft
  • rowanmanning
  • chee
  • alexwilson