Skip to content

Commit

Permalink
Switched to webpack bundling
Browse files Browse the repository at this point in the history
  • Loading branch information
marekdedic committed Oct 22, 2022
1 parent da80600 commit 74cfbe4
Show file tree
Hide file tree
Showing 22 changed files with 1,424 additions and 134 deletions.
85 changes: 16 additions & 69 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ const cleanCSS = require('gulp-clean-css');
const concat = require('gulp-concat');
const inject = require('gulp-inject-string');
const merge = require('merge-stream');
const named = require('vinyl-named');
const rename = require('gulp-rename');
const replace = require('gulp-replace');
const shell = require('gulp-shell');
const terser = require('gulp-terser');
const ts = require('gulp-typescript');
const webpack = require('webpack-stream');

gulp.task('build:css:admin', function () {
return gulp
Expand Down Expand Up @@ -120,78 +122,23 @@ gulp.task(
gulp.task('build:deps', gulp.parallel('build:deps:composer', 'build:deps:npm'));

gulp.task('build:js:admin', function () {
function bundle(name, sources, jQuery = false) {
const tsProject = ts.createProject('tsconfig.json');
let ret = gulp
.src(sources.concat(['src/d.ts/*.d.ts']))
.pipe(tsProject())
.js.pipe(concat(name + '.min.js'));
if (jQuery) {
ret = ret
.pipe(inject.prepend('jQuery( function( $ ) {\n'))
.pipe(inject.append('} );\n'));
}
return ret.pipe(terser()).pipe(gulp.dest('dist/admin/js/'));
}

return merge(
bundle(
'root_selection',
['src/ts/isError.ts', 'src/ts/admin/root_selection.ts'],
true
),
bundle(
'tinymce',
['src/ts/isError.ts', 'src/ts/admin/tinymce.ts'],
true
)
);
return gulp
.src(['src/ts/admin/root_selection.ts', 'src/ts/admin/tinymce.ts'])
.pipe(named((file) => file.stem + '.min'))
.pipe(webpack(require('./webpack.config.js')))
.pipe(inject.prepend('jQuery( function( $ ) {\n'))
.pipe(inject.append('} );\n'))
.pipe(gulp.dest('dist/admin/js/'));
});

gulp.task('build:js:frontend', function () {
function bundle(name, sources, jQuery = false) {
const tsProject = ts.createProject('tsconfig.json');
let ret = gulp
.src(sources.concat(['src/d.ts/*.d.ts']))
.pipe(tsProject())
.js.pipe(concat(name + '.min.js'));
if (jQuery) {
ret = ret
.pipe(inject.prepend('jQuery( function( $ ) {\n'))
.pipe(inject.append('} );\n'));
}
return ret.pipe(terser()).pipe(gulp.dest('dist/frontend/js/'));
}

return merge(
bundle(
'block',
[
'src/ts/isError.ts',
'src/ts/frontend/block/SgdgEditorComponent.ts',
'src/ts/frontend/block/SgdgBlockIconComponent.ts',
'src/ts/frontend/block.ts',
'src/ts/frontend/block/SgdgSettingsComponent.ts',
'src/ts/frontend/block/SgdgBooleanSettingsComponent.ts',
'src/ts/frontend/block/SgdgIntegerSettingsComponent.ts',
'src/ts/frontend/block/SgdgOrderingSettingsComponent.ts',
'src/ts/frontend/block/SgdgSettingsOverrideComponent.ts',
'src/ts/frontend/interfaces/Attributes.ts',
],
true
),
bundle(
'shortcode',
[
'src/ts/isError.ts',
'src/ts/frontend/shortcode/QueryParameter.ts',
'src/ts/frontend/shortcode/Shortcode.ts',
'src/ts/frontend/shortcode/ShortcodeRegistry.ts',
'src/ts/frontend/shortcode.ts',
],
true
)
);
return gulp
.src(['src/ts/frontend/block.ts', 'src/ts/frontend/shortcode.ts'])
.pipe(named((file) => file.stem + '.min'))
.pipe(webpack(require('./webpack.config.js')))
.pipe(inject.prepend('jQuery( function( $ ) {\n'))
.pipe(inject.append('} );\n'))
.pipe(gulp.dest('dist/frontend/js/'));
});

gulp.task('build:js', gulp.parallel('build:js:admin', 'build:js:frontend'));
Expand Down
Loading

0 comments on commit 74cfbe4

Please sign in to comment.