Skip to content

Commit

Permalink
Fix ts option
Browse files Browse the repository at this point in the history
  • Loading branch information
helloitsjoe committed Dec 5, 2020
1 parent 3cddca4 commit 6e62c49
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 27 deletions.
22 changes: 5 additions & 17 deletions __tests__/index.test.js
Expand Up @@ -21,16 +21,6 @@ describe('makeWebpackConfig', () => {
const defaultConfig = makeWebpackConfig();
const newRules = [{ test: /\.js$/, use: [{ loader: 'other-loader' }] }];

const originalWarn = console.warn;

beforeEach(() => {
console.warn = jest.fn();
});

afterEach(() => {
console.warn = originalWarn;
});

it('Rules include js and css by default', () => {
expect(defaultConfig.module.rules.length).toBe(DEFAULT_RULES_LENGTH);
expect(defaultConfig.module.rules[0]).toEqual(makeJS());
Expand All @@ -48,6 +38,11 @@ describe('makeWebpackConfig', () => {
expect(config.module.rules.find(rule => rule.test.test('.tsx'))).toEqual(ts);
});

it('passing ts adds extensions to resolve', () => {
const config = makeWebpackConfig({ ts: true });
expect(config.resolve.extensions).toEqual(['.ts', '.tsx', '.js', '.json']);
});

it('User can add to `rules` array', () => {
const config = makeWebpackConfig({
rules: [...defaultWebpackRules, ...newRules],
Expand Down Expand Up @@ -139,13 +134,6 @@ describe('makeWebpackConfig', () => {
`('User can update $option', ({ option, value }) => {
const config = makeWebpackConfig({ [option]: value });
expect(config[option]).toBe(value);
expect(console.warn).not.toBeCalled();
});

it('warns (but allows) unrecognized config options', () => {
const config = makeWebpackConfig({ foo: 'bar' });
expect(config.foo).toBe('bar');
expect(console.warn).toBeCalled();
});
});
});
Expand Down
15 changes: 5 additions & 10 deletions index.js
Expand Up @@ -121,10 +121,7 @@ const makeCSS = ({ cssLoaderOptions, sassLoaderOptions, use = defaultCSSUse } =
const defaultWebpackRules = [makeJS(), makeCSS()];

const makeWebpackConfig = (options = {}) => {
const {
js,
ts,
css,
let {
node,
serve,
stats,
Expand All @@ -146,11 +143,7 @@ const makeWebpackConfig = (options = {}) => {
...rest
} = options;

if (Object.keys(rest).length) {
for (const key in rest) {
console.warn(`${key} is unrecognized, but it will be added to the config.`);
}
}
const { js, ts, css, ...webpackOptions } = options;

let customRules = rules;

Expand All @@ -164,10 +157,12 @@ const makeWebpackConfig = (options = {}) => {

if (ts) {
customRules = [...rules, ts === true ? makeTS() : ts];
resolve = { extensions: ['.ts', '.tsx', '.js', '.json'] };
}

return {
...options,
...webpackOptions,
resolve,
mode,
target,
module: {
Expand Down

0 comments on commit 6e62c49

Please sign in to comment.