gpt4 book ai didi

typescript - 自定义 webpack 配置别名在 ionic 2 中不起作用

转载 作者:搜寻专家 更新时间:2023-10-30 21:08:29 25 4
gpt4 key购买 nike

我在自定义配置中使用环境别名,如下所示:包.json

 "config": {
"ionic_bundler": "webpack",
"ionic_webpack": "./config/webpack-extension.config.js"
}

webpack-extension.config.js

/*
inspired by:
https://github.com/driftyco/ionic-app-scripts/pull/683#issuecomment-287401855
*/

let path = require('path')
let useDefaultConfig = require('@ionic/app-scripts/config/webpack.config.js')

module.exports = function () {

useDefaultConfig.resolve.alias = {
"@app/env": path.resolve(__dirname, '../src/environments/env.' + process.env.IONIC_ENV + '.ts'),
};

return useDefaultConfig;
}

环境.ts

import {

isDEV,
API_HOST,
...etc

} from '@app/env'

但是我得到了错误:

Typescript Error
Cannot find module '@app/env'.

最佳答案

经过艰苦的谷歌搜索后,我找到了此修复程序(让 typescript 加载程序知道别名):tsconfig.json

  "compilerOptions": {
...
"baseUrl": "./src",
"paths": {
"@app/config": ["config/config"]
}
}
...

来源:https://github.com/ionic-team/ionic-app-scripts/pull/683#issuecomment-294078919

我的 ionic 信息:

cli packages: (/Users/.../node_modules)

@ionic/cli-plugin-cordova : 1.6.2
@ionic/cli-plugin-ionic-angular : 1.4.1
@ionic/cli-utils : 1.7.0
ionic (Ionic CLI) : 3.7.0

全局包:

Cordova CLI : 7.0.1 

本地包:

@ionic/app-scripts : 2.1.3
Cordova Platforms : none
Ionic Framework : ionic-angular 3.6.0

系统:

Node       : v6.9.5
OS : macOS Sierra
Xcode : Xcode 8.3.3 Build version 8E3004b
ios-deploy : 1.9.1
ios-sim : 5.0.13
npm : 5.3.0

关于typescript - 自定义 webpack 配置别名在 ionic 2 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45543792/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com