1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | module.exports = ({ loaderOptions, tsChecker } = {}) => {
|
9 | const tsLoaderOptions = Object.assign(
|
10 | {
|
11 | appendTsSuffixTo: [/\.vue$/],
|
12 | transpileOnly: true
|
13 | },
|
14 | loaderOptions
|
15 | )
|
16 |
|
17 | return {
|
18 | name: 'typescript',
|
19 | apply(poi) {
|
20 | poi.chainWebpack(config => {
|
21 | const tsRule = config.module.rule('typescript').test(/\.tsx?$/)
|
22 | tsRule
|
23 | .use('ts-loader')
|
24 | .loader('ts-loader')
|
25 | .options(tsLoaderOptions)
|
26 |
|
27 | config.resolve.extensions.add('.ts').add('.tsx')
|
28 |
|
29 | config
|
30 | .plugin('fork-ts-checker')
|
31 | .use(require('fork-ts-checker-webpack-plugin'), [
|
32 | Object.assign(
|
33 | {
|
34 | vue: config.module.rules.has('vue')
|
35 | },
|
36 | tsChecker
|
37 | )
|
38 | ])
|
39 |
|
40 | config.resolve
|
41 | .plugin('tsconfig-paths')
|
42 | .use(require('tsconfig-paths-webpack-plugin'))
|
43 |
|
44 | const vueRule = config.module.rule('vue')
|
45 | vueRule.use('vue-loader').tap(vueOptions => {
|
46 | vueOptions.esModule = true
|
47 | vueOptions.loaders.ts = [
|
48 | {
|
49 | loader: 'ts-loader',
|
50 | options: tsLoaderOptions
|
51 | }
|
52 | ]
|
53 | return vueOptions
|
54 | })
|
55 | })
|
56 | }
|
57 | }
|
58 | }
|