Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
renderChunk (code) {
const str = new MagicString(code);
str.replace(
/\/((?:[^\n\r[\\\/]|\\.|\[(?:[^\n\r\\\]]|\\.)*\])+)\/\s*\.\s*source\b/g,

Check warning on line 253 in scripts/build.js

View workflow job for this annotation

GitHub Actions / lint

Unnecessary escape character: \/
(m, /** @type {string} */ source) => {
// escape backslashes
source = source.replace(
Expand Down Expand Up @@ -297,7 +297,7 @@
renderChunk (code) {
const str = new MagicString(code);
str.replace(
/^(?<indent>[ \t]+)grammar: (\{[\s\S]*?^\k<indent>\})/m,

Check warning on line 300 in scripts/build.js

View workflow job for this annotation

GitHub Actions / lint

The quantifier '[\s\S]*?' is always entered despite having a minimum of 0. This is because the assertion '^' contradicts with the element(s) after the quantifier. Either set the minimum to 1 (+?) or change the assertion
(m, _, /** @type {string} */ grammar) => `\tgrammar: () => (${grammar})`
);
return toRenderedChunk(str);
Expand Down Expand Up @@ -334,7 +334,8 @@
};
}

const terserPlugin = rollupTerser({
/** @type {import('@rollup/plugin-terser').Options} */
const terserOptions = {
ecma: 2020,
module: true,
compress: {
Expand All @@ -348,7 +349,8 @@
comments: false,
},
keep_classnames: true,
});
};
const terserPlugin = rollupTerser(terserOptions);

async function clean () {
const outputDir = path.join(__dirname, '../dist');
Expand Down Expand Up @@ -404,7 +406,6 @@
const input = {
'index': path.join(SRC_DIR, 'index.js'),
'global': path.join(SRC_DIR, 'global.js'),
'prism': path.join(SRC_DIR, 'prism.global.js'),
'shared': path.join(SRC_DIR, 'shared.js'),
};
for (const id of languageIds) {
Expand Down Expand Up @@ -446,6 +447,24 @@
format: 'cjs',
},
},
iife: {
rollupOptions: {
...defaultRollupOptions,
input: path.join(SRC_DIR, 'auto-start.js'),
plugins: [
...defaultRollupOptions.plugins.slice(0, -1), // remove default terser plugin
rollupTerser({ ...terserOptions, module: false }),
],
},
outputOptions: {
...defaultOutputOptions,
dir: undefined,
file: path.join(DIST_DIR, 'prism.js'),
format: 'iife',
name: 'Prism',
exports: 'default',
},
},
};

try {
Expand Down
5 changes: 4 additions & 1 deletion src/global.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ import globalPrism from './core/prism.js';
*
* This instance of Prism is unique. Even if this module is imported from
* different sources, the same Prism instance will be returned.
*
* When a global build (IIFE) has already set `globalThis.Prism`, this
* module reuses that instance so ESM plugins share the same singleton.
*/
export default globalPrism;
export default globalThis.Prism?.constructor?.name === 'Prism' ? globalThis.Prism : globalPrism;
7 changes: 0 additions & 7 deletions src/prism.global.js

This file was deleted.

Loading