Ionic2在配置rollup.config.js后显示“系统未定义”

时间:2017-09-06 01:53:28

标签: ionic-framework ionic3 rollupjs

我在package.json中添加了config,rollup.config.js如下:

const rollupConfig = require('@ionic/app-scripts/config/rollup.config');
enter code hereconst replace = require('rollup-plugin-replace');

const isProd = (process.env.IONIC_ENV === 'prod');

console.log('cur ENV: ', process.env.IONIC_ENV);
const EnvConfig = {
  prod: {
    API_URL: ''
  },
  dev: {
    API_URL: 'http://localhost:3000'
  },
  deviceDev: {
    API_URL: 'http://192.168.1.7:3000'
  }
}

const curConfig = EnvConfig[process.env.IONIC_ENV]

const rollupConfigReplaceEnviroment = replace({
  exclude: 'node_modules/**',
  delimiters: ['<@', '@>'],
  // use the /environments/environment.dev as the default import(!), no stub needed.
  // note we only replace the "last" part of the import statement so relative paths are maintained
  'API_URL': curConfig.API_URL,
});

rollupConfig.plugins = rollupConfig.plugins || [];
rollupConfig.plugins.splice(0, 0, rollupConfigReplaceEnviroment);

module.exports = rollupConfig;

但是当我运行ionic serve -b时,会出现一个警告: ```

[22:54:11]  rollup: commonjs-proxy:/Applications/My-Project/sharemap/node_modules/@angular/http/@angular/http.es5.js
            has issued a warning: 'default' is not exported by 'node_modules/@angular/http/@angular/http.es5.js'
[22:54:11]  rollup: commonjs-proxy:/Applications/My-Project/sharemap/node_modules/@angular/core/@angular/core.es5.js
            has issued a warning: 'default' is not exported by 'node_modules/@angular/core/@angular/core.es5.js'

然后我在浏览器中运行我的应用程序,它显示错误:

ERROR ReferenceError: System is not defined
    at loadAndCompile (main.js:82094)
    at NgModuleLoader.load (main.js:82071)
    at ModuleLoader.load (main.js:82147)
    at DeepLinker.getNavLinkComponent (main.js:56968)
    at DeepLinker.initViews (main.js:57039)
    at Nav.ngAfterViewInit (main.js:80489)
    at callProviderLifecycles (main.js:13220)
    at callElementProvidersLifecycles (main.js:13195)
    at callLifecycleHooksChildrenFirst (main.js:13179)
    at checkAndUpdateView (main.js:14211)

我认为这些可能是rollup-plugin-commonjs@8.0.2的错误,然后我将这些lib升级到8.2.0,但问题仍然存在。

MY @ ionic / app-scripts版本为2.1.4

我的离子信息:

cli packages: (/Applications/My-Project/sharemap/node_modules)

    @ionic/cli-utils  : 1.9.2
    ionic (Ionic CLI) : 3.9.2

global packages:

    Cordova CLI : not installed

local packages:

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

System:

    Android SDK Tools : 26.0.2
    ios-deploy        : 1.9.1
    ios-sim           : 6.0.0
    Node              : v8.4.0
    npm               : 5.2.0
    OS                : macOS Sierra
    Xcode             : Xcode 8.3.3 Build version 8E3004b

1 个答案:

答案 0 :(得分:0)

您必须使用下面给出的特定路径添加package.json;

"config": {
        "ionic_copy": "./config/rollup.config.js"
    },

rollup.config.js文件将位于根目录下的config目录中,类似projectName/config/rollup.config.js