A playground project with vue3.x, TypeScript, ESLint, webpack and others. Used to learn.
$ yarn
$ npm run devI am using the latest version of vue and now can use vue3 normally.
I am using yarn to manage dependencies.
-
First, install the dependencies:
yarn add vue@next yarn add -D @vue/compiler-sfc vue-style-loader vue-loader@next css-loader
@vue/compiler-sfcis used to compile SFC into javascript.vue-loader@nextis loader for vue3.x
-
Then update our
webpack configas normal vue2.x project .We can add vue alias to avoid some questions according to Evan's project :
module.exports = { resolve: { alias: { 'vue': '@vue/runtime-dom', }, }, };
- First, install dependencies: eslint-plugin-vue@next
yarn add -D eslint eslint-plugin-vue@next
- Then, add config in
.eslintrc.jsmodule.exports = { parser: 'vue-eslint-parser', plugins: [ '@typescript-eslint', 'vue', ], extends: [ // other rules: 'eslint:recommended', 'plugin:vue/vue3-recommended', ], };
In order to parse SFC, we must specify parser: 'vue-eslint-parser' in top level.
If you want to use custom parser, you must add it in parserOptions :
js module.exports = { parserOptions: { // typescript parser parser: '@typescript-eslint/parser', } }
-
multiple root element in
templateCurrently if we usemultiple root elementintemplate,Veturwill report error. We can configvetursetting:"vetur.validation.template": false
More information, see:
TypeScript has decided to use ESLint to check code.
-
First install the required packages:
yarn add -D typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin
-
Then create a config file in root
.eslintrc.js, and use@typescript-eslint/parseras the parser:module.exports = { parser: '@typescript-eslint/parser', };
-
Use
env: { node: true }to enable the use ofmodule.exports. -
Using
requireinwebpack.config.jswill report error,we can useoverridesto override the rules inbuilddirectory:module.exports = { overrides: [ { files: [ 'build/*.js' ], rules: { "@typescript-eslint/no-var-requires": "off" } } ] }
-
To use
webpack alias, you should configtsconfig.json:{ "compilerOptions": { "baseUrl": ".", "paths": { "@/*": [ "./src/*" ] } } }