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

feat: expose babelOptions for Marko 5 compiler #25

Merged
merged 1 commit into from
Feb 27, 2020
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
32 changes: 28 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default [
module: {
rules: [
{
test: /\.marko?$/,
test: /\.marko$/,
loader: "@marko/webpack/loader"
}
]
Expand All @@ -84,7 +84,7 @@ export default [
{
rules: [
{
test: /\.marko?$/,
test: /\.marko$/,
loader: "@marko/webpack/loader"
},
// If using `style` blocks with Marko you must use an appropriate loader
Expand All @@ -98,6 +98,30 @@ export default [
];
```

## Babel options (Marko 5+)

If you are using Marko 5 with this plugin you can manually override the Babel configuration used by passing a `babelOptions` object along side the `@marko/webpack/loader`. By default Babels regular [config file resolution](https://babeljs.io/docs/en/config-files) will be used.

```javascript
export default {
module: {
rules: [
{
test: /\.marko$/,
loader: "@marko/webpack/loader",
options: {
babelOptions: {
presets: [
["@babel/preset-env", { node: "current" }]
]
}
}
}
]
}
},
```

## Multiple client side compilers

Sometimes you need to have multiple compilers for your client side bundles. For example with [`i18n`](https://github.com/webpack/webpack/tree/master/examples/i18n) or [even shipping dynamic runtime bundles to the browser](https://github.com/eBay/arc/tree/master/packages/arc-webpack).
Expand All @@ -124,7 +148,7 @@ export default [
module: {
rules: [
{
test: /\.marko?$/,
test: /\.marko$/,
loader: "@marko/webpack/loader"
}
]
Expand All @@ -135,7 +159,7 @@ export default [
name: `Browser-${language}`,
rules: [
{
test: /\.marko?$/,
test: /\.marko$/,
loader: "@marko/webpack/loader"
},
// If using `style` blocks with Marko you must use an appropriate loader
Expand Down
23 changes: 20 additions & 3 deletions src/loader/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,20 @@ export default function(source: string): string {
// eslint-disable-next-line @typescript-eslint/no-var-requires
const markoCompiler = require((queryOptions && queryOptions.compiler) ||
DEFAULT_COMPILER);
const babelOptions = Object.assign(
{},
queryOptions && queryOptions.babelOptions
);
babelOptions.caller = Object.assign(
{
target: this.target,
supportsStaticESM: true,
supportsDynamicImport: true,
supportsTopLevelAwait: true
},
babelOptions.caller
);

const dependenciesOnly = this.resource.endsWith("?dependencies");
const hydrate = this.resource.endsWith("?hydrate");
const assets = this.resource.endsWith("?assets");
Expand Down Expand Up @@ -94,7 +108,8 @@ export default function(source: string): string {
{
writeToDisk: false,
requireTemplates: true,
writeVersionComment: false
writeVersionComment: false,
babelOptions
}
);
} else if (hydrate) {
Expand All @@ -116,7 +131,8 @@ export default function(source: string): string {
sourceOnly: false,
writeToDisk: false,
writeVersionComment: false,
sourceMaps
sourceMaps,
babelOptions
}
);

Expand Down Expand Up @@ -198,7 +214,8 @@ export default function(source: string): string {
writeToDisk: false,
requireTemplates: true,
writeVersionComment: false,
sourceMaps
sourceMaps,
babelOptions
}
);

Expand Down