Skip to content

Commit

Permalink
support rollup.config.mjs & webpack.config.mjs
Browse files Browse the repository at this point in the history
  • Loading branch information
btakita committed Jul 19, 2021
1 parent e5c776f commit a4b26c0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/api/utils/validate_bundler.ts
Expand Up @@ -3,8 +3,8 @@ import * as fs from 'fs';
export default function validate_bundler(bundler?: 'rollup' | 'webpack') {
if (!bundler) {
bundler = (
fs.existsSync('rollup.config.js') || fs.existsSync('rollup.config.ts') ? 'rollup' :
fs.existsSync('webpack.config.js') || fs.existsSync('webpack.config.ts') ? 'webpack' : null
fs.existsSync('rollup.config.js') || fs.existsSync('rollup.config.mjs') || fs.existsSync('rollup.config.ts') ? 'rollup' :
fs.existsSync('webpack.config.js') || fs.existsSync('webpack.config.mjs') || fs.existsSync('webpack.config.ts') ? 'webpack' : null
);

if (!bundler) {
Expand Down
10 changes: 9 additions & 1 deletion src/core/create_compilers/RollupCompiler.ts
@@ -1,4 +1,5 @@
import * as path from 'path';
import { access, constants } from 'fs/promise';
import color from 'kleur';
import relative from 'require-relative';
import { dependenciesForTree, DependencyTreeOptions } from 'rollup-dependency-tree';
Expand Down Expand Up @@ -401,7 +402,14 @@ export default class RollupCompiler {
static async load_config(cwd: string) {
if (!rollup) rollup = relative('rollup', cwd);

const input = path.resolve(cwd, 'rollup.config.js');
let input: string;
try {
input = path.resolve(cwd, 'rollup.config.mjs');
await access(input, constants.F_OK | constants.R_OK);
} catch (_e) {
input = path.resolve(cwd, 'rollup.config.js');
await access(input, constants.F_OK | constants.R_OK);
}

const bundle = await rollup.rollup({
input,
Expand Down

0 comments on commit a4b26c0

Please sign in to comment.