設定
必要なpackageを取得
npm install vue-property-decorator
npm install --save-dev typescript webpack webpack-merge
tsconfig(基本的に推奨構成より)
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"strict": true,
"moduleResolution": "node",
"noImplicitAny": true, // 暗黙のany
"strictNullChecks": true, //nullやundefinedを明示するように
"noImplicitThis": true,
"moduleResolution": "node",
// importのpathを./src/...から@src/...に
"paths": {
"@src/*": ["src/*"]
},
"include": [
"./src/**/*.ts"
]
}
}
includeなどは自分の設定に合わせて…
webpack設定
webpack.common.js
const path = require('path');
const VueLoaderPlugin = require('vue-loader/lib/plugin')
const webpack = require('webpack')
module.exports = {
entry: {
app: ["./src/index.ts"]
},
output: {
filename: "[name].bundle.js",
path: path.resolve(__dirname, "public/js")
},
resolve: {
extensions: [".js", ".ts", ".vue", ".json", ".css"],
alias: {
vue$: "vue/dist/vue.esm.js",
// importのpathを./src/...から@src/...に
'@src': path.resolve(__dirname, './src')
},
modules: ["node_modules"]
},
plugins: [
new VueLoaderPlugin(),
]
}
開発用のビルドと本番用のビルドで分けたりする。(sourcemap出力したり)
webpack.dev.js
// 開発ビルド用
const merge = require('webpack-merge')
const common = require('./webpack.common.js')
module.exports = merge(common, {
mode: 'development',
module: {
rules: [
{
test: /\.vue$/,
exclude: /node_modules/,
loader: 'vue-loader',
options: {
cssModules: {
camelCase: true
}
}
},
{
test: /\.ts$/,
exclude: '/node_modules/',
use: [
{
loader: 'ts-loader',
options: {
appendTsSuffixTo: [/\.vue$/]
}
}
]
},
]
}
})