Skip to content

Commit

Permalink
bootstrapPath configurable via query string #255
Browse files Browse the repository at this point in the history
  • Loading branch information
justin808 committed Feb 26, 2017
1 parent e7cc4c2 commit 2857d2b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 17 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ All notable changes to this project will be documented in this file. Items under

Contributors: please follow the recommendations outlined at [keepachangelog.com](http://keepachangelog.com/). Please use the existing headings and styling as a guide, and add a link for the version diff at the bottom of the file. Also, please update the `Unreleased` link to compare to the latest release version.

## Unreleased
##### Added
- Make `bootstrap`/`bootstrap-sass` path configurable so that it can be found when `bootstrap-loader` is symlinked in development. [#255](https://github.com/shakacode/bootstrap-loader/pull/255) by [vjpr](https://github.com/vjpr).

## [2.0.0.beta.21] - 2017-02-16
##### Updates
- Update Example Dependencies [#261](https://github.com/shakacode/bootstrap-loader/pull/261) and [#259](https://github.com/shakacode/bootstrap-loader/pull/259) by [judahmeek](https://github.com/judahmeek)
Expand All @@ -15,7 +19,6 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
##### Fixed
- Allow `styleLoaders` config with only `env` config. [#227](https://github.com/shakacode/bootstrap-loader/pull/227) by [bertho-zero](https://github.com/bertho-zero).


## [2.0.0.beta.17] - 2016-12-04
##### Added
- Allow `styleLoaders` to depend on the environment variable `NODE_ENV` [#222](https://github.com/shakacode/bootstrap-loader/pull/222) by [bertho-zero](https://github.com/bertho-zero).
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,18 @@ And in your `./config/sass-resources.scss`:

You can then use mixins and variables from Bootstrap in your own code.

### Using a custom location for bootstrap module

By default, `bootstrap-loader` will try to resolve `bootstrap` from where `bootstrap-loader` has been installed. In [certain situations](https://github.com/shakacode/bootstrap-loader/issues/254) (e.g. npm linking, using a custom package installer) it may not be resolvable. In this case, you can pass in the location manually.

```js
require('bootstrap-loader?bootstrapPath=/path/to/bootstrap');
// or
entry: [ 'bootstrap-loader?bootstrapPath=/path/to/bootstrap', './app' ]
```

## Contributing
See [Contributing](CONTRIBUTING.md) to get started.

Expand Down
13 changes: 3 additions & 10 deletions node_package/tests/utils/buildExtractStylesLoader.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import test from 'tape';
import path from 'path';
import fs from 'fs';
import buildExtractStylesLoader from '../../../src/utils/buildExtractStylesLoader';

test('buildExtractStylesLoader throws error if ary doesnt have "style-" at ary[0]', (assert) => {
Expand All @@ -12,18 +13,10 @@ your 'styleLoaders' array starts with 'style' or 'isomorphic-style' at index 0.

test('buildExtractStylesLoader runs as expected', (assert) => {
assert.equals(buildExtractStylesLoader(['style-loader', 'url-loader', 'css-loader']),
path.join(
`${__dirname}`,
'../../../node_modules/extract-text-webpack-plugin' +
'/loader.js?{"omit":1,"remove":true}!style-loader!url-loader!css-loader!',
),
`${fs.realpathSync(path.join(__dirname, '../../../node_modules/extract-text-webpack-plugin'))}/loader.js?{"omit":1,"remove":true}!style-loader!url-loader!css-loader!`,
);
assert.equals(buildExtractStylesLoader(['isomorphic-style-loader', 'url-loader', 'css-loader']),
path.join(
`${__dirname}`,
'../../../node_modules/extract-text-webpack-plugin' +
'/loader.js?{"omit":1,"remove":true}!isomorphic-style-loader!url-loader!css-loader!',
),
`${fs.realpathSync(path.join(__dirname, '../../../node_modules/extract-text-webpack-plugin'))}/loader.js?{"omit":1,"remove":true}!isomorphic-style-loader!url-loader!css-loader!`,
);
assert.end();
});
13 changes: 7 additions & 6 deletions src/bootstrap.loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = function() {};
module.exports.pitch = function(source) {
if (this.cacheable) this.cacheable();

const { extractStyles, configFilePath } = loaderUtils.getOptions(this) || {};
const { extractStyles, configFilePath, bootstrapPath } = loaderUtils.getOptions(this) || {};

if (configFilePath) {
const fullPathToUserConfig = path.resolve(__dirname, configFilePath);
Expand Down Expand Up @@ -107,13 +107,14 @@ module.exports.pitch = function(source) {

logger.debug('Using Bootstrap module:', bootstrapNPMModule);

config.bootstrapPath = resolveModule(bootstrapNPMModule);
config.bootstrapPath = bootstrapPath || resolveModule(bootstrapNPMModule);
logger.debug(`Bootstrap module location (abs): ${config.bootstrapPath}`);
if (!config.bootstrapPath) {
throw new Error(`
Could not find bootstrap version: '${bootstrapVersion}'. Did you install it?
The package is 'bootstrap' for bootstrap v4 and 'bootstrap-sass' for v3.
`);
let msg = `Could not resolve module '${bootstrapNPMModule}' which must be installed when bootstrap version is configured to v${bootstrapVersion}.
You must install 'bootstrap' for bootstrap v4 or 'bootstrap-sass' for bootstrap v3.
You can also specify the location manually by specifying 'bootstrapPath' in bootstrap-loader's query string.
See https://github.com/shakacode/bootstrap-loader/blob/master/README.md#usage.`;
throw new Error(msg);
}

config.bootstrapRelPath = path.relative(this.context, config.bootstrapPath);
Expand Down

0 comments on commit 2857d2b

Please sign in to comment.