Skip to content

Commit

Permalink
fix: pass externals to webpack config
Browse files Browse the repository at this point in the history
Closes #42
  • Loading branch information
swashata committed Nov 3, 2018
1 parent 7a1e8cd commit ae32d63
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/scripts/__tests__/config/WebpackConfigHelper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { PresetOptions } from '@wpackio/babel-preset-base/lib/preset';
// tslint:disable-next-line:no-implicit-dependencies
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
import miniCssExtractPlugin from 'mini-css-extract-plugin';
import path from 'path';
Expand Down Expand Up @@ -472,6 +473,20 @@ describe('CreateWebPackConfig', () => {

// getCommmon
describe('getCommon', () => {
test('has externals', () => {
const cwc = new WebpackConfigHelper(
projectConfig.files[0],
{
...getConfigFromProjectAndServer(
projectConfig,
serverConfig
),
},
'/foo/bar',
true
);
expect(cwc.getCommon().externals).toBe(projectConfig.externals);
});
test('sends proper stuff depending on isDev', () => {
const cwc = new WebpackConfigHelper(
projectConfig.files[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ exports[`CreateWebPackConfig getCommon sends proper stuff depending on isDev 1`]
Object {
"context": "/foo/bar",
"devtool": "source-map",
"externals": Object {
"jquery": "jQuery",
},
"mode": "production",
"name": "config1",
"target": "web",
Expand All @@ -15,6 +18,9 @@ exports[`CreateWebPackConfig getCommon sends proper stuff depending on isDev 2`]
Object {
"context": "/foo/bar",
"devtool": "inline-source-map",
"externals": Object {
"jquery": "jQuery",
},
"mode": "development",
"name": "config1",
"target": "web",
Expand Down
1 change: 1 addition & 0 deletions packages/scripts/__tests__/helpers/testUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ export function getConfigFromProjectAndServer(
pCfg.outputPath
}/`,
errorOverlay: true,
externals: pCfg.externals,
};
}
2 changes: 2 additions & 0 deletions packages/scripts/src/config/CreateWebpackConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export class CreateWebpackConfig {
outputPath,
appName,
errorOverlay,
externals,
} = this.projectConfig;
const { host, port } = this.serverConfig;
const helper: WebpackConfigHelper = new WebpackConfigHelper(
Expand All @@ -162,6 +163,7 @@ export class CreateWebpackConfig {
publicPath: this.getPublicPath(),
publicPathUrl: this.getPublicPathUrl(),
errorOverlay,
externals,
},
this.cwd,
this.isDev
Expand Down
3 changes: 3 additions & 0 deletions packages/scripts/src/config/WebpackConfigHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export interface WebpackConfigHelperConfig {
publicPath: string; // Not used right now, but maybe we will need it in future?
publicPathUrl: string;
errorOverlay: ProjectConfig['errorOverlay'];
externals: ProjectConfig['externals'];
}

interface CommonWebpackConfig {
Expand All @@ -54,6 +55,7 @@ interface CommonWebpackConfig {
watch: webpack.Configuration['watch'];
mode: webpack.Configuration['mode'];
name: webpack.Configuration['name'];
externals: webpack.Configuration['externals'];
}

/**
Expand Down Expand Up @@ -540,6 +542,7 @@ ${bannerConfig.copyrightText}${bannerConfig.credit ? creditNote : ''}`,
watch: this.isDev,
mode: this.env,
name: this.file.name,
externals: this.config.externals,
};
}

Expand Down

0 comments on commit ae32d63

Please sign in to comment.