Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implement a feature of defaultLang(#497) #500

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions lib/loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ try {

var rewriterInjectRE = /\b(css(?:-loader)?(?:\?[^!]+)?)(?:!|$)/

var defaultLang = {
template: 'html',
styles: 'css',
script: 'js'
}

// When extracting parts from the source vue file, we want to apply the
// loaders chained before vue-loader, but exclude some loaders that simply
// produces side effects such as linting. This is a hard-coded list and
Expand All @@ -57,6 +51,11 @@ module.exports = function (content) {
var query = loaderUtils.parseQuery(this.query)
var rawRequest = getRawRequest(this)
var options = this.options.__vueOptions__ = Object.assign({}, this.options.vue, this.vue, query)
var defaultLang = Object.assign({
template: 'html',
styles: 'css',
script: 'js'
}, options.defaultLang)

var filePath = this.resourcePath
var fileName = path.basename(filePath)
Expand Down Expand Up @@ -90,7 +89,7 @@ module.exports = function (content) {
function getRequire (type, part, index, scoped) {
return 'require(' +
getRequireString(type, part, index, scoped) +
')'
')'
}

function getRequireString (type, part, index, scoped) {
Expand All @@ -109,7 +108,7 @@ module.exports = function (content) {
function getRequireForImport (type, impt, scoped) {
return 'require(' +
getRequireForImportString(type, impt, scoped) +
')'
')'
}

function getRequireForImportString (type, impt, scoped) {
Expand Down Expand Up @@ -304,7 +303,7 @@ module.exports = function (content) {
// )
output += 'var Component = require(' +
loaderUtils.stringifyRequest(loaderContext, '!' + componentNormalizerPath) +
')(\n'
')(\n'

// <script>
output += ' /* script */\n '
Expand Down Expand Up @@ -358,17 +357,17 @@ module.exports = function (content) {
// check named exports
output +=
'if (Component.esModule && Object.keys(Component.esModule).some(function (key) {' +
'return key !== "default" && key !== "__esModule"' +
'return key !== "default" && key !== "__esModule"' +
'})) {' +
'console.error("named exports are not supported in *.vue files.")' +
'console.error("named exports are not supported in *.vue files.")' +
'}\n'
// check functional components used with templates
if (template) {
output +=
'if (Component.options.functional) {' +
'console.error("' +
'[vue-loader] ' + fileName + ': functional components are not ' +
'supported with templates, they should use render functions.' +
'console.error("' +
'[vue-loader] ' + fileName + ': functional components are not ' +
'supported with templates, they should use render functions.' +
'")}\n'
}
}
Expand Down Expand Up @@ -418,19 +417,19 @@ module.exports = function (content) {
// update
if (cssModules) {
output +=
' if (module.hot.data.cssModules && JSON.stringify(module.hot.data.cssModules) !== JSON.stringify(cssModules)) {\n' +
' delete Component.options._Ctor\n' +
' }\n'
' if (module.hot.data.cssModules && JSON.stringify(module.hot.data.cssModules) !== JSON.stringify(cssModules)) {\n' +
' delete Component.options._Ctor\n' +
' }\n'
}
output +=
' hotAPI.reload("' + moduleId + '", Component.options)\n' +
' }\n'
if (cssModules) {
// save cssModules
output +=
' module.hot.dispose(function (data) {\n' +
' data.cssModules = cssModules\n' +
' })\n'
' module.hot.dispose(function (data) {\n' +
' data.cssModules = cssModules\n' +
' })\n'
}
output += '})()}\n'
}
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/default-lang.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<style>
.msg
color red
</style>
14 changes: 14 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -697,4 +697,18 @@ describe('vue-loader', function () {
done()
})
})

it('default lang', function (done) {
test({
entry: './test/fixtures/default-lang.vue',
vue: {
defaultLang: {
styles: 'stylus'
}
}
}, function (window) {
expect(window.document.querySelectorAll('style')[0].textContent).to.contain('.msg {\n color: #f00;\n}')
done()
})
})
})