Skip to content

Commit d8327df

Browse files
authored
Minimal changes necessary for Webpack 5 compatibility (#401)
1 parent a7b6a0d commit d8327df

7 files changed

Lines changed: 21 additions & 50 deletions

File tree

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
55

66
## [Unreleased]
77
*Please add entries here for your pull requests.*
8+
#### Fixed
9+
- Now compatible with Webpack 5. Removed relative bootstraprc paths & addition of `sourceMap` to `sass-loader` querystring [PR 401](https://github.com/shakacode/bootstrap-loader/pull/401) by [judahmeek](https://github.com/judahmeek).
810

911
## [3.0.3] - 2019-03-27
1012
#### Fixed

node_package/tests/utils/processStyleLoaders.test.js

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,6 @@ test('processStyleLoaders throws an error if given parameter is not an array', a
88
assert.end();
99
});
1010

11-
test('processStyleLoaders throws an error if given array does not include "sass"', assert => {
12-
assert.throws(() => {
13-
processStyleLoaders({ loaders: ['url'] });
14-
}, /can't find 'sass-loader'./);
15-
assert.end();
16-
});
17-
1811
test('processStyleLoaders works as expected', assert => {
1912
assert.deepEquals(
2013
processStyleLoaders({
@@ -27,7 +20,7 @@ test('processStyleLoaders works as expected', assert => {
2720
processStyleLoaders({
2821
loaders: ['other', 'sass'],
2922
}),
30-
['other', 'resolve-url-loader', 'sass-loader?sourceMap'],
23+
['other', 'resolve-url-loader', 'sass-loader'],
3124
);
3225
assert.deepEquals(
3326
processStyleLoaders({
@@ -41,7 +34,7 @@ test('processStyleLoaders works as expected', assert => {
4134
loaders: ['other', 'sass'],
4235
disableResolveUrlLoader: true,
4336
}),
44-
['other', 'sass-loader?sourceMap'],
37+
['other', 'sass-loader'],
4538
);
4639
assert.deepEquals(
4740
processStyleLoaders({
@@ -56,7 +49,7 @@ test('processStyleLoaders works as expected', assert => {
5649
processStyleLoaders({
5750
loaders: ['other', 'sass?other'],
5851
}),
59-
['other', 'resolve-url-loader', 'sass-loader?other&sourceMap'],
52+
['other', 'resolve-url-loader', 'sass-loader?other'],
6053
);
6154
assert.deepEquals(
6255
processStyleLoaders({
@@ -70,7 +63,7 @@ test('processStyleLoaders works as expected', assert => {
7063
loaders: ['other', 'sass?other'],
7164
disableResolveUrlLoader: true,
7265
}),
73-
['other', 'sass-loader?other&sourceMap'],
66+
['other', 'sass-loader?other'],
7467
);
7568
assert.deepEquals(
7669
processStyleLoaders({
@@ -92,13 +85,13 @@ test('processStyleLoaders works as expected', assert => {
9285
processStyleLoaders({
9386
loaders: ['sass', 'sass-resources'],
9487
}),
95-
['resolve-url-loader', 'sass-loader?sourceMap', 'sass-resources'],
88+
['resolve-url-loader', 'sass-loader', 'sass-resources'],
9689
);
9790
assert.deepEquals(
9891
processStyleLoaders({
9992
loaders: ['sass-loader', 'sass-resources-loader'],
10093
}),
101-
['resolve-url-loader', 'sass-loader?sourceMap', 'sass-resources-loader'],
94+
['resolve-url-loader', 'sass-loader', 'sass-resources-loader'],
10295
);
10396
assert.end();
10497
});

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@
3939
"css-loader": "*",
4040
"mini-css-extract-plugin": ">=0.4.0",
4141
"node-sass": "*",
42+
"sass": "*",
4243
"resolve-url-loader": "*",
4344
"sass-loader": "*",
4445
"url-loader": "*",
45-
"webpack": ">=4.0.0"
46+
"webpack": ">=5.0.0"
4647
},
4748
"dependencies": {
4849
"chalk": "2.4.2",
@@ -70,6 +71,6 @@
7071
"prettier": "1.12.1",
7172
"tap-spec": "^4.1.2",
7273
"tape": "4.9.0",
73-
"webpack": "4.8.1"
74+
"webpack": "^5"
7475
}
7576
}

src/bootstrap.scripts.loader.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ module.exports = function() {
1414
logger.debug('Scripts input config:', '\n', this.query);
1515

1616
const config = loaderUtils.getOptions(this) || {};
17-
const { scripts, bootstrapVersion, bootstrapRelPath } = config;
17+
const { scripts, bootstrapVersion, bootstrapPath } = config;
1818

19-
const processedScripts = processModules(scripts, bootstrapVersion, bootstrapRelPath, true);
19+
const processedScripts = processModules(scripts, bootstrapVersion, bootstrapPath, true);
2020

2121
const scriptsOutput = processedScripts.map(script => `${script}\n`).join('');
2222

src/bootstrap.styles.loader.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = function() {
2020
const bootstrapVersion = parseInt(config.bootstrapVersion, 10);
2121
const {
2222
styles,
23-
bootstrapRelPath,
23+
bootstrapPath,
2424
useCustomIconFontPath,
2525
preBootstrapCustomizations,
2626
bootstrapCustomizations,
@@ -30,28 +30,28 @@ module.exports = function() {
3030
const processedStyles = [];
3131

3232
if (styles.indexOf('mixins') > -1) {
33-
processedStyles.push(createBootstrapImport('mixins', bootstrapVersion, bootstrapRelPath));
33+
processedStyles.push(createBootstrapImport('mixins', bootstrapVersion, bootstrapPath));
3434
}
3535

3636
if (preBootstrapCustomizations) {
3737
processedStyles.push(createUserImport(preBootstrapCustomizations, this));
3838
}
3939

4040
if (bootstrapVersion === 4) {
41-
processedStyles.push(createBootstrapImport('functions', bootstrapVersion, bootstrapRelPath));
41+
processedStyles.push(createBootstrapImport('functions', bootstrapVersion, bootstrapPath));
4242
}
4343

44-
processedStyles.push(createBootstrapImport('variables', bootstrapVersion, bootstrapRelPath));
44+
processedStyles.push(createBootstrapImport('variables', bootstrapVersion, bootstrapPath));
4545

4646
if (bootstrapVersion === 3 && !useCustomIconFontPath) {
47-
processedStyles.push(`$icon-font-path: "${getFontsPath(bootstrapRelPath, this)}";`);
47+
processedStyles.push(`$icon-font-path: "${getFontsPath(bootstrapPath, this)}";`);
4848
}
4949

5050
if (bootstrapCustomizations) {
5151
processedStyles.push(createUserImport(bootstrapCustomizations, this));
5252
}
5353

54-
const bootstrapStyles = processModules(styles, bootstrapVersion, bootstrapRelPath);
54+
const bootstrapStyles = processModules(styles, bootstrapVersion, bootstrapPath);
5555
const userStyles = appStyles ? createUserImport(appStyles, this) : '';
5656

5757
const stylesOutput = processedStyles

src/utils/getFontsPath.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path';
33
/**
44
* Builds path to Bootstrap fonts
55
*
6-
* @param {string} bootstrapRelPath
6+
* @param {string} bootstrapPath
77
* @returns {string}
88
*/
9-
export default bootstrapRelPath => path.join(bootstrapRelPath, 'assets', 'fonts', 'bootstrap/');
9+
export default bootstrapPath => path.join(bootstrapPath, 'assets', 'fonts', 'bootstrap/');

src/utils/processStyleLoaders.js

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -41,31 +41,6 @@ Default is ['style', 'css', 'sass']
4141
const sassLoader = loadersWithSuffix.find(loader => sassLoaderRegExp.test(loader));
4242
const sassLoaderIndex = loadersWithSuffix.indexOf(sassLoader);
4343

44-
if (!disableSassSourceMap) {
45-
if (!sassLoader) {
46-
throw new Error(`
47-
I can't find 'sass-loader'.
48-
Add it to array of loaders in .bootstraprc.
49-
`);
50-
}
51-
52-
const sassLoaderQuery = sassLoader.split('?')[1];
53-
54-
// We need to check if user's loader already contains sourceMap param
55-
// And if it's not there - inject it
56-
let sassLoaderWithSourceMap;
57-
if (sassLoaderQuery) {
58-
sassLoaderWithSourceMap = sassLoaderQuery.includes('sourceMap')
59-
? sassLoader
60-
: `${sassLoader}&sourceMap`;
61-
} else {
62-
sassLoaderWithSourceMap = `${sassLoader}?sourceMap`;
63-
}
64-
65-
// eslint-disable-next-line no-param-reassign
66-
loadersWithSuffix[sassLoaderIndex] = sassLoaderWithSourceMap;
67-
}
68-
6944
if (!disableResolveUrlLoader) {
7045
const resolveUrlLoaderRegExp = getLoaderRegExp('resolve-url');
7146
const resolveUrlLoader = loadersWithSuffix.find(loader => resolveUrlLoaderRegExp.test(loader));

0 commit comments

Comments
 (0)