Ionic 2修改Index.html

时间:2017-05-25 08:30:32

标签: typescript ionic-framework ionic2

我想在构建用于开发或生产的应用程序时修改index.html文件。

如果是生产,我需要注入一个<script>,如果是开发,我需要注入其他<script>

其实我用这个---&gt; https://github.com/driftyco/ionic-app-scripts

这个JS

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

const isProd = (process.env.IONIC_ENV === 'prod');
console.log('✓ ENVIRONMENT IS PRODUCTION: ', isProd);

const rollupConfigReplaceEnviroment = replace({
  exclude: 'node_modules/**',
  // 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
  '/environments/environment.dev' : ( isProd ? '/environments/environment.prod' : '/environments/environment.dev'),
});

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

module.exports = rollupConfig;

谢谢

1 个答案:

答案 0 :(得分:2)

您需要以不同方式调用build以使用该汇总配置: "build": "ionic-app-scripts build --rollup ./config/rollup.config.js",