我尝试在编译应用程序时获取源地图,但是它不起作用。
我的tsconfig.json
{
"compilerOptions": {
"outDir": "./dist/",
"noImplicitAny": true,
"suppressImplicitAnyIndexErrors": false,
"module": "amd",
"moduleResolution": "node",
"target": "es6",
"jsx": "react",
"allowJs": true,
"sourceMap": true,
"lib": ["es5", "es6", "es2017", "dom"],
"allowSyntheticDefaultImports": true,
"baseUrl": ".",
"paths": {
"~*": ["./*"]
}
}
}
webpack.config.js
const path = require('path')
const webpack = require('webpack')
const CompressionPlugin = require('compression-webpack-plugin')
const gpconfig = require('./gpconfig')
const createStyledComponentsTransformer = require('typescript-plugin-styled-components').default;
const styledComponentsTransformer = createStyledComponentsTransformer();
module.exports = function(env, arg) {
// It comes from command line
const platform = env.platform
const base = {
module: {
rules: [
{
test: /\.(graphql|gql)$/,
exclude: /node_modules/,
loader: 'graphql-tag/loader',
},
{
test: /\.tsx?$/,
loader: 'awesome-typescript-loader',
options: {
transpileOnly: true,
experimentalWatchApi: true,
getCustomTransformers: () => ({ before: [styledComponentsTransformer] })
},
},
{
test: /\.js$/,
use: ['source-map-loader'],
enforce: 'pre',
},
],
},
resolve: {
extensions: ['.mjs', '.tsx', '.ts', '.js'],
alias: {
react: path.resolve(__dirname, 'node_modules', 'react'),
'~': path.resolve('./'),
},
},
devtool: 'source-map',
externals: {
React: 'react',
},
}
...
if (platform === 'graphql') {
~ base.mode = 'development'
base.entry = './graphql/server.ts'
base.output = {
path: path.resolve(__dirname, './dist/graphql/'),
filename: 'server.js',
}
base.target = 'node'
base.node = {
__dirname: false,
__filename: false,
}
}
...
编译器输出:
../dist/graphql/server.js:457
throw new Error("Module build failed (from ./node_modules/awesome-typescript-loader/dist/entry.js):\nError: ENOENT: no such file or directory, open '.../app/db/models/Account/Account.ts'");
^
Error: Module build failed (from ./node_modules/awesome-typescript-loader/dist/entry.js):
Error: ENOENT: no such file or directory, open '.../app/db/models/Account/Account.ts'
at Object../app/db/models/Account/Account.ts my/dist/graphql/server.js:457:7)
at __webpack_require__ (.../dist/graphql/server.js:20:30)
at Object../graphql/getAccount.ts (.../dist/graphql/server.js:2014:19)
at __webpack_require__ (..dist/graphql/server.js:20:30)
at Object../graphql/server.ts (../dist/graphql/server.js:2648:22)
at __webpack_require__ (../dist/graphql/server.js:20:30)
at ../dist/graphql/server.js:84:18
at Object.<anonymous> (..dist/graphql/server.js:87:10)
at Module._compile (internal/modules/cjs/loader.js:816:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:827:10)
at Module.load (internal/modules/cjs/loader.js:685:32)
at Function.Module._load (internal/modules/cjs/loader.js:620:12)
at Function.Module.runMain (internal/modules/cjs/loader.js:877:12)
at internal/main/run_main_module.js:21:11