Skip to content

Commit d413556

Browse files
author
cenzhende
committed
v1.0.0
1 parent e95431d commit d413556

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

lib/loader.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
var fs = require('fs')
22
var path = require('path')
33
var parse = require('./parse')
4+
var loaderUtils = require('loader-utils')
45

56
module.exports = function (content) {
67
var filePath = this.resourcePath
7-
var options = resolveOptions(this.options)
8+
var options = resolveOptions(loaderUtils.getOptions(this))
89
var parts = parse(content, filePath)
910
var output = content
1011

@@ -76,7 +77,7 @@ function fileExistsSync (filePath) {
7677
}
7778

7879
function resolveOptions (config) {
79-
var options = config.vueAutoImport || {}
80+
var options = config || {}
8081

8182
options.scoped = !!options.scoped
8283

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-auto-import-loader",
3-
"version": "0.1.2",
3+
"version": "1.0.0",
44
"description": "Auto import template / style / script for *.vue file.",
55
"main": "index.js",
66
"scripts": {
@@ -23,6 +23,7 @@
2323
"homepage": "https://github.com/WEBuster/vue-auto-import-loader#readme",
2424
"dependencies": {
2525
"hash-sum": "^1.0.2",
26+
"loader-utils": "^1.0.2",
2627
"lru-cache": "^4.0.1",
2728
"parse5": "^2.2.0"
2829
},
@@ -31,6 +32,6 @@
3132
"mocha": "^3.0.2",
3233
"raw-loader": "^0.5.1",
3334
"rimraf": "^2.5.4",
34-
"webpack": "^1.13.2"
35+
"webpack": "^2.2.1"
3536
}
3637
}

test/test.js

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,22 @@ var expect = require('chai').expect
88
describe('vue-auto-import-loader', function () {
99

1010
var outputDir = path.resolve(__dirname, './output')
11-
var loaderPath = 'raw!' + path.resolve(__dirname, '../')
11+
var loaderPath = path.resolve(__dirname, '..')
1212
var globalConfig = {
1313
output: {
1414
path: outputDir,
1515
filename: 'test.build.vue'
1616
},
17+
resolveLoader: {
18+
alias: {
19+
'vue-auto-import-loader': loaderPath
20+
}
21+
},
1722
module: {
18-
loaders: [
23+
rules: [
1924
{
2025
test: /\.vue$/,
21-
loader: loaderPath
26+
use: ['raw-loader', 'vue-auto-import-loader']
2227
}
2328
]
2429
}
@@ -98,12 +103,25 @@ describe('vue-auto-import-loader', function () {
98103
it('blank-specific-name', function (done) {
99104
test({
100105
entry: './test/fixtures/blank-specific-name/blank.vue',
101-
vueAutoImport: {
102-
files: {
103-
template: 'template.html',
104-
style: 'style.css',
105-
script: 'script.js'
106-
}
106+
module: {
107+
rules: [
108+
{
109+
test: /\.vue$/,
110+
use: [
111+
'raw-loader',
112+
{
113+
loader: 'vue-auto-import-loader',
114+
options: {
115+
files: {
116+
template: 'template.html',
117+
style: 'style.css',
118+
script: 'script.js'
119+
}
120+
}
121+
}
122+
]
123+
}
124+
]
107125
}
108126
}, function (fragment) {
109127
var typeList = []
@@ -166,8 +184,21 @@ describe('vue-auto-import-loader', function () {
166184
it('scoped', function (done) {
167185
test({
168186
entry: './test/fixtures/scoped/scoped.vue',
169-
vueAutoImport: {
170-
scoped: true
187+
module: {
188+
rules: [
189+
{
190+
test: /\.vue$/,
191+
use: [
192+
'raw-loader',
193+
{
194+
loader: 'vue-auto-import-loader',
195+
options: {
196+
scoped: true
197+
}
198+
}
199+
]
200+
}
201+
]
171202
}
172203
}, function (fragment) {
173204
var node = fragment.childNodes[0]

0 commit comments

Comments
 (0)