Comments (4)
Agreed. Thats a bug, it should do esm by default. I will fix it in the next update.
I will not switch to babel by default, since ts transpile can do esm also.
from bundler.
This is my suggestion
As long as deno supports the ts compiler API which is Deno.transpileOnly, I think this is more make sense and we can get the higher benefits when you're using the babel such as react preset or other preset which means it can support vue.js react.js anguler.js.
And this kind of plugins are really helpful to reduce the bundle size. https://www.npmjs.com/package/babel-plugin-transform-imports
const isTS = (path: string) => /\.(tsx?|ts?)$/.test(path);
const isReact = (path: string) => /\.(tsx?|jsx?)$/.test(path);
function injectDependenciesPlugin(
changeMap: ChangeMap,
outputPathMap: { [resolvedPath: string]: string },
compilerOptions: CompilerOptions,
) {
return async (input: string, output: string | undefined, depsDir: string) => {
let data: string = await fetchTextFile(input);
const moduleDeps = changeMap[input];
if (isTS(input)) {
// transpile
data = (await Deno.transpileOnly({
[input]: data
}, compilerOptions))[input].source
}
const replacer = ({
enter(path: any, state: any) {
if (path.node.source) {
const moduleNodePath = path.node.source.value;
// get relative path to dist dir
const resolvedPath = moduleDeps.dependencies[moduleNodePath];
// either name of transpiled file or new uuid name
let newPath;
const outputPath = outputPathMap[resolvedPath];
if (isURL(outputPath)) {
// keep url import instead of caching it
newPath = outputPath;
} else {
newPath = outputPathMap[resolvedPath] = outputPath ||
`${v4.generate()}.js`;
// if is named file, its dir is dist dir, else is dist/deps
newPath = join(output ? depsDir : ".", newPath);
newPath = `./${newPath}`;
}
//append relative import string
path.node.source.value = newPath;
}
}
})
try {
const outputText = await (babelCore as { transform: Function }).transform(data, {
presets: isReact(input) ? [babelPresetReact] : [],
plugins: [
() => ({
visitor: {
ImportDeclaration: replacer,
ExportAllDeclaration: replacer,
ExportNamedDeclaration: replacer
}
})
],
comments: false
}).code;
return outputText;
} catch(err) {
throw {
error: err,
data,
input
}
}
};
}
it's totally up to you :)
from bundler.
Also, I've been applied this bundler to the Attain.
This bundler generates all the files as a local file, and this meaning is the server should handle all the modules as synchronously not asynchronously.
So, I'd like to suggest in the final stage of bundle how about to use this Deno.bundle API?
from bundler.
Thanks for your suggestion.
Babel default transpiler
Deno switched to swc, so in the future this bundler should use swc as a deno plugin instead of the ts compiler. Until then, I think we should stick with ts for transpilation. But you should be able to use babel to transform/minify code with the Bundler
API.
Deno.transpileOnly
I am currently working on an implementation for system
modules, that creates a standalone module like Deno.transpileOnly
but also creates dynamically imported paths as separate modules that can be imported when needed.
from bundler.
Related Issues (20)
- how to disable export default in final js bundle file? HOT 2
- Use as a api HOT 2
- API: bundle function don't write output assets HOT 2
- API doc
- hello_world examples not working HOT 1
- Generic lambda compiled as React components HOT 1
- export default is working only with function HOT 1
- bundler and bundler api are not emiting javascript output HOT 3
- examples/server don't work HOT 2
- spa dev server example HOT 1
- project struture in read me HOT 1
- API Examples failing
- Feature Request: Support circular dependencies HOT 3
- Bundler fails to run when trying to import `acorn` via `terser` HOT 5
- Crash with CSS Gradients: `TypeError: i.walkFunctionNodes is not a function` HOT 3
- Does not understand .mjs extension / script type HOT 1
- Fails to download one of the dependency files HOT 3
- Bundler misinterprets Windows path as a url HOT 4
- Newline behavior HOT 4
- Guide for create pluging HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from bundler.