mirror of
https://github.com/developit/microbundle.git
synced 2026-01-18 13:56:35 +00:00
Fix broken --alias option
This commit is contained in:
parent
a0fd75e85c
commit
39dad8e724
@ -57,6 +57,7 @@
|
||||
"gzip-size": "^5.0.0",
|
||||
"pretty-bytes": "^5.1.0",
|
||||
"rollup": "^0.67.3",
|
||||
"rollup-plugin-alias": "^1.5.1",
|
||||
"rollup-plugin-babel": "^4.1.0-0",
|
||||
"rollup-plugin-buble": "^0.19.4",
|
||||
"rollup-plugin-bundle-size": "^1.0.1",
|
||||
|
||||
25
src/index.js
25
src/index.js
@ -11,6 +11,7 @@ import babel from 'rollup-plugin-babel';
|
||||
import nodeResolve from 'rollup-plugin-node-resolve';
|
||||
import buble from 'rollup-plugin-buble';
|
||||
import { terser } from 'rollup-plugin-terser';
|
||||
import alias from 'rollup-plugin-alias';
|
||||
import postcss from 'rollup-plugin-postcss';
|
||||
import gzipSize from 'gzip-size';
|
||||
import brotliSize from 'brotli-size';
|
||||
@ -35,6 +36,9 @@ const parseMappingArgument = globalStrings => {
|
||||
return globals;
|
||||
};
|
||||
|
||||
// Extensions to use when resolving modules
|
||||
const EXTENSIONS = ['.ts', '.tsx', '.js', '.jsx', '.es6', '.es', '.mjs'];
|
||||
|
||||
const WATCH_OPTS = {
|
||||
exclude: 'node_modules/**',
|
||||
};
|
||||
@ -287,15 +291,16 @@ function createConfig(options, entry, format, writeMeta) {
|
||||
options.entries.filter(e => e !== entry),
|
||||
);
|
||||
|
||||
let aliases = {};
|
||||
let outputAliases = {};
|
||||
// since we transform src/index.js, we need to rename imports for it:
|
||||
if (options.multipleEntries) {
|
||||
aliases['.'] = './' + basename(options.output);
|
||||
}
|
||||
if (options.alias) {
|
||||
aliases = Object.assign(aliases, parseMappingArgument(options.alias));
|
||||
outputAliases['.'] = './' + basename(options.output);
|
||||
}
|
||||
|
||||
const moduleAliases = options.alias
|
||||
? parseMappingArgument(options.alias)
|
||||
: {};
|
||||
|
||||
const peerDeps = Object.keys(pkg.peerDependencies || {});
|
||||
if (options.external === 'none') {
|
||||
// bundle everything (external=[])
|
||||
@ -396,6 +401,12 @@ function createConfig(options, entry, format, writeMeta) {
|
||||
inject: false,
|
||||
extract: !!writeMeta,
|
||||
}),
|
||||
Object.keys(moduleAliases).length > 0 &&
|
||||
alias(
|
||||
Object.assign({}, moduleAliases, {
|
||||
resolve: EXTENSIONS,
|
||||
}),
|
||||
),
|
||||
nodeResolve({
|
||||
module: true,
|
||||
jsnext: true,
|
||||
@ -431,7 +442,7 @@ function createConfig(options, entry, format, writeMeta) {
|
||||
// supplied configurations we set this option to false. Note
|
||||
// that we never supported using custom babel configs anyway.
|
||||
babelrc: false,
|
||||
extensions: ['.ts', '.tsx', '.js', '.jsx', '.es6', '.es', '.mjs'],
|
||||
extensions: EXTENSIONS,
|
||||
exclude: 'node_modules/**',
|
||||
plugins: [
|
||||
require.resolve('@babel/plugin-syntax-jsx'),
|
||||
@ -542,7 +553,7 @@ function createConfig(options, entry, format, writeMeta) {
|
||||
},
|
||||
|
||||
outputOptions: {
|
||||
paths: aliases,
|
||||
paths: outputAliases,
|
||||
globals,
|
||||
strict: options.strict === true,
|
||||
legacy: true,
|
||||
|
||||
@ -1,5 +1,30 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`fixtures alias 1`] = `
|
||||
"Used script: microbundle --no-sourcemap -f cjs --alias ./constants=./constants-debug
|
||||
|
||||
Directory tree:
|
||||
|
||||
alias
|
||||
dist
|
||||
alias-mapping.js
|
||||
package.json
|
||||
src
|
||||
constants-debug.js
|
||||
constants.js
|
||||
index.js
|
||||
|
||||
|
||||
Build \\"aliasMapping\\" to dist:
|
||||
62 B: alias-mapping.js.gz
|
||||
46 B: alias-mapping.js.br"
|
||||
`;
|
||||
|
||||
exports[`fixtures alias 2`] = `
|
||||
"console.log(\\"DEBUG should be true: \\",!0);
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`fixtures async-iife-ts 1`] = `
|
||||
"Used script: microbundle
|
||||
|
||||
|
||||
6
test/fixtures/alias/package.json
vendored
Normal file
6
test/fixtures/alias/package.json
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
{
|
||||
"name": "alias-mapping",
|
||||
"scripts": {
|
||||
"build": "microbundle --no-sourcemap -f cjs --alias ./constants=./constants-debug"
|
||||
}
|
||||
}
|
||||
1
test/fixtures/alias/src/constants-debug.js
vendored
Normal file
1
test/fixtures/alias/src/constants-debug.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
export const DEBUG = true;
|
||||
1
test/fixtures/alias/src/constants.js
vendored
Normal file
1
test/fixtures/alias/src/constants.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
export const DEBUG = false;
|
||||
2
test/fixtures/alias/src/index.js
vendored
Normal file
2
test/fixtures/alias/src/index.js
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
import { DEBUG } from './constants';
|
||||
console.log('DEBUG should be true: ', DEBUG);
|
||||
Loading…
x
Reference in New Issue
Block a user