我尝试使用webpack
和ts-loader
插件构建应用。
但是出现此错误:
ERROR in ./jobs/createUpdateSimasFilters.ts
Module not found: Error: Can't resolve '../services/data.service' in '/Users/gefalko/gecars2/jobs'
@ ./jobs/createUpdateSimasFilters.ts 53:10-45
ERROR in ./jobs/createUpdateSimasFilters.ts
Module not found: Error: Can't resolve '~/appData/simasData/activeFilters' in '/Users/gefalko/gecars2/jobs'
@ ./jobs/createUpdateSimasFilters.ts 52:22-66
文件:
3 import filters from '~/appData/simasData/activeFilters'
4 const ser = require('../services/data.service')
tsconfig.json:
{
"compilerOptions": {
"skipLibCheck": true,
"sourceMap": true,
"target": "esnext",
"jsx": "react",
"module": "esnext",
"allowSyntheticDefaultImports": true,
"forceConsistentCasingInFileNames": true,
"strict": true,
"moduleResolution": "node",
"declaration": false,
"removeComments": true,
"noImplicitReturns": true,
"strictNullChecks": true,
"outDir": "build",
"noUnusedLocals": true,
"lib": ["es6", "es7", "dom"],
"types": ["node"],
"baseUrl": "./",
"paths": {
"~*": ["./*"]
}
},
"exclude": ["build", "node_modules"]
}
webpack.config.json:
const path = require('path');
module.exports = function(env, args) {
const config = {
module: {
rules: [
{
test: /\.ts?$/,
use: 'ts-loader',
exclude: /node_modules/,
},
],
},
resolve: {
extensions: ['.ts', '.js'],
},
output: {
path: path.resolve(__dirname, 'dist'),
},
target: 'async-node',
mode: 'development'
}
if(args.targetFile === 'createUpdateSimasFilters') {
config.entry = './jobs/createUpdateSimasFilters.ts'
config.output.filename = 'createUpdateSimasFilters.js'
}
return config
}