@financial-times/dotcom-build-sass 7.3.1 → 7.3.2
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/package.json +3 -2
- package/src/index.ts +127 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@financial-times/dotcom-build-sass",
|
3
|
-
"version": "7.3.
|
3
|
+
"version": "7.3.2",
|
4
4
|
"description": "",
|
5
5
|
"main": "dist/node/index.js",
|
6
6
|
"types": "src/index.ts",
|
@@ -40,7 +40,8 @@
|
|
40
40
|
"npm": "7.x || 8.x"
|
41
41
|
},
|
42
42
|
"files": [
|
43
|
-
"dist/"
|
43
|
+
"dist/",
|
44
|
+
"src/"
|
44
45
|
],
|
45
46
|
"repository": {
|
46
47
|
"type": "git",
|
package/src/index.ts
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
import StylesOnlyPlugin from 'webpack-fix-style-only-entries'
|
2
|
+
import MiniCssExtractPlugin from 'mini-css-extract-plugin'
|
3
|
+
import type webpack from 'webpack'
|
4
|
+
|
5
|
+
export type TPluginOptions = {
|
6
|
+
includePaths?: string[]
|
7
|
+
prependData?: string
|
8
|
+
webpackImporter?: boolean
|
9
|
+
}
|
10
|
+
|
11
|
+
export class PageKitSassPlugin {
|
12
|
+
includePaths: string[]
|
13
|
+
prependData: string
|
14
|
+
webpackImporter: boolean
|
15
|
+
|
16
|
+
constructor({ includePaths = [], prependData = '', webpackImporter }: TPluginOptions = {}) {
|
17
|
+
this.includePaths = includePaths
|
18
|
+
this.prependData = prependData
|
19
|
+
this.webpackImporter = webpackImporter
|
20
|
+
}
|
21
|
+
|
22
|
+
apply(compiler: webpack.Compiler) {
|
23
|
+
const sassLoaderOptions = {
|
24
|
+
// This enables the use of enhanced-resolve for @import statements prefixed with ~
|
25
|
+
// but we don't usually use this and disabling it can speed up builds by up to 20%.
|
26
|
+
webpackImporter: this.webpackImporter,
|
27
|
+
// Prefer `dart-sass`.
|
28
|
+
implementation: require('sass'),
|
29
|
+
// Prepends SCSS code before the actual entry file.
|
30
|
+
// Introduced to maintain snappy grid after n-ui-foundations removed it as the default.
|
31
|
+
// Once user-facing apps and components move away from using snappy grid then this can be removed.
|
32
|
+
prependData: this.prependData,
|
33
|
+
sassOptions: {
|
34
|
+
// Disable formatting so that we don't spend time pretty printing
|
35
|
+
outputStyle: 'compressed',
|
36
|
+
// Enable Sass to @import source files from installed dependencies
|
37
|
+
includePaths: ['bower_components', 'node_modules', ...this.includePaths]
|
38
|
+
}
|
39
|
+
}
|
40
|
+
|
41
|
+
const autoprefixerOptions = {
|
42
|
+
// https://github.com/browserslist/browserslist
|
43
|
+
overrideBrowserslist: ['last 1 Chrome versions', 'Safari >= 13', 'ff ESR', 'last 1 Edge versions'],
|
44
|
+
grid: true
|
45
|
+
}
|
46
|
+
|
47
|
+
// https://cssnano.co/guides/optimisations
|
48
|
+
const cssnanoOptions = {
|
49
|
+
preset: [
|
50
|
+
'default',
|
51
|
+
{
|
52
|
+
// disable reduceInitial optimisation as `initial` is not supported in IE11
|
53
|
+
// https://github.com/cssnano/cssnano/issues/721
|
54
|
+
// https://developer.mozilla.org/en-US/docs/Web/CSS/initial
|
55
|
+
reduceInitial: false
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}
|
59
|
+
|
60
|
+
const postcssLoaderOptions = {
|
61
|
+
postcssOptions: {
|
62
|
+
plugins: [
|
63
|
+
// Add vendor prefixes automatically using data from Can I Use
|
64
|
+
// https://github.com/postcss/autoprefixer
|
65
|
+
require('autoprefixer')(autoprefixerOptions),
|
66
|
+
// Ensure that the final result is as small as possible. This can
|
67
|
+
// de-duplicate rule-sets which is useful if $o-silent-mode is toggled.
|
68
|
+
// https://github.com/cssnano/cssnano
|
69
|
+
require('cssnano')(cssnanoOptions)
|
70
|
+
]
|
71
|
+
},
|
72
|
+
implementation: require('postcss')
|
73
|
+
}
|
74
|
+
|
75
|
+
const cssLoaderOptions = {
|
76
|
+
// Allow css-loader to resolve @import because the sass-loader
|
77
|
+
// does not successfully resolve files with a .css extension.
|
78
|
+
import: true,
|
79
|
+
// Disable Webpack from resolving url() because we do not
|
80
|
+
// currently use this functionality.
|
81
|
+
url: false
|
82
|
+
}
|
83
|
+
|
84
|
+
const miniCssExtractPluginOptions = {
|
85
|
+
// only include content hash in filename when compiling production assets
|
86
|
+
filename: compiler.options.mode === 'development' ? '[name].css' : '[name].[contenthash:12].css'
|
87
|
+
}
|
88
|
+
|
89
|
+
// This plugin prevents empty JS bundles being created for CSS entry points
|
90
|
+
// https://github.com/fqborges/webpack-fix-style-only-entries
|
91
|
+
const stylesOnlyPluginOptions = {
|
92
|
+
silent: true
|
93
|
+
}
|
94
|
+
|
95
|
+
compiler.options.module.rules.push({
|
96
|
+
test: [/\.sass|scss$/],
|
97
|
+
use: [
|
98
|
+
// Extracts CSS into separate, non-JS files
|
99
|
+
// https://github.com/webpack-contrib/mini-css-extract-plugin
|
100
|
+
{
|
101
|
+
loader: MiniCssExtractPlugin.loader
|
102
|
+
},
|
103
|
+
// Add support for handling .css files
|
104
|
+
// https://github.com/webpack-contrib/css-loader
|
105
|
+
{
|
106
|
+
loader: require.resolve('css-loader'),
|
107
|
+
options: cssLoaderOptions
|
108
|
+
},
|
109
|
+
// Enable use of PostCSS for CSS postprocessing
|
110
|
+
// https://github.com/postcss/postcss-loader
|
111
|
+
{
|
112
|
+
loader: require.resolve('postcss-loader'),
|
113
|
+
options: postcssLoaderOptions
|
114
|
+
},
|
115
|
+
// Enable use of Sass for CSS preprocessing
|
116
|
+
// https://github.com/webpack-contrib/sass-loader
|
117
|
+
{
|
118
|
+
loader: require.resolve('sass-loader'),
|
119
|
+
options: sassLoaderOptions
|
120
|
+
}
|
121
|
+
]
|
122
|
+
})
|
123
|
+
|
124
|
+
new StylesOnlyPlugin(stylesOnlyPluginOptions).apply(compiler)
|
125
|
+
new MiniCssExtractPlugin(miniCssExtractPluginOptions).apply(compiler)
|
126
|
+
}
|
127
|
+
}
|