Skip to content

Instantly share code, notes, and snippets.

@notiv-nt
Last active October 21, 2019 08:49
Show Gist options
  • Save notiv-nt/6d8cba689afe412d7d275957d040d304 to your computer and use it in GitHub Desktop.
Save notiv-nt/6d8cba689afe412d7d275957d040d304 to your computer and use it in GitHub Desktop.
Gulp javascript task — rollup version
const gulp = require('gulp');
gulp.task('js', async () => {
const rollup = require('rollup');
const replace = require('rollup-plugin-replace');
const postcss = require('rollup-plugin-postcss');
const resolve = require('rollup-plugin-node-resolve');
const babel = require('rollup-plugin-babel');
const { terser } = require('rollup-plugin-terser');
const commonjs = require('rollup-plugin-commonjs');
const options = {
input: ['./src/index.js'],
output: {
dir: './dist/js/',
entryFileNames: '[name].js',
sourcemap: false,
format: 'system',
// name: config.params.name,
// amd, cjs, system, esm, iife, umd
},
plugins: [
replace({
'process.env.NODE_ENV': JSON.stringify(process.env.NODE_ENV),
}),
resolve({
browser: true,
}),
commonjs(),
postcss(),
babel({
exclude: 'node_modules/**',
presets: [
[
'@babel/env',
{
useBuiltIns: 'usage',
corejs: '2',
modules: false,
targets: '>1%',
},
],
],
plugins: ['@babel/plugin-syntax-dynamic-import'],
}),
terser(),
],
};
const bundle = await rollup.rollup(options);
await bundle.generate(options);
const { output } = await bundle.write(options);
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/3.1.6/system.min.js"></script>
<script>
System.import('/assets/js/index.js');
</script>
{
"devDependencies": {
"gulp": "^4.0.2",
"@babel/core": "^7.4.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.4.5",
"rollup": "^1.16.2",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.0.1",
"rollup-plugin-node-resolve": "^5.1.0",
"rollup-plugin-postcss": "^2.0.3",
"rollup-plugin-replace": "^2.2.0",
"rollup-plugin-terser": "^5.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment