-
Notifications
You must be signed in to change notification settings - Fork 361
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
Fix problem #960
Closed
Closed
Fix problem #960
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'microbundle': patch | ||
--- | ||
|
||
Fix css compilation problems when multiple entries |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'microbundle': patch | ||
--- | ||
|
||
Fix problems related to use rollup-plugin-terser |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -111,12 +111,7 @@ export default async function microbundle(inputOptions) { | |
for (let i = 0; i < options.entries.length; i++) { | ||
for (let j = 0; j < formats.length; j++) { | ||
steps.push( | ||
createConfig( | ||
options, | ||
options.entries[i], | ||
formats[j], | ||
i === 0 && j === 0, | ||
), | ||
createConfig(options, options.entries[i], formats[j], j === 0), | ||
); | ||
} | ||
} | ||
|
@@ -333,6 +328,7 @@ function getMain({ options, entry, format }) { | |
const shebang = {}; | ||
|
||
function createConfig(options, entry, format, writeMeta) { | ||
const entryFileName = basename(entry, extname(entry)); | ||
let { pkg } = options; | ||
|
||
/** @type {(string|RegExp)[]} */ | ||
|
@@ -390,15 +386,15 @@ function createConfig(options, entry, format, writeMeta) { | |
|
||
// let rollupName = safeVariableName(basename(entry).replace(/\.js$/, '')); | ||
|
||
let nameCache = {}; | ||
const bareNameCache = nameCache; | ||
// Support "minify" field and legacy "mangle" field via package.json: | ||
const rawMinifyValue = options.pkg.minify || options.pkg.mangle || {}; | ||
let minifyOptions = typeof rawMinifyValue === 'string' ? {} : rawMinifyValue; | ||
const getNameCachePath = | ||
typeof rawMinifyValue === 'string' | ||
? () => resolve(options.cwd, rawMinifyValue) | ||
: () => resolve(options.cwd, 'mangle.json'); | ||
let minifyOptions = typeof rawMinifyValue === 'string' ? {} : rawMinifyValue; | ||
let endsWithNewLine = false; | ||
let terserOptions = {}; | ||
|
||
const useTypescript = extname(entry) === '.ts' || extname(entry) === '.tsx'; | ||
const emitDeclaration = | ||
|
@@ -415,29 +411,6 @@ function createConfig(options, entry, format, writeMeta) { | |
const externalTest = | ||
external.length === 0 ? id => false : id => externalPredicate.test(id); | ||
|
||
let endsWithNewLine = false; | ||
|
||
function loadNameCache() { | ||
try { | ||
const data = fs.readFileSync(getNameCachePath(), 'utf8'); | ||
endsWithNewLine = data.endsWith(EOL); | ||
nameCache = JSON.parse(data); | ||
// mangle.json can contain a "minify" field, same format as the pkg.mangle: | ||
if (nameCache.minify) { | ||
minifyOptions = Object.assign( | ||
{}, | ||
minifyOptions || {}, | ||
nameCache.minify, | ||
); | ||
} | ||
} catch (e) {} | ||
} | ||
loadNameCache(); | ||
|
||
normalizeMinifyOptions(minifyOptions); | ||
|
||
if (nameCache === bareNameCache) nameCache = null; | ||
|
||
/** @type {false | import('rollup').RollupCache} */ | ||
let cache; | ||
if (modern) cache = false; | ||
|
@@ -502,7 +475,7 @@ function createConfig(options, entry, format, writeMeta) { | |
extract: | ||
!!writeMeta && | ||
options.css !== 'inline' && | ||
options.output.replace(EXTENSION, '.css'), | ||
resolve(outputDir, `${entryFileName}.css`), | ||
Comment on lines
-505
to
+478
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How about changing it to this |
||
minimize: options.compress, | ||
sourceMap: options.sourcemap && options.css !== 'inline', | ||
}), | ||
|
@@ -601,43 +574,79 @@ function createConfig(options, entry, format, writeMeta) { | |
}, | ||
}), | ||
options.compress !== false && [ | ||
terser({ | ||
compress: Object.assign( | ||
{ | ||
keep_infinity: true, | ||
pure_getters: true, | ||
// Ideally we'd just get Terser to respect existing Arrow functions... | ||
// unsafe_arrows: true, | ||
passes: 10, | ||
}, | ||
typeof minifyOptions.compress === 'boolean' | ||
? minifyOptions.compress | ||
: minifyOptions.compress || {}, | ||
), | ||
format: { | ||
// By default, Terser wraps function arguments in extra parens to trigger eager parsing. | ||
// Whether this is a good idea is way too specific to guess, so we optimize for size by default: | ||
wrap_func_args: false, | ||
comments: /^\s*([@#]__[A-Z]+__\s*$|@cc_on)/, | ||
preserve_annotations: true, | ||
}, | ||
module: modern, | ||
ecma: modern ? 2017 : 5, | ||
toplevel: modern || format === 'cjs' || format === 'es', | ||
mangle: | ||
typeof minifyOptions.mangle === 'boolean' | ||
? minifyOptions.mangle | ||
: Object.assign({}, minifyOptions.mangle || {}), | ||
nameCache, | ||
}), | ||
nameCache && { | ||
terser(terserOptions), | ||
{ | ||
// before hook | ||
options: loadNameCache, | ||
options() { | ||
let nameCache = {}; | ||
const bareNameCache = nameCache; | ||
|
||
function loadNameCache() { | ||
try { | ||
const data = fs.readFileSync(getNameCachePath(), 'utf8'); | ||
endsWithNewLine = data.endsWith(EOL); | ||
nameCache = JSON.parse(data); | ||
// mangle.json can contain a "minify" field, same format as the pkg.mangle: | ||
if (nameCache.minify) { | ||
minifyOptions = Object.assign( | ||
{}, | ||
minifyOptions || {}, | ||
nameCache.minify, | ||
); | ||
} | ||
} catch (e) {} | ||
} | ||
loadNameCache(); | ||
|
||
normalizeMinifyOptions(minifyOptions); | ||
|
||
if (nameCache === bareNameCache) nameCache = null; | ||
|
||
Object.entries({ | ||
compress: Object.assign( | ||
{ | ||
keep_infinity: true, | ||
pure_getters: true, | ||
// Ideally we'd just get Terser to respect existing Arrow functions... | ||
// unsafe_arrows: true, | ||
passes: 10, | ||
}, | ||
typeof minifyOptions.compress === 'boolean' | ||
? minifyOptions.compress | ||
: minifyOptions.compress || {}, | ||
), | ||
format: { | ||
// By default, Terser wraps function arguments in extra parens to trigger eager parsing. | ||
// Whether this is a good idea is way too specific to guess, so we optimize for size by default: | ||
wrap_func_args: false, | ||
comments: /^\s*([@#]__[A-Z]+__\s*$|@cc_on)/, | ||
preserve_annotations: true, | ||
}, | ||
module: modern, | ||
ecma: modern ? 2017 : 5, | ||
toplevel: modern || format === 'cjs' || format === 'es', | ||
mangle: | ||
typeof minifyOptions.mangle === 'boolean' | ||
? minifyOptions.mangle | ||
: Object.assign({}, minifyOptions.mangle || {}), | ||
nameCache, | ||
}).forEach(([key, value]) => { | ||
terserOptions[key] = value; | ||
}); | ||
}, | ||
// after hook | ||
writeBundle() { | ||
if (writeMeta && nameCache) { | ||
if (writeMeta && terserOptions.nameCache) { | ||
try { | ||
if ( | ||
terserOptions.nameCache.minify.mangle.properties.regex | ||
) { | ||
terserOptions.nameCache.minify.mangle.properties.regex = | ||
terserOptions.nameCache.minify.mangle.properties.regex.source; | ||
} | ||
} catch (error) {} | ||
let filename = getNameCachePath(); | ||
let json = JSON.stringify(nameCache, null, 2); | ||
let json = JSON.stringify(terserOptions.nameCache, null, 2); | ||
if (endsWithNewLine) json += EOL; | ||
fs.writeFile(filename, json, () => {}); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect. Please use the existing naming setup that we had, it ensures names are properly stripped:
microbundle/src/index.js
Line 505 in 9a4e2b2
index.esm.js
as an input needs to becomeindex
; yours would have it becomeindex.esm
, soindex.esm.css
would be output. We need to strip indicators towards ES module format, i.e.,cjs
,es[m]
, etc.