Comments (14)
@sjoerdvisscher is there any particular reason for the -!
prefix here?
from vue-loader.
No, I just copied what multi-loader
is doing: https://github.com/webpack/multi-loader/blob/master/index.loader.js#L6
from vue-loader.
Weird, the docs say: adding -! to a request will disable configured preLoaders and loaders but not the postLoaders
from vue-loader.
I think loaderUtils.stringifyRequest
breaks the -!
.
@OEvgeny Does it work if you replace it with JSON.stringify
?
from vue-loader.
@sjoerdvisscher No, it works the same way as before.
I replace line 32 with this:
return 'require(' + JSON.stringify('-!' + loader(part, lang) + require.resolve('./selector.js') + '?' + part + '/' + lang + '!' + vueUrl) + ')';
And removing -!
also fixes issue.
from vue-loader.
@OEvgeny one unrelated problem: it seems using postLoaders like this doesn't really get to lint the script contents inside vue files, because they are compiled into something like this:
require("-!style!css!./../../../vue-loader/selector.js?style!./b.vue")
module.exports = require("-!./../../../vue-loader/selector.js?script!./b.vue")
module.exports.template = require("-!html!./../../../vue-loader/selector.js?template!./b.vue")
from vue-loader.
This is probably the proper config to jshint the JavaScript in your vue files:
var vue = require('vue-loader')
module.exports = {
entry: "./src/main.js",
output: {
path: "./build",
filename: "build.js"
},
module: {
loaders: [
{
test: /\.vue$/,
loader: vue.withLoaders({
js: 'jshint'
})
}
]
}
}
from vue-loader.
In addition: because .vue
files are also valid HTML files, you can lint them directly with jshint using --extract=always
option. This will give you correct line numbers, but it won't work if you are using pre-processors for <script>
.
from vue-loader.
Thanks, Evan. Will try this approach for jshint.
from vue-loader.
But I can't use this for code coverage: https://github.com/deepsweet/istanbul-instrumenter-loader
from vue-loader.
@OEvgeny I'll try to investigate the best practices for linting and testing when using vue-loader after 0.12 stabilizes. In the meanwhile, do let me know if you find any good solutions.
from vue-loader.
@yyx990803 Ok, I will try.
from vue-loader.
Didn't know that postLoaders
works well as loaders
.
This seems to work properly for .vue
coverage. I included examples with babel and plain js.
gulp.task('test:cover', function(done) {
var vue = require('vue-loader')
karma.start({
browsers: ['PhantomJS'],
files: [
'./node_modules/phantomjs-polyfill/bind-polyfill.js',
'./test/index.js'
],
frameworks: ['jasmine'],
preprocessors: {
'./test/index.js': ['webpack'],
},
reporters: ['dots', 'coverage'],
singleRun: true,
webpack: {
module: {
postLoaders: [
{
test: /\.js$/,
// exclude this dirs from coverage
exclude: /(test|node_modules|bower_components)/,
loader: 'istanbul-instrumenter'
},
{
test: /\.es6$/,
// exclude this dirs from coverage
exclude: /(test|node_modules|bower_components)/,
loader: 'isparta'
},
],
loaders: [
{
test: /\.vue$/, loader: vue.withLoaders({
js: 'istanbul-instrumenter',
esnext: 'babel!isparta'
})
}
],
},
watch: true,
},
webpackServer: {
noInfo: true,
},
coverageReporter: {
reporters: [
{ type: 'text-summary' }
]
}
}, done)
})
./test/index.js
content:
var testsContext = require.context('.', true, /_[a-z]*\.js$/)
testsContext.keys().forEach(testsContext)
from vue-loader.
Great! AFAIK all loaders are written against the same API. postLoaders
is just a way to control when the loader should be executed on the file.
from vue-loader.
Related Issues (20)
- Can't import interface / type and use them with defineProps "failed to resolve import source" HOT 2
- Hash generated(for HMR) from relative path name is not unique in a microfrontend architecture
- d
- webpack5.0+vue2.0 使用vue-loader 15.10.0 打包 vue 文件---想兼容es5 HOT 1
- Compiling RuleSet failed: Unexpected property test in condition HOT 1
- vue cli3 在打包到时候会把项目中没有使用的图片文件打包输出到dist目录。 HOT 1
- 同一页面有两个不同scopeid HOT 3
- 使用swc-loader替换babel报错 HOT 1
- Build error: Cannot read properties of null (reading 'lang') HOT 2
- v17.3 breaks v-bind HOT 2
- vue2 Upgrade vue3 vue-loader browser error message: Uncaught TypeError: Object(...) is not a function
- Error: Codegen node is missing for element/if/for node. HOT 1
- TypeError: Cannot read property 'compilation' of undefined HOT 1
- Scoped styles are not applied when loading Vue component via SystemJS
- Tricky Src Imports : no compile or hot-reload with version 17.4.2
- Importing plain component file from separate monorepo package results in wrong build
- const/let converto var
- Custom blocks when using vite HOT 1
- about defineAsyncComponent function in Vue3, the path always wrong after webpack compiled
- TypeScript with noImplicitAny: true and SFC without script tag
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vue-loader.