1.查看项目的package.json中
有两个依赖环境:正式环境和开发环境
开发环境中,没有存储依赖:"@ionic/storage": "^2.1.3",
2.项目中有标示环境的文件:
// The file contents for the current environment will overwrite these during build.
// The build system defaults to the dev environment which uses `environment.ts`, but if you do
// `ng build --env=prod` then `environment.prod.ts` will be used instead.
// The list of which env maps to which file can be found in `.angular-cli.json`.
export const environment = {
// production: false //这是默认值
production: true
};
/*
* In development mode, to ignore zone related error stack frames such as
* `zone.run`, `zoneDelegate.invokeTask` for easier debugging, you can
* import the following file, but please comment it out in production mode
* because it will have performance impact when throw error
*/
// import 'zone.js/dist/zone-error'; // Included with Angular CLI.
3.检查 environment 被谁使用:
在main.ts中: 打印日志是我添加的
import {enableProdMode} from '@angular/core';
import {platformBrowserDynamic} from '@angular/platform-browser-dynamic';
import {AppModule} from './app/app.module';
import {environment} from './environments/environment';
if (environment.production) {
enableProdMode();
console.log('current run mode: PROD'); // 此信息会在浏览器的控制台打印出来!
} else {
console.log('current run mode: DEV');
}
platformBrowserDynamic().bootstrapModule(AppModule)
.catch(err => console.log(err));
4.再次启动项目ionic serve,检查浏览器的存储,发现有写入值:
5.另一种简单的方式将存储依赖也加到开发环境的依赖中就可以了!
6.举一反三:以后再有类似不起效的场景,可以检查这里!