Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
grunt: skip babel transpile for core-js
Previously grunt build would transpile the output of browserify to transpile all dependencies, but this would make some dependencies, such as core-js, unexpectedly transpiled. Also, this way of transpiling would create source maps only targeting the browserify output instead of original source, and makes the final `dist/exceljs.js` larger than expected.

* Fix Symbol.toString() related errors on IE11 caused by transpiling core-js
* Reduce size for compiled dist
* Keep original source maps before browserify
  • Loading branch information
myfreeer committed Sep 17, 2020
commit 24377b6e3848bee0a53d06b023e04c7928bff79c
83 changes: 57 additions & 26 deletions gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-terser');
grunt.loadNpmTasks('grunt-contrib-jasmine');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-exorcise');

grunt.initConfig({
babel: {
Expand All @@ -22,57 +23,87 @@ module.exports = function(grunt) {
},
],
},
bundle: {
files: [
{
cwd: './build',
expand: true,
src: ['exceljs.bare.js', 'exceljs.js'],
dest: './dist/',
},
],
},
},
browserify: {
bare: {
src: ['./build/lib/exceljs.bare.js'],
dest: './build/exceljs.bare.js',
options: {
browserifyOptions: {
standalone: 'ExcelJS',
},
options: {
transform: [
['babelify', {
// enable babel transpile for node_modules
global: true,
presets: ['@babel/preset-env'],
// core-js should not be transpiled
// See https://github.com/zloirock/core-js/issues/514
ignore: [/node_modules[\\/]core-js/],
}],
],
browserifyOptions: {
// enable source map for browserify
debug: true,
standalone: 'ExcelJS',
},
},
bare: {
// keep the original source for source maps
src: ['./lib/exceljs.bare.js'],
dest: './dist/exceljs.bare.js',
},
bundle: {
src: ['./build/lib/exceljs.browser.js'],
dest: './build/exceljs.js',
options: {
browserifyOptions: {
standalone: 'ExcelJS',
},
},
// keep the original source for source maps
src: ['./lib/exceljs.browser.js'],
dest: './dist/exceljs.js',
},
spec: {
src: ['./build/spec/browser/exceljs.spec.js'],
dest: './build/web/exceljs.spec.js',
},
},

terser: {
options: {
sourceMap: true,
output: {
preamble: '/*! ExcelJS <%= grunt.template.today("dd-mm-yyyy") %> */\n',
ascii_only: true,
},
},
dist: {
options: {
// Keep the original source maps from browserify
// See also https://www.npmjs.com/package/terser#source-map-options
sourceMap: {
content: 'inline',
url: 'exceljs.min.js.map',
},
},
files: {
'./dist/exceljs.min.js': ['./dist/exceljs.js'],
},
},
bare: {
options: {
// Keep the original source maps from browserify
// See also https://www.npmjs.com/package/terser#source-map-options
sourceMap: {
content: 'inline',
url: 'exceljs.bare.min.js.map',
},
},
files: {
'./dist/exceljs.bare.min.js': ['./dist/exceljs.bare.js'],
},
},
},

// Move source maps to a separate file
exorcise: {
bundle: {
options: {},
files: {
'./dist/exceljs.js.map': ['./dist/exceljs.js'],
'./dist/exceljs.bare.js.map': ['./dist/exceljs.bare.js'],
},
},
},

copy: {
dist: {
files: [
Expand All @@ -93,6 +124,6 @@ module.exports = function(grunt) {
},
});

grunt.registerTask('build', ['babel:dist', 'browserify', 'babel:bundle', 'terser', 'copy']);
grunt.registerTask('build', ['babel:dist', 'browserify', 'terser', 'exorcise', 'copy']);
grunt.registerTask('ug', ['terser']);
};
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@
"grunt-contrib-copy": "^1.0.0",
"grunt-contrib-jasmine": "^2.1.0",
"grunt-contrib-watch": "^1.1.0",
"grunt-exorcise": "^2.1.1",
"grunt-terser": "^1.0.0",
"husky": "^4.2.5",
"lint-staged": "^10.2.13",
Expand Down