Skip to content

Commit ae32d63

Browse files
committed
fix: pass externals to webpack config
Closes #42
1 parent 7a1e8cd commit ae32d63

File tree

5 files changed

+27
-0
lines changed

5 files changed

+27
-0
lines changed

packages/scripts/__tests__/config/WebpackConfigHelper.spec.ts

+15
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { PresetOptions } from '@wpackio/babel-preset-base/lib/preset';
2+
// tslint:disable-next-line:no-implicit-dependencies
23
import ForkTsCheckerWebpackPlugin from 'fork-ts-checker-webpack-plugin';
34
import miniCssExtractPlugin from 'mini-css-extract-plugin';
45
import path from 'path';
@@ -472,6 +473,20 @@ describe('CreateWebPackConfig', () => {
472473

473474
// getCommmon
474475
describe('getCommon', () => {
476+
test('has externals', () => {
477+
const cwc = new WebpackConfigHelper(
478+
projectConfig.files[0],
479+
{
480+
...getConfigFromProjectAndServer(
481+
projectConfig,
482+
serverConfig
483+
),
484+
},
485+
'/foo/bar',
486+
true
487+
);
488+
expect(cwc.getCommon().externals).toBe(projectConfig.externals);
489+
});
475490
test('sends proper stuff depending on isDev', () => {
476491
const cwc = new WebpackConfigHelper(
477492
projectConfig.files[0],

packages/scripts/__tests__/config/__snapshots__/WebpackConfigHelper.spec.ts.snap

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ exports[`CreateWebPackConfig getCommon sends proper stuff depending on isDev 1`]
44
Object {
55
"context": "/foo/bar",
66
"devtool": "source-map",
7+
"externals": Object {
8+
"jquery": "jQuery",
9+
},
710
"mode": "production",
811
"name": "config1",
912
"target": "web",
@@ -15,6 +18,9 @@ exports[`CreateWebPackConfig getCommon sends proper stuff depending on isDev 2`]
1518
Object {
1619
"context": "/foo/bar",
1720
"devtool": "inline-source-map",
21+
"externals": Object {
22+
"jquery": "jQuery",
23+
},
1824
"mode": "development",
1925
"name": "config1",
2026
"target": "web",

packages/scripts/__tests__/helpers/testUtils.ts

+1
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,6 @@ export function getConfigFromProjectAndServer(
5656
pCfg.outputPath
5757
}/`,
5858
errorOverlay: true,
59+
externals: pCfg.externals,
5960
};
6061
}

packages/scripts/src/config/CreateWebpackConfig.ts

+2
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ export class CreateWebpackConfig {
142142
outputPath,
143143
appName,
144144
errorOverlay,
145+
externals,
145146
} = this.projectConfig;
146147
const { host, port } = this.serverConfig;
147148
const helper: WebpackConfigHelper = new WebpackConfigHelper(
@@ -162,6 +163,7 @@ export class CreateWebpackConfig {
162163
publicPath: this.getPublicPath(),
163164
publicPathUrl: this.getPublicPathUrl(),
164165
errorOverlay,
166+
externals,
165167
},
166168
this.cwd,
167169
this.isDev

packages/scripts/src/config/WebpackConfigHelper.ts

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ export interface WebpackConfigHelperConfig {
4545
publicPath: string; // Not used right now, but maybe we will need it in future?
4646
publicPathUrl: string;
4747
errorOverlay: ProjectConfig['errorOverlay'];
48+
externals: ProjectConfig['externals'];
4849
}
4950

5051
interface CommonWebpackConfig {
@@ -54,6 +55,7 @@ interface CommonWebpackConfig {
5455
watch: webpack.Configuration['watch'];
5556
mode: webpack.Configuration['mode'];
5657
name: webpack.Configuration['name'];
58+
externals: webpack.Configuration['externals'];
5759
}
5860

5961
/**
@@ -540,6 +542,7 @@ ${bannerConfig.copyrightText}${bannerConfig.credit ? creditNote : ''}`,
540542
watch: this.isDev,
541543
mode: this.env,
542544
name: this.file.name,
545+
externals: this.config.externals,
543546
};
544547
}
545548

0 commit comments

Comments
 (0)