Skip to content

Commit 224d063

Browse files
authored
Merge pull request #1466 from myfreeer/grunt-transpile
grunt: skip babel transpile for core-js
2 parents caadcb1 + c339126 commit 224d063

File tree

3 files changed

+77
-26
lines changed

3 files changed

+77
-26
lines changed

gruntfile.js

Lines changed: 61 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ module.exports = function(grunt) {
66
grunt.loadNpmTasks('grunt-terser');
77
grunt.loadNpmTasks('grunt-contrib-jasmine');
88
grunt.loadNpmTasks('grunt-contrib-copy');
9+
grunt.loadNpmTasks('grunt-exorcise');
910

1011
grunt.initConfig({
1112
babel: {
@@ -22,57 +23,91 @@ module.exports = function(grunt) {
2223
},
2324
],
2425
},
25-
bundle: {
26-
files: [
27-
{
28-
cwd: './build',
29-
expand: true,
30-
src: ['exceljs.bare.js', 'exceljs.js'],
31-
dest: './dist/',
32-
},
33-
],
34-
},
3526
},
3627
browserify: {
37-
bare: {
38-
src: ['./build/lib/exceljs.bare.js'],
39-
dest: './build/exceljs.bare.js',
40-
options: {
41-
browserifyOptions: {
42-
standalone: 'ExcelJS',
43-
},
28+
options: {
29+
transform: [
30+
['babelify', {
31+
// enable babel transpile for node_modules
32+
global: true,
33+
presets: ['@babel/preset-env'],
34+
// core-js should not be transpiled
35+
// See https://github.com/zloirock/core-js/issues/514
36+
ignore: [/node_modules[\\/]core-js/],
37+
}],
38+
],
39+
browserifyOptions: {
40+
// enable source map for browserify
41+
debug: true,
42+
standalone: 'ExcelJS',
4443
},
4544
},
45+
bare: {
46+
// keep the original source for source maps
47+
src: ['./lib/exceljs.bare.js'],
48+
dest: './dist/exceljs.bare.js',
49+
},
4650
bundle: {
47-
src: ['./build/lib/exceljs.browser.js'],
48-
dest: './build/exceljs.js',
49-
options: {
50-
browserifyOptions: {
51-
standalone: 'ExcelJS',
52-
},
53-
},
51+
// keep the original source for source maps
52+
src: ['./lib/exceljs.browser.js'],
53+
dest: './dist/exceljs.js',
5454
},
5555
spec: {
56+
options: {
57+
transform: null,
58+
browserifyOptions: null,
59+
},
5660
src: ['./build/spec/browser/exceljs.spec.js'],
5761
dest: './build/web/exceljs.spec.js',
5862
},
5963
},
64+
6065
terser: {
6166
options: {
62-
sourceMap: true,
6367
output: {
6468
preamble: '/*! ExcelJS <%= grunt.template.today("dd-mm-yyyy") %> */\n',
6569
ascii_only: true,
6670
},
6771
},
6872
dist: {
73+
options: {
74+
// Keep the original source maps from browserify
75+
// See also https://www.npmjs.com/package/terser#source-map-options
76+
sourceMap: {
77+
content: 'inline',
78+
url: 'exceljs.min.js.map',
79+
},
80+
},
6981
files: {
7082
'./dist/exceljs.min.js': ['./dist/exceljs.js'],
83+
},
84+
},
85+
bare: {
86+
options: {
87+
// Keep the original source maps from browserify
88+
// See also https://www.npmjs.com/package/terser#source-map-options
89+
sourceMap: {
90+
content: 'inline',
91+
url: 'exceljs.bare.min.js.map',
92+
},
93+
},
94+
files: {
7195
'./dist/exceljs.bare.min.js': ['./dist/exceljs.bare.js'],
7296
},
7397
},
7498
},
7599

100+
// Move source maps to a separate file
101+
exorcise: {
102+
bundle: {
103+
options: {},
104+
files: {
105+
'./dist/exceljs.js.map': ['./dist/exceljs.js'],
106+
'./dist/exceljs.bare.js.map': ['./dist/exceljs.bare.js'],
107+
},
108+
},
109+
},
110+
76111
copy: {
77112
dist: {
78113
files: [
@@ -93,6 +128,6 @@ module.exports = function(grunt) {
93128
},
94129
});
95130

96-
grunt.registerTask('build', ['babel:dist', 'browserify', 'babel:bundle', 'terser', 'copy']);
131+
grunt.registerTask('build', ['babel:dist', 'browserify', 'terser', 'exorcise', 'copy']);
97132
grunt.registerTask('ug', ['terser']);
98133
};

lib/exceljs.browser.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,23 @@
22
require('core-js/modules/es.promise');
33
require('core-js/modules/es.object.assign');
44
require('core-js/modules/es.object.keys');
5+
require('core-js/modules/es.object.values');
56
require('core-js/modules/es.symbol');
67
require('core-js/modules/es.symbol.async-iterator');
8+
// required by core-js/modules/es.promise Promise.all
9+
require('core-js/modules/es.array.iterator');
10+
// required by node_modules/saxes/saxes.js SaxesParser.captureTo
11+
require('core-js/modules/es.array.includes');
12+
// required by lib/doc/workbook.js Workbook.model
13+
require('core-js/modules/es.array.find-index');
14+
// required by lib/doc/workbook.js Workbook.addWorksheet and Workbook.getWorksheet
15+
require('core-js/modules/es.array.find');
16+
// required by node_modules/saxes/saxes.js SaxesParser.getCode10
17+
require('core-js/modules/es.string.from-code-point');
18+
// required by lib/xlsx/xform/sheet/data-validations-xform.js DataValidationsXform.parseClose
19+
require('core-js/modules/es.string.includes');
20+
// required by lib/utils/utils.js utils.validInt and lib/csv/csv.js CSV.read
21+
require('core-js/modules/es.number.is-nan');
722
require('regenerator-runtime/runtime');
823

924
const ExcelJS = {

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@
134134
"grunt-contrib-copy": "^1.0.0",
135135
"grunt-contrib-jasmine": "^2.1.0",
136136
"grunt-contrib-watch": "^1.1.0",
137+
"grunt-exorcise": "^2.1.1",
137138
"grunt-terser": "^1.0.0",
138139
"husky": "^4.2.5",
139140
"lint-staged": "^10.2.13",

0 commit comments

Comments
 (0)