Skip to content

Commit b8f87d6

Browse files
committed
feat(index): allow passing custom loaders to be used by in the Views
1 parent 9b900e6 commit b8f87d6

File tree

1 file changed

+37
-41
lines changed

1 file changed

+37
-41
lines changed

src/index.js

+37-41
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,7 @@
1-
var path = require('upath');
2-
var ContextElementDependency = require('webpack/lib/dependencies/ContextElementDependency');
3-
var resolveTemplates = require('./build-resources');
4-
5-
function getPath(resolvedResource) {
6-
let input = resolvedResource.source;
7-
let lazy = resolvedResource.lazy;
8-
let bundle = resolvedResource.bundle;
9-
10-
const extension = path.extname(input);
11-
let output = '';
12-
13-
// for .css files force the request to the appropriate css loader (https://github.com/aurelia/webpack-plugin/issues/11#issuecomment-212578861)
14-
switch (extension) {
15-
case ".css":
16-
output += `!!css!`;
17-
break;
18-
case ".scss":
19-
output += `!!css!sass!`;
20-
break;
21-
case ".less":
22-
output += `!!css!less!`;
23-
break;
24-
case ".styl":
25-
output += `!!css!stylus!`;
26-
break;
27-
}
28-
29-
if (lazy || bundle)
30-
output += `bundle?`;
31-
if (lazy)
32-
output += `lazy`;
33-
if (lazy && bundle)
34-
output += `&`;
35-
if (bundle)
36-
output += `name=${bundle}`;
37-
if (lazy || bundle)
38-
output += `!`;
39-
40-
return `${output}${input}`;
41-
}
1+
const path = require('upath');
2+
const ContextElementDependency = require('webpack/lib/dependencies/ContextElementDependency');
3+
const resolveTemplates = require('./build-resources');
4+
const debug = require('debug')('webpack-plugin');
425

436
function handleError(error) {
447
console.error('Error processing templates', error.message);
@@ -52,9 +15,42 @@ class AureliaWebpackPlugin {
5215
options.root = options.root ? path.normalizeSafe(options.root) : path.dirname(module.parent.filename);
5316
options.src = options.src ? path.normalizeSafe(options.src) : path.resolve(options.root, 'src');
5417
options.resourceRegExp = options.resourceRegExp || /aurelia-loader-context/;
18+
options.customViewLoaders = Object.assign({
19+
'.css': ['css'],
20+
'.scss': ['css', 'sass'],
21+
'.less': ['css', 'less'],
22+
'.styl': ['css', 'stylus'],
23+
}, options.customViewLoaders || {});
5524

5625
this.options = options;
5726
}
27+
28+
getPath(resolvedResource) {
29+
let input = resolvedResource.source;
30+
let lazy = resolvedResource.lazy;
31+
let bundle = resolvedResource.bundle;
32+
33+
const extension = path.extname(input);
34+
let output = '';
35+
36+
// for .css files force the request to the appropriate css loader (https://github.com/aurelia/webpack-plugin/issues/11#issuecomment-212578861)
37+
if (this.options.customViewLoaders[extension]) {
38+
output += '!!' + this.options.customViewLoaders[extension].join('!') + '!';
39+
}
40+
41+
if (lazy || bundle)
42+
output += `bundle?`;
43+
if (lazy)
44+
output += `lazy`;
45+
if (lazy && bundle)
46+
output += `&`;
47+
if (bundle)
48+
output += `name=${bundle}`;
49+
if (lazy || bundle)
50+
output += `!`;
51+
52+
return `${output}${input}`;
53+
}
5854

5955
apply(compiler) {
6056
compiler.plugin('context-module-factory', cmf => {

0 commit comments

Comments
 (0)