Skip to content

Commit e047221

Browse files
committed
firt commit
1 parent e88efbe commit e047221

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
*.iml
2+
.DS_Store
3+
.idea/
4+
node_modules/
5+
npm-debug.log*
6+
.vscode/

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
"# vue-file-loader"
2+
3+
this is a file-loader wrapper for Vue and Webpack, solve the image relative path issues when HTML and CSS are not in the same directory.
4+

index.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
var loaderUtils = require('loader-utils');
2+
function handlePath (path, url) {
3+
if (!path) return url;
4+
if (typeof path === 'function') return path(url);
5+
else if (path.endsWith('/')) return path + url;
6+
else return path + '/' + url;
7+
}
8+
let originPublicPath = undefined;
9+
module.exports = function loader (content) {
10+
let options = loaderUtils.getOptions(this) || {};
11+
if (options.publicStylePath) {
12+
if (originPublicPath === undefined) originPublicPath = options.publicPath;
13+
let _query = this._compilation.name;
14+
options.publicPath = function (url) {
15+
if (_query && /(?:\=|\.)(?:scss|css)$/.test(_query)) return handlePath(options.publicStylePath, url);
16+
else return handlePath(originPublicPath, url);
17+
};
18+
}
19+
20+
const fileLoader = require('file-loader');
21+
return fileLoader.call(this, content);
22+
};

package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "vue-file-loader",
3+
"version": "0.1.0",
4+
"description": "a file-loader for Vue solve the image relative path issues when HTML and CSS not in the same directory",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/gxlmyacc/vue-file-loader.git"
12+
},
13+
"keywords": [
14+
"vue-file-loader",
15+
"file-loader",
16+
"vue",
17+
"webpack"
18+
],
19+
"author": "gxlmyacc",
20+
"license": "MIT",
21+
"bugs": {
22+
"url": "https://github.com/gxlmyacc/vue-file-loader/issues"
23+
},
24+
"homepage": "https://github.com/gxlmyacc/vue-file-loader#readme",
25+
"engines": {
26+
"node": ">= 6.9.0 || >= 8.9.0"
27+
},
28+
"dependencies": {
29+
"loader-utils": "^1.1.0"
30+
},
31+
"peerDependencies": {
32+
"webpack": "^3.0.0 || ^4.0.0"
33+
},
34+
"devDependencies": {
35+
"file-loader": "^1.1.11"
36+
}
37+
}

0 commit comments

Comments
 (0)