Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for .cjs config #1727

Merged
merged 5 commits into from Aug 5, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions packages/webpack-cli/lib/groups/ConfigGroup.js
Expand Up @@ -42,6 +42,16 @@ const getDefaultConfigFiles = () => {

const getConfigInfoFromFileName = (filename) => {
const fileMetaData = parse(filename);
// .cjs is not available on interpret side, handle it manually for now
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (filename.endsWith('.cjs')) {
return [
{
path: resolve(filename),
ext: '.cjs',
module: null,
},
];
}
return Object.keys(extensions)
.filter((ext) => ext.includes(fileMetaData.ext))
.filter((ext) => fileMetaData.base.substr(fileMetaData.base.length - ext.length) === ext)
Expand Down
12 changes: 12 additions & 0 deletions test/config-format/commonjs/commonjs.test.js
@@ -0,0 +1,12 @@
const { run } = require('../../utils/test-utils');
const { existsSync } = require('fs');
const { resolve } = require('path');

describe('webpack cli', () => {
it('should support CommonJS file', () => {
const { stderr, stdout } = run(__dirname, ['-c', 'webpack.config.cjs'], false);
expect(stderr).toBeFalsy();
expect(stdout).toBeTruthy();
expect(existsSync(resolve(__dirname, 'dist/foo.bundle.js'))).toBeTruthy();
});
});
1 change: 1 addition & 0 deletions test/config-format/commonjs/main.js
@@ -0,0 +1 @@
console.log('Hoshiumi');
12 changes: 12 additions & 0 deletions test/config-format/commonjs/webpack.config.cjs
@@ -0,0 +1,12 @@
const path = require('path');

const config = {
mode: 'production',
entry: './main.js',
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'foo.bundle.js',
},
};

module.exports = config;
File renamed without changes.
@@ -1,6 +1,6 @@
/* eslint-disable node/no-missing-require */
/* eslint-disable node/no-unpublished-require */
const { run, runInstall } = require('../utils/test-utils');
const { run, runInstall } = require('../../utils/test-utils');
const { stat } = require('fs');
const { resolve } = require('path');

Expand Down
@@ -1,3 +1,4 @@
/* eslint-disable node/no-unsupported-features/es-syntax */
/** eslint-disable **/
import * as path from 'path';

Expand Down