Skip to content

Instantly share code, notes, and snippets.

@CompuIves
Created August 26, 2017 16:43
Show Gist options
  • Save CompuIves/d19878f5dd40f212786ca499a4b730e6 to your computer and use it in GitHub Desktop.
Save CompuIves/d19878f5dd40f212786ca499a4b730e6 to your computer and use it in GitHub Desktop.
import babelTranspiler from '../../transpilers/babel';
import jsonTranspiler from '../../transpilers/json';
import stylesTranspiler from '../../transpilers/css';
import sassTranspiler from '../../transpilers/sass';
import rawTranspiler from '../../transpilers/raw';
import stylusTranspiler from '../../transpilers/stylus';
import lessTranspiler from '../../transpilers/less';
import asyncTranspiler from './transpilers/async';
import Preset from '../';
const preactPreset = new Preset(
'preact-cli',
['js', 'jsx', 'ts', 'tsx', 'json', 'less', 'scss', 'sass', 'styl', 'css'],
{
preact$: 'preact',
// preact-compat aliases for supporting React dependencies:
react: 'preact-compat',
'react-dom': 'preact-compat',
'create-react-class': 'preact-compat/lib/create-react-class',
'react-addons-css-transition-group': 'preact-css-transition-group'
}
);
preactPreset.registerTranspiler(module => /\.jsx?$/.test(module.title), [
{
transpiler: babelTranspiler,
options: {
presets: [
// babel preset env starts with latest, then drops rules.
// We don't have env, so we just support latest
'latest',
'stage-1'
],
plugins: [
'transform-object-assign',
'transform-decorators-legacy',
['transform-react-jsx', { pragma: 'h' }],
[
'jsx-pragmatic',
{
module: 'preact',
export: 'h',
import: 'h'
}
]
]
}
}
]);
preactPreset.registerTranspiler(module => /\.s[a|c]ss/.test(module.title), [
{ transpiler: sassTranspiler },
{ transpiler: stylesTranspiler }
]);
preactPreset.registerTranspiler(module => /\.less/.test(module.title), [
{ transpiler: lessTranspiler },
{ transpiler: stylesTranspiler }
]);
preactPreset.registerTranspiler(module => /\.json/.test(module.title), [
{ transpiler: jsonTranspiler }
]);
preactPreset.registerTranspiler(module => /\.styl/.test(module.title), [
{ transpiler: stylusTranspiler },
{ transpiler: stylesTranspiler }
]);
// Support for !async statements
preactPreset.registerTranspiler(
() => false /* never load without explicit statement */,
[{ transpiler: asyncTranspiler }]
);
// This transpiler is backup for all other files
preactPreset.registerTranspiler(() => true, [{ transpiler: rawTranspiler }]);
export default preactPreset;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment