aboutsummaryrefslogtreecommitdiffstats
path: root/build/tasks/build.js
diff options
context:
space:
mode:
Diffstat (limited to 'build/tasks/build.js')
-rw-r--r--build/tasks/build.js43
1 files changed, 27 insertions, 16 deletions
diff --git a/build/tasks/build.js b/build/tasks/build.js
index e1dd39993..79498d012 100644
--- a/build/tasks/build.js
+++ b/build/tasks/build.js
@@ -17,27 +17,33 @@ module.exports = function( grunt ) {
return grunt.file.read( `${ srcFolder }/${ fileName }` );
};
- // Catch `// @CODE` and subsequent comment lines event if they don't start
- // in the first column.
- const wrapper = read( "wrapper.js" )
- .split( /[\x20\t]*\/\/ @CODE\n(?:[\x20\t]*\/\/[^\n]+\n)*/ );
-
const inputFileName = "jquery.js";
const inputRollupOptions = {
input: `${ srcFolder }/${ inputFileName }`
};
- const outputRollupOptions = {
- // The ESM format is not actually used as we strip it during
- // the build; it's just that it doesn't generate any extra
- // wrappers so there's nothing for us to remove.
- format: "esm",
+ function getOutputRollupOptions( {
+ esm = false
+ } = {} ) {
+ const wrapperFileName = `wrapper${ esm ? "-esm" : "" }.js`;
+
+ // Catch `// @CODE` and subsequent comment lines event if they don't start
+ // in the first column.
+ const wrapper = read( wrapperFileName )
+ .split( /[\x20\t]*\/\/ @CODE\n(?:[\x20\t]*\/\/[^\n]+\n)*/ );
+
+ return {
+
+ // The ESM format is not actually used as we strip it during the
+ // build, inserting our own wrappers; it's just that it doesn't
+ // generate any extra wrappers so there's nothing for us to remove.
+ format: "esm",
+
+ intro: `${ wrapper[ 0 ].replace( /\n*$/, "" ) }`,
+ outro: wrapper[ 1 ].replace( /^\n*/, "" )
+ };
+ }
- intro: wrapper[ 0 ]
- .replace( /\n*$/, "" ),
- outro: wrapper[ 1 ]
- .replace( /^\n*/, "" )
- };
const fileOverrides = new Map();
function getOverride( filePath ) {
@@ -62,6 +68,8 @@ module.exports = function( grunt ) {
const flags = this.flags;
const optIn = flags[ "*" ];
let name = grunt.option( "filename" );
+ const esm = !!grunt.option( "esm" );
+ const distFolder = grunt.option( "dist-folder" );
const minimum = this.data.minimum;
const removeWith = this.data.removeWith;
const excluded = [];
@@ -185,7 +193,7 @@ module.exports = function( grunt ) {
// Filename can be passed to the command line using
// command line options
// e.g. grunt build --filename=jquery-custom.js
- name = name ? `dist/${ name }` : this.data.dest;
+ name = name ? `${ distFolder }/${ name }` : this.data.dest;
// append commit id to version
if ( process.env.COMMIT ) {
@@ -296,6 +304,9 @@ module.exports = function( grunt ) {
plugins: [ rollupFileOverrides( fileOverrides ) ]
} );
+ const outputRollupOptions =
+ getOutputRollupOptions( { esm } );
+
const { output: [ { code } ] } = await bundle.generate( outputRollupOptions );
const compiledContents = code