- Notifications
You must be signed in to change notification settings - Fork 359
Fix problem#960
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
Uh oh!
There was an error while loading. Please reload this page.
Fix problem #960
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'microbundle': patch | ||
| --- | ||
| Fix css compilation problems when multiple entries |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| 'microbundle': patch | ||
| --- | ||
| Fix problems related to use rollup-plugin-terser |
| 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
Collaborator 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. ContributorAuthor 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, () => {}); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.
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.jsas an input needs to becomeindex; yours would have it becomeindex.esm, soindex.esm.csswould be output. We need to strip indicators towards ES module format, i.e.,cjs,es[m], etc.