Comparing version 1.2.2 to 1.2.3
@@ -16,3 +16,16 @@ "use strict"; | ||
const MAJOR_NODE_VERSION = process.versions.node.split(".")[0]; | ||
let esbuildInput = { | ||
stdin: { | ||
contents: "", | ||
resolveDir: "", | ||
sourcefile: "", | ||
loader: "ts" | ||
}, | ||
format: "cjs", | ||
target: [`node${process.versions.node.split(".")[0]}`], | ||
sourcemap: "inline", | ||
bundle: true, | ||
write: false | ||
}; | ||
let textDecoder = new TextDecoder("utf-8"); | ||
@@ -24,18 +37,7 @@ function loader(_code) { | ||
const compilation = this._compilation; | ||
const context = compilation.compiler.context; | ||
let result = (0, _esbuild.buildSync)({ | ||
stdin: { | ||
contents: code, | ||
resolveDir: context, | ||
sourcefile: _path.default.basename(this.resourcePath) + ".js", | ||
loader: "ts" | ||
}, | ||
format: "cjs", | ||
target: [`node${MAJOR_NODE_VERSION}`], | ||
sourcemap: "inline", | ||
bundle: true, | ||
write: false | ||
}); | ||
return (0, _atbuild.requireFromString)(new TextDecoder("utf-8").decode(result.outputFiles[0].contents), this.resourcePath); // const workerContext = {}; | ||
esbuildInput.stdin.contents = code; | ||
esbuildInput.stdin.resolveDir = this._compilation.compiler.context; | ||
esbuildInput.stdin.sourcefile = _path.default.basename(this.resourcePath) + ".js"; | ||
const result = (0, _esbuild.buildSync)(esbuildInput); | ||
return (0, _atbuild.requireFromString)(textDecoder.decode(result.outputFiles[0].contents), this.resourcePath); // const workerContext = {}; | ||
// const filename = this.resourcePath; | ||
@@ -42,0 +44,0 @@ // workerContext.options = { |
{ | ||
"name": "atbuild", | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"main": "dist/atbuild.js", | ||
@@ -9,3 +9,5 @@ "license": "MIT", | ||
"./package.json", | ||
"dist" | ||
"dist", | ||
"./webpack-loader.js", | ||
"./index.js" | ||
], | ||
@@ -12,0 +14,0 @@ "bin": { |
@@ -75,5 +75,7 @@ # AtBuild – JavaScript Preprocessor | ||
**October 29th, 2020**: Added support for bundling buildtime code in the webpack loader, meaning you can use the same syntax for buildtime code and runtime code. The webpack-loader uses [esbuild](https://esbuild.github.io/) for bundling the backend code. | ||
**October 28th, 2020**: Extremely WIP VSCode extension. | ||
**October 28th, 2020**: Added support for `require` in buildtime code. Runtime code works like normal and is run through Babel or any other loaders you use. Buildtime code isn't run through babel, but this might be implemented later via webpack's `this._compilation_.createChildCompiler`, which would run buildtime and runtime code both through webpack. | ||
**October 28th, 2020**: Added support for `require` in buildtime code. Runtime code works like normal and is run through Babel or any other loaders you use. ~Buildtime code isn't run through babel, but this might be implemented later via webpack's `this._compilation_.createChildCompiler`, which would run buildtime and runtime code both through webpack.~ Fixed | ||
@@ -139,2 +141,6 @@ ## Why? | ||
Buildtime code is run through a [high performance bundler](https://esbuild.github.io/) for you automatically, so you can write your buildtime code using the same modern JavaScript as the rest of your code. This also means you can import other modules, and those modules don't have to be `.@js` files - they can be any other file in your codebase (so long as it runs in Node after bundling). | ||
Runtime code is passed through webpack as regular JavaScript – so you can still use babel-loader as normal. | ||
``` | ||
@@ -157,5 +163,5 @@ // Webpack config | ||
{ | ||
loader: "atbuild/dist/webpack-loader | ||
loader: "atbuild/webpack-loader | ||
}, | ||
// Run Babel afterwards | ||
// Run Babel on the runtime code afterwards (optional) | ||
{ | ||
@@ -205,3 +211,3 @@ loader: "babel-loader", | ||
// This is where the webpack loader is added. | ||
loader: "atbuild/dist/webpack-loader", | ||
loader: "atbuild/webpack-loader", | ||
}, | ||
@@ -216,6 +222,4 @@ ], | ||
The important thing to note that is that you still want to run Babel on the output from AtBuild. That way, you can still write your code like any other part of your app. | ||
## Alternatives | ||
- [`babel-plugin-codegen`](https://github.com/kentcdodds/babel-plugin-codegen) makes it easy to run build scripts, but it gets tough if you want to do some things at buildtime and some other things at run-time for the same code. |
35119
718
221