Skip to content

Commit

Permalink
refactor: use buildOptimizerLoaderPath
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Jul 5, 2019
1 parent c4128e8 commit c4bfb2f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import { BuildOptimizerWebpackPlugin } from '@angular-devkit/build-optimizer';
import {
BuildOptimizerWebpackPlugin,
buildOptimizerLoaderPath,
} from '@angular-devkit/build-optimizer';
import { tags } from '@angular-devkit/core';
import * as CopyWebpackPlugin from 'copy-webpack-plugin';
import * as path from 'path';
Expand Down Expand Up @@ -35,9 +38,6 @@ const TerserPlugin = require('terser-webpack-plugin');

// tslint:disable-next-line:no-any
const g: any = typeof global !== 'undefined' ? global : {};
export const buildOptimizerLoader: string = g['_DevKitIsLocal']
? require.resolve('@angular-devkit/build-optimizer/src/build-optimizer/webpack-loader')
: '@angular-devkit/build-optimizer/webpack-loader';

// tslint:disable-next-line:no-big-function
export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
Expand Down Expand Up @@ -256,7 +256,7 @@ export function getCommonConfig(wco: WebpackConfigOptions): Configuration {
buildOptimizerUseRule = {
use: [
{
loader: buildOptimizerLoader,
loader: buildOptimizerLoaderPath,
options: { sourceMap: scriptsSourceMap },
},
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface BuildOptimizerLoaderOptions {
sourceMap: boolean;
}

export const buildOptimizerLoaderPath = __filename;

export default function buildOptimizerLoader
(this: webpack.loader.LoaderContext, content: string, previousSourceMap: RawSourceMap) {
this.cacheable();
Expand Down
5 changes: 4 additions & 1 deletion packages/angular_devkit/build_optimizer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
export { default as buildOptimizerLoader } from './build-optimizer/webpack-loader';
export {
default as buildOptimizerLoader,
buildOptimizerLoaderPath,
} from './build-optimizer/webpack-loader';
export { BuildOptimizerWebpackPlugin } from './build-optimizer/webpack-plugin';
export { buildOptimizer } from './build-optimizer/build-optimizer';

Expand Down

0 comments on commit c4bfb2f

Please sign in to comment.