Skip to content

Commit 5914a96

Browse files
committed
support scoped
1 parent 5bd3972 commit 5914a96

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ to support that output directory structure, your webpack config maybe like this:
4949
5050
```js
5151
{
52-
test: /\.(png|jpe?g|gif|svg)(\?\S*)?$/,
52+
test: /\.(png|jpe?g|gif|svg)(\?\S*)?$/,
5353
use: [{ loader: 'file-loader', options: { publicPath: '../', name: 'images/[name].[ext]?[hash]' }]
5454
}
5555
```
@@ -70,7 +70,7 @@ your webpack config can be like this:
7070
7171
```js
7272
{
73-
test: /\.(png|jpe?g|gif|svg)(\?\S*)?$/,
73+
test: /\.(png|jpe?g|gif|svg)(\?\S*)?$/,
7474
use: [{ loader: 'vue-asset-loader', options: { publicPath: '', publicStylePath: '../', name: 'images/[name].[ext]?[hash]' }]
7575
}
7676
```

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@ function handlePath (path, url) {
55
else if (path.endsWith('/')) return path + url;
66
else return path + '/' + url;
77
}
8-
let originPublicPath = undefined;
8+
var originPublicPath = undefined;
9+
var REGX = /(?:\=|\.)(?:scss|sass|less|styl|stylus|css)(?:&scoped=true)?&?$/;
910
module.exports = function loader () {
10-
let options = loaderUtils.getOptions(this) || {};
11+
var options = loaderUtils.getOptions(this) || {};
1112
if (options.publicStylePath) {
1213
if (originPublicPath === undefined) originPublicPath = options.publicPath;
13-
let _query = this._compilation.name;
14+
var _query = this._compilation.name;
1415
options.publicPath = function (url) {
15-
if (_query && /(?:\=|\.)(?:scss|less|styl|stylus|css)&?$/.test(_query)) return handlePath(options.publicStylePath, url);
16+
if (_query && REGX.test(_query)) return handlePath(options.publicStylePath, url);
1617
else return handlePath(originPublicPath, url);
1718
};
1819
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-asset-loader",
3-
"version": "0.1.4",
3+
"version": "0.1.5",
44
"description": "a file-loader for Vue solve the image relative path issues when HTML and CSS not in the same directory",
55
"main": "index.js",
66
"scripts": {

0 commit comments

Comments
 (0)