Skip to content
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

transpile bundles for ie support #3

Merged
merged 1 commit into from
Aug 2, 2019
Merged
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
node_modules/
.cache/
3 changes: 3 additions & 0 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
<link href="https://fonts.googleapis.com/css?family=Barlow+Semi+Condensed&display=swap" rel="stylesheet">
<link rel="stylesheet" href="./css/bootstrap.min.css">
<!-- <link rel="stylesheet" href="./css/dx-styles.css"> -->

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.4.3/polyfill.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/custom-elements/1.2.4/custom-elements.min.js"></script>
</head>

<body>
Expand Down
3 changes: 3 additions & 0 deletions tasks/build.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
process.env.NODE_ENV = 'production';
const transpileForIE = require('./transpile-for-ie');


const Bundler = require("parcel-bundler"),
Path = require("path"),
Expand Down Expand Up @@ -26,5 +28,6 @@ fs.removeSync('dist');
const bundler = new Bundler(entryFiles, options);

bundler.bundle().then(() => {
transpileForIE("dist");
console.log("done building");
}, e => console.log(e));
9 changes: 8 additions & 1 deletion tasks/dev.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const transpileForIE = require('./transpile-for-ie');

const Bundler = require("parcel-bundler"),
Path = require("path"),
browserSync = require("browser-sync").create(),
Expand Down Expand Up @@ -31,7 +33,12 @@ bundler.on("bundled", async () => {
});

bundler.on("buildEnd", () => {
browserSync.reload();
// setTimeout is to avoid browserSync throwing an error
// after the IE11 transpile is done
setTimeout(function() {
transpileForIE("dist");
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you comment out this "transpileForIE" call in the dev task, you'll at least have accurate source maps while developing. Just won't be able to develop using IE.

browserSync.reload();
},0)
});

bundler.bundle();
37 changes: 37 additions & 0 deletions tasks/transpile-for-ie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const fs = require('fs-extra');
const babel = require('@babel/core')

function transpileFileForIE(path) {
const code = babel.transformFileSync(path, {
"presets": [
[
"@babel/preset-env",
{
"modules": false,
"targets": {
"ie": "11"
}
}
]
]
}).code;
fs.writeFileSync(path, code);
}

function transpileForIE(folderPath) {
const files = fs.readdirSync(`${folderPath}`);

const filesToBuildForIE = [];
files.forEach(file => {
if (file.indexOf('.js') === file.length-3) {
filesToBuildForIE.push(file);
}
});

for (let i=0;i<filesToBuildForIE.length;i++) {
transpileFileForIE(`${folderPath}/${filesToBuildForIE[i]}`);
}

console.log("JS bundles transpiled to ES5 for IE11 support.");
}
module.exports = transpileForIE;