Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Commit

Permalink
feat(webpack): default webpack, set bundler via configs
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Oct 15, 2016
2 parents 4168a2f + 100cb74 commit 09bc511
Show file tree
Hide file tree
Showing 22 changed files with 864 additions and 396 deletions.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ npm install @ionic/app-scripts@latest --save-dev
```


# 0.0.36 (2016-10-15)

* Fix handling multiple async template updates


# 0.0.35 (2016-10-15)

* Fix resolving index files correctly
* Fix template rebuilds for multiple templates in one file
* Fix ability to watchers to ignore paths


# 0.0.34 (2016-10-15)

* Fix silently failed bundles
* Fix template path resolving issues


# 0.0.33 (2016-10-14)

* Improve build times for template changes
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ npm install @ionic/app-scripts@latest --save-dev
Out of the box, Ionic starters have been preconfigured with great defaults for building fast apps, including:

- Multi-core processing tasks in parallel for faster builds
- In-memory file transpiling and bundling
- Transpiling source code to ES5 JavaScript
- Ahead of Time (AoT) template compiling
- Just in Time (JiT) template compiling
Expand Down Expand Up @@ -97,12 +98,14 @@ npm run build --rollup ./config/rollup.config.js
| Sass | `ionic_sass` | `--sass` or `-s` |
| TSLint | `ionic_tslint` | `--tslint` or `-l` |
| UglifyJS | `ionic_uglifyjs` | `--uglifyjs` or `-u` |
| Webpack | `ionic_webpack` | `--webpack` or `-w` |


### Overriding Config Values

| Config Values | NPM Config Property | Cmd-line Flag | Defaults |
|-----------------|---------------------|---------------|-----------------|
| bundler | `ionic_bundler` | `--bundler` | `webpack` |
| root directory | `ionic_root_dir` | `--rootDir` | `process.cwd()` |
| tmp directory | `ionic_tmp_dir` | `--tmpDir` | `.tmp` |
| www directory | `ionic_www_dir` | `--wwwDir` | `www` |
Expand Down
3 changes: 0 additions & 3 deletions config/bundle.config.js

This file was deleted.

1 change: 1 addition & 0 deletions config/watch.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = {
paths: [
'{{SRC}}/**/*.ts'
],
options: { ignored: '{{SRC}}/**/*.spec.ts' },
callback: buildUpdate
},

Expand Down
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ionic/app-scripts",
"version": "0.0.33",
"version": "0.0.36",
"description": "Scripts for Ionic Projects",
"homepage": "http://ionicframework.com/",
"author": "Ionic Team <hi@ionic.io> (http://ionic.io)",
Expand All @@ -17,6 +17,7 @@
},
"scripts": {
"build": "npm run clean && tsc",
"build-and-test": "npm run build && npm run test",
"clean": "rm -rf ./dist",
"lint": "tslint -c ./tslint.json --project ./tsconfig.json",
"prepublish": "jasmine JASMINE_CONFIG_PATH=src/spec/jasmine.config.json && npm run build",
Expand All @@ -32,7 +33,6 @@
"cross-spawn": "4.0.0",
"fs-extra": "0.30.0",
"json-loader": "^0.5.4",
"magic-string": "0.16.0",
"node-sass": "3.9.3",
"postcss": "5.2.0",
"rollup": "0.36.3",
Expand All @@ -50,12 +50,17 @@
},
"devDependencies": {
"@types/chalk": "0.4.30",
"@types/chokidar": "^1.4.29",
"@types/clean-css": "3.4.29",
"@types/fs-extra": "0.0.33",
"@types/jasmine": "2.2.33",
"@types/mock-fs": "^3.6.29",
"@types/node": "6.0.38",
"@types/node-sass": "0.0.29",
"@types/uglify-js": "2.0.27",
"@types/webpack": "^1.12.35",
"jasmine": "2.5.2",
"mock-fs": "^3.11.0",
"tslint": "3.15.1",
"tslint-ionic-rules": "0.0.5"
},
Expand Down
4 changes: 2 additions & 2 deletions src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function build(context: BuildContext) {

const logger = new Logger(`build ${(context.isProd ? 'prod' : 'dev')}`);

return runBuild(context)
return buildWorker(context)
.then(() => {
// congrats, we did it! (•_•) / ( •_•)>⌐■-■ / (⌐■_■)
logger.finish();
Expand All @@ -27,7 +27,7 @@ export function build(context: BuildContext) {
}


function runBuild(context: BuildContext) {
function buildWorker(context: BuildContext) {
if (context.isProd) {
// production build
return buildProd(context);
Expand Down
69 changes: 26 additions & 43 deletions src/bundle.ts
Original file line number Diff line number Diff line change
@@ -1,78 +1,61 @@
import { BuildContext, TaskInfo } from './util/interfaces';
import { BuildContext } from './util/interfaces';
import { BuildError } from './util/logger';
import { fillConfigDefaults, generateContext, getUserConfigFile } from './util/config';
import { generateContext, BUNDLER_ROLLUP } from './util/config';
import { rollup, rollupUpdate, getRollupConfig, getOutputDest as rollupGetOutputDest } from './rollup';
import { getWebpackConfig, webpack, webpackUpdate, getOutputDest as webpackGetOutputDest } from './webpack';
import { webpack, webpackUpdate, getWebpackConfig, getOutputDest as webpackGetOutputDest } from './webpack';


export function bundle(context?: BuildContext, configFile?: string) {
context = generateContext(context);
const bundleConfig = getBundleConfig(context, configFile);

return createBundle(context, configFile, bundleConfig)
return bundleWorker(context, configFile)
.catch((err: Error) => {
throw new BuildError(err);
});
}

function createBundle(context: BuildContext, configFile: string, bundleConfig: BundleConfig) {
if (bundleConfig.useWebpack) {
return webpack(context, configFile);
} else {

function bundleWorker(context: BuildContext, configFile: string) {
if (context.bundler === BUNDLER_ROLLUP) {
return rollup(context, configFile);
}

return webpack(context, configFile);
}


export function bundleUpdate(event: string, path: string, context: BuildContext) {
const bundleConfig = getBundleConfig(context, null);
if (bundleConfig.useWebpack) {
return webpackUpdate(event, path, context, null)
.catch( (err: Error) => {
throw new BuildError(err);
});
} else {
if (context.bundler === BUNDLER_ROLLUP) {
return rollupUpdate(event, path, context)
.catch( (err: Error) => {
.catch(err => {
throw new BuildError(err);
});
}

return webpackUpdate(event, path, context, null)
.catch(err => {
throw new BuildError(err);
});
}


export function buildJsSourceMaps(context: BuildContext) {
const bundleConfig = getBundleConfig(context, null);
if (bundleConfig.useWebpack) {
// TODO - read this from webpack config (could be multiple values)
return true;
} else {
if (context.bundler === BUNDLER_ROLLUP) {
const rollupConfig = getRollupConfig(context, null);
return rollupConfig.sourceMap;
}

// TODO - read this from webpack config (could be multiple values)
return true;
}


export function getJsOutputDest(context: BuildContext) {
const bundleConfig = getBundleConfig(context, null);
if (bundleConfig.useWebpack) {
const webpackConfig = getWebpackConfig(context, null);
return webpackGetOutputDest(context, webpackConfig);
} else {
if (context.bundler === BUNDLER_ROLLUP) {
const rollupConfig = getRollupConfig(context, null);
return rollupGetOutputDest(context, rollupConfig);
}
}

function getBundleConfig(context: BuildContext, configFile: string) {
configFile = getUserConfigFile(context, taskInfo, configFile);
const bundleConfig: BundleConfig = fillConfigDefaults(configFile, taskInfo.defaultConfigFile);
return bundleConfig;
}

const taskInfo: TaskInfo = {
fullArgConfig: '--bundle',
shortArgConfig: '-e',
envConfig: 'ionic_bundle',
defaultConfigFile: 'bundle.config'
};

export interface BundleConfig {
useWebpack: boolean;
const webpackConfig = getWebpackConfig(context, null);
return webpackGetOutputDest(context, webpackConfig);
}
4 changes: 3 additions & 1 deletion src/declarations.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
declare module "*";
declare module 'autoprefixer';
declare module 'rollup-pluginutils';
declare module 'rollup';
52 changes: 33 additions & 19 deletions src/plugins/ion-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { BuildContext } from '../util/interfaces';
import { dirname, join } from 'path';
import { dirname, join, resolve } from 'path';
import * as pluginutils from 'rollup-pluginutils';


Expand Down Expand Up @@ -31,24 +31,7 @@ export function ionCompiler(context: BuildContext) {
},

resolveId(importee: string, importer: string): any {
if (!importer || /\0/.test(importee)) {
// disregard entry module
// ignore IDs with null character, these belong to other plugins
return null;
}

if (context.tsFiles) {
const importerFile = context.tsFiles[importer];
if (importerFile && importerFile.output) {
const attemptedImportee = join(dirname(importer), importee) + '.ts';
const importeeFile = context.tsFiles[attemptedImportee];
if (importeeFile) {
return attemptedImportee;
}
}
}

return null;
return resolveId(importee, importer, context);
},

load(sourcePath: string) {
Expand All @@ -65,5 +48,36 @@ export function ionCompiler(context: BuildContext) {
}


export function resolveId(importee: string, importer: string, context: BuildContext) {
if (!importer || /\0/.test(importee)) {
// disregard entry module
// ignore IDs with null character, these belong to other plugins
return null;
}

if (context.tsFiles) {
const importerFile = context.tsFiles[importer];
if (importerFile && importerFile.output) {
const attemptedImporteeBasename = resolve(join(dirname(importer), importee));
const attemptedImportee = attemptedImporteeBasename + '.ts';
const importeeFile = context.tsFiles[attemptedImportee];
if (importeeFile) {
return attemptedImportee;
} else {
// rather than a file, the attempedImportee could be a directory
// while via node resolve pattern auto resolves to index file
const attemptedImporteeIndex = resolve(join(attemptedImporteeBasename, 'index.ts'));
const importeeIndexFile = context.tsFiles[attemptedImporteeIndex];
if (importeeIndexFile) {
return attemptedImporteeIndex;
}
}
}
}

return null;
}


const INCLUDE = ['*.ts+(|x)', '**/*.ts+(|x)'];
const EXCLUDE = ['*.d.ts', '**/*.d.ts'];
Loading

0 comments on commit 09bc511

Please sign in to comment.