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

Commit

Permalink
fix(sass): use webpack/rollup modules for non-optimized build, use op…
Browse files Browse the repository at this point in the history
…timization data for prod/optimized buids
  • Loading branch information
danbucholtz committed Jul 11, 2017
1 parent 7961095 commit 0554201
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 16 deletions.
15 changes: 1 addition & 14 deletions src/preprocess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export function preprocess(context: BuildContext) {
function preprocessWorker(context: BuildContext) {
const bundlePromise = bundleCoreComponents(context);
const deepLinksPromise = getBooleanPropertyValue(Constants.ENV_PARSE_DEEPLINKS) ? deepLinking(context) : Promise.resolve();
const componentSassPromise = lookUpDefaultIonicComponentPaths(context);
return Promise.all([bundlePromise, deepLinksPromise, componentSassPromise])
return Promise.all([bundlePromise, deepLinksPromise])
.then(() => {
if (context.optimizeJs) {
return optimization(context, null);
Expand Down Expand Up @@ -68,15 +67,3 @@ export function preprocessUpdate(changedFiles: ChangedFile[], context: BuildCont

return Promise.all(promises);
}

export function lookUpDefaultIonicComponentPaths(context: BuildContext) {
const componentsDirGlob = join(getStringPropertyValue(Constants.ENV_VAR_IONIC_ANGULAR_DIR), 'components', '**', '*.scss');
const srcDirGlob = join(getStringPropertyValue(Constants.ENV_VAR_SRC_DIR), '**', '*.scss');
return globAll([componentsDirGlob, srcDirGlob]).then((results: GlobResult[]) => {
const componentPathSet = new Set<string>();
results.forEach(result => {
componentPathSet.add(result.absolutePath);
});
context.moduleFiles = Array.from(componentPathSet);
});
}
13 changes: 12 additions & 1 deletion src/rollup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,17 @@ export function rollupWorker(context: BuildContext, configFile: string): Promise

Logger.debug(`bundle.modules: ${bundle.modules.length}`);

// set the module files used in this bundle
// this reference can be used elsewhere in the build (sass)
context.moduleFiles = bundle.modules.map((m) => {
// sometimes, Rollup appends weird prefixes to the path like commonjs:proxy
const index = m.id.indexOf(sep);
if (index >= 0) {
return m.id.substring(index);
}
return m.id;
});

// cache our bundle for later use
if (context.isWatch) {
cachedBundle = bundle;
Expand Down Expand Up @@ -214,4 +225,4 @@ export interface RollupLocationInfo {
file: string;
line: number;
column: number;
}
}
19 changes: 18 additions & 1 deletion src/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ function webpackBuildComplete(stats: any, context: BuildContext, webpackConfig:
Logger.debug('Webpack Dependency Map End');
}

// set the module files used in this bundle
// this reference can be used elsewhere in the build (sass)
if (!context.isProd || !context.optimizeJs) {
const files: string[] = stats.compilation.modules.map((webpackObj: any) => {
if (webpackObj.resource) {
return webpackObj.resource;
} else {
return webpackObj.context;
}
}).filter((path: string) => {
// just make sure the path is not null
return path && path.length > 0;
});

context.moduleFiles = files;
}

return setBundledFiles(context);
}

Expand Down Expand Up @@ -227,4 +244,4 @@ export interface WebpackOutputObject {
export interface WebpackResolveObject {
extensions: string[];
modules: string[];
}
}

0 comments on commit 0554201

Please sign in to comment.