Skip to content

Commit c3957d8

Browse files
Spencerspalgerelasticmachine
authored
[canvas/shareable_runtime] sync sass loaders with kbn/optimizer (#60653)
* [canvas/shareable_runtime] sync sass loaders with kbn/optimizer * limit sass options to those relevant in this context Co-authored-by: spalger <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent 182acdb commit c3957d8

File tree

2 files changed

+51
-5
lines changed

2 files changed

+51
-5
lines changed

x-pack/legacy/plugins/canvas/shareable_runtime/webpack.config.js

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
const path = require('path');
88
const webpack = require('webpack');
9+
const { stringifyRequest } = require('loader-utils'); // eslint-disable-line
910

1011
const {
1112
KIBANA_ROOT,
@@ -140,19 +141,63 @@ module.exports = {
140141
},
141142
{
142143
test: /\.scss$/,
143-
exclude: /\.module.(s(a|c)ss)$/,
144+
exclude: [/node_modules/, /\.module\.s(a|c)ss$/],
144145
use: [
145-
{ loader: 'style-loader' },
146-
{ loader: 'css-loader', options: { importLoaders: 2 } },
146+
{
147+
loader: 'style-loader',
148+
},
149+
{
150+
loader: 'css-loader',
151+
options: {
152+
sourceMap: !isProd,
153+
},
154+
},
147155
{
148156
loader: 'postcss-loader',
149157
options: {
158+
sourceMap: !isProd,
150159
config: {
151-
path: require.resolve('./postcss.config.js'),
160+
path: require.resolve('./postcss.config'),
161+
},
162+
},
163+
},
164+
{
165+
loader: 'resolve-url-loader',
166+
options: {
167+
// eslint-disable-next-line no-unused-vars
168+
join: (_, __) => (uri, base) => {
169+
if (!base) {
170+
return null;
171+
}
172+
173+
// manually force ui/* urls in legacy styles to resolve to ui/legacy/public
174+
if (uri.startsWith('ui/') && base.split(path.sep).includes('legacy')) {
175+
return path.resolve(KIBANA_ROOT, 'src/legacy/ui/public', uri.replace('ui/', ''));
176+
}
177+
178+
return null;
179+
},
180+
},
181+
},
182+
{
183+
loader: 'sass-loader',
184+
options: {
185+
// must always be enabled as long as we're using the `resolve-url-loader` to
186+
// rewrite `ui/*` urls. They're dropped by subsequent loaders though
187+
sourceMap: true,
188+
prependData(loaderContext) {
189+
return `@import ${stringifyRequest(
190+
loaderContext,
191+
path.resolve(KIBANA_ROOT, 'src/legacy/ui/public/styles/_styling_constants.scss')
192+
)};\n`;
193+
},
194+
webpackImporter: false,
195+
sassOptions: {
196+
outputStyle: 'nested',
197+
includePaths: [path.resolve(KIBANA_ROOT, 'node_modules')],
152198
},
153199
},
154200
},
155-
{ loader: 'sass-loader' },
156201
],
157202
},
158203
{

x-pack/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
"jest-cli": "^24.9.0",
143143
"jest-styled-components": "^7.0.0",
144144
"jsdom": "^15.2.1",
145+
"loader-utils": "^1.2.3",
145146
"madge": "3.4.4",
146147
"marge": "^1.0.1",
147148
"mocha": "^6.2.2",

0 commit comments

Comments
 (0)