6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ionicのwebpack.config.jsを拡張する

Last updated at Posted at 2017-11-07

Ionicでwebpack.config.jsを拡張する手順

1 ルート層にconfigフォルダを作り、その中にwebpack.config.jsを作成
2 webpack.config.jsを以下のように書き換える

config/webpack.config.js
const webpackConfig = require('../node_modules/@ionic/app-scripts/config/webpack.config');
// ここから拡張したい内容を追加

3 package.jsonに以下を追加

package.json
"config": {
    "ionic_webpack": "./config/webpack.config.js"
}

例えばaliasを追加してimportを便利にしたり出来ます。

config/webpack.config.js
const webpackConfig = require('../node_modules/@ionic/app-scripts/config/webpack.config');
webpackConfig.resolve = {
    extensions: ['.ts', '.js'],
    alias: {
        '@component': path.join(__dirname, '../src/components'),
        '@page': path.join(__dirname, '../src/pages'),
    }
}
sample.ts
import { CardPage } from '@page/hoge';
/* src/pages/hoge.ts */

import { CardPage } from '@component/hoge';
/* src/components/hoge.ts */
6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?