From a4b26c0ef7369cab028c46821e0b0659eaf631fb Mon Sep 17 00:00:00 2001 From: Brian Takita Date: Mon, 19 Jul 2021 13:57:19 -0400 Subject: [PATCH] support rollup.config.mjs & webpack.config.mjs https://github.com/sveltejs/sapper/issues/1791 --- src/api/utils/validate_bundler.ts | 4 ++-- src/core/create_compilers/RollupCompiler.ts | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/api/utils/validate_bundler.ts b/src/api/utils/validate_bundler.ts index 9712e69ec..f74ab07e9 100644 --- a/src/api/utils/validate_bundler.ts +++ b/src/api/utils/validate_bundler.ts @@ -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) { diff --git a/src/core/create_compilers/RollupCompiler.ts b/src/core/create_compilers/RollupCompiler.ts index c14562b0e..f3791f635 100644 --- a/src/core/create_compilers/RollupCompiler.ts +++ b/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'; @@ -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,