diff --git a/gulpfile.js b/gulpfile.js index 6395071..cb0f123 100644 --- a/gulpfile.js +++ b/gulpfile.js @@ -2,6 +2,8 @@ const gulp = require('gulp'); const configs = require('./lib/gulp/configs.js'); +const {generateBundle} = require('./lib/gulp/js.js'); +const glob = require('util').promisify(require('glob')); // Get all tasks const clean = require('./lib/gulp/clean.js'); @@ -10,6 +12,20 @@ const {css, cssCompile} = require('./lib/gulp/css.js'); const {img, imgCompile, svgSprite} = require('./lib/gulp/image.js'); const {js, jsCompile, jsConcat} = require('./lib/gulp/js.js'); +async function getDependencyTree(files, cwd) { + let dependencyTree = await Promise.all(files.map(async src => { + const bundle = await generateBundle({src, cwd}); + return bundle.watchFiles; + })); + + dependencyTree = dependencyTree + .flat() + // https://github.com/jlmakes/karma-rollup-preprocessor/issues/30 + .filter(dependency => !dependency.includes('\u0000')); + + return dependencyTree; +} + // Watch files async function watchFiles() { await configs.then(configurations => { @@ -30,21 +46,34 @@ async function watchFiles() { cssCompile({src: item.src, dest: item.dest}); }); - config.js.forEach(j => { + config.js.forEach(async j => { // Watch JS files, we name the function so that Gulp outputs the correct name + const files = await glob(j.src.join(), {absolute: true}); + const dependencyTree = await getDependencyTree(files, j.cwd); + // eslint-disable-next-line func-names - gulp.watch(j.watch, function js() { - return jsCompile({src: j.src, dest: j.dest, cwd: config.cwd, browserSync}); + gulp.watch(dependencyTree, function js() { + return Promise.all(files.map(async file => { + return jsCompile({ + src: file, + dest: j.dest, + cwd: config.cwd, + browserSync + }); + })); }); // Compile JS once at watch startup - jsCompile({src: j.src, dest: j.dest}); + await Promise.all(files.map(async file => jsCompile({src: file, dest: j.dest, cwd: config.cwd, browserSync}))); }); - config['js-concat'].forEach(js => { + config['js-concat'].forEach(async js => { // Watch JS files which need to be concatenated, we name the function so that Gulp outputs the correct name + const files = await glob(js.src.join(), {absolute: true}); + const dependencyTree = await getDependencyTree(files, js.cwd); + // eslint-disable-next-line func-names - gulp.watch(js.watch, function concat() { + gulp.watch(dependencyTree, function concat() { return jsConcat({src: js.src, dest: js.dest, js: js.name, browserSync}); }); diff --git a/lib/gulp/configs.js b/lib/gulp/configs.js index db5b16a..18faa5a 100644 --- a/lib/gulp/configs.js +++ b/lib/gulp/configs.js @@ -32,9 +32,24 @@ function processConfig(config, cwd) { ['css', 'js', 'img', 'js-concat', 'svg-sprite', 'copy'].forEach(key => { if (config[key]) { config[key] = config[key].map(value => { - const src = path.join(cwd, config.src_base_path, value.src); + let src = ''; + if (Array.isArray(value.src)) { + src = value.src.map(src => path.join(cwd, config.src_base_path, src)); + } else { + src = path.join(cwd, config.src_base_path, value.src); + } + const dest = path.join(cwd, config.dest_base_path, value.dest); - let watch = [src]; + + if (key === 'js' || key === 'js-concat') { + // Make sure JavaScript files are always arrays to prevent streamlined + src = Array.isArray(src) ? src : [src]; + } + + // Make sure watch entries are always arrays + // spreading of src array is to prevent copying with reference so + // src files do not get modified by watchConfigPaths + let watch = Array.isArray(src) ? [...src] : [src]; if (key === 'css') { watch = watchConfigPaths(watch, 'stylelint', cwd); diff --git a/lib/gulp/js.js b/lib/gulp/js.js index 3d7bca3..2f26534 100644 --- a/lib/gulp/js.js +++ b/lib/gulp/js.js @@ -1,13 +1,14 @@ -const babel = require('gulp-babel'); -const terser = require('gulp-terser'); -const presetEnv = require('@babel/preset-env'); -const concat = require('gulp-concat'); -const gulp = require('gulp'); -const gulpIf = require('gulp-if'); const {cosmiconfigSync} = require('cosmiconfig'); -const eslint = require('gulp-eslint'); -const plumber = require('gulp-plumber'); +const {babel} = require('@rollup/plugin-babel'); +const {eslint} = require('rollup-plugin-eslint'); +const {rollup} = require('rollup'); +const path = require('path'); +const resolve = require('@rollup/plugin-node-resolve'); +const commonjs = require('@rollup/plugin-commonjs'); +const glob = require('util').promisify(require('glob')); +const {terser} = require('rollup-plugin-terser'); const configs = require('./configs.js'); +const multi = require('@rollup/plugin-multi-entry'); async function js() { let jsTasks = []; @@ -15,8 +16,9 @@ async function js() { const configurations = await configs.then(configurations => { configurations.forEach(config => { - jsTasks = jsTasks.concat(config.js.map(js => { - return jsCompile({src: js.src, dest: js.dest, cwd: config.cwd}); + jsTasks = jsTasks.concat(config.js.map(async js => { + const src = await resolveAllAssetsFromArray(js.src); + return jsCompile({src, dest: js.dest, cwd: config.cwd}); })); }); return configurations; @@ -24,8 +26,9 @@ async function js() { await Promise.all(jsTasks).then(() => { configurations.forEach(config => { - jsConcatTasks = jsConcatTasks.concat(config['js-concat'].map(js => { - return jsConcat({src: js.src, dest: js.dest, name: js.name}); + jsConcatTasks = jsConcatTasks.concat(config['js-concat'].map(async js => { + const src = await resolveAllAssetsFromArray(js.src); + return jsConcat({src, dest: js.dest, name: js.name, cwd: config.cwd}); })); }); }); @@ -33,75 +36,83 @@ async function js() { return Promise.all(jsConcatTasks); } -function jsCompile({src, dest, cwd, browserSync = false}) { - return new Promise( - (async resolve => { // eslint-disable-line no-async-promise-executor - let stream = gulp - .src(src); - - // Prevent errors from aborting task when files are being watched - if (process.argv.includes('watch')) { - stream = stream.pipe(plumber()); - } - - // Enable linting if configured - const eslintConfig = cosmiconfigSync('eslint').search(cwd); - if (eslintConfig) { - stream = stream.pipe(eslint({ - fix: process.argv.includes('--fix') - })) - .pipe(gulpIf(file => file.eslint !== null && file.eslint.fixed, gulp.dest(file => file._base))) - .pipe(eslint.format()); - } - - stream = stream.pipe(babel({ - presets: [presetEnv] - })); +async function resolveAllAssetsFromArray(assets) { + return (await Promise.all(assets.map(async asset => glob(asset)))).flat(); +} + +async function generateBundle({src, cwd, plugins = []}) { + const rollupPlugins = plugins; + + // Bundle third party imported modules + rollupPlugins.push(resolve.default()); + + // Auto convert CommonJS modules to ES6, so they can be included in a Rollup bundle + rollupPlugins.push(commonjs()); + + // If user has an eslint configuration, load Eslint. + const hasEslintConfig = Boolean(cosmiconfigSync('eslint').search(cwd)); + if (hasEslintConfig) { + rollupPlugins.push(eslint({fix: process.argv.includes('--fix')})); + } - if (process.env.NODE_ENV === 'production') { - stream = stream.pipe(terser()); - } + // Decide whether to load a default babel preset if there is no babel configuration found + const hasBabelConfig = Boolean(cosmiconfigSync('babel').search(cwd)); + const babelConfig = {babelHelpers: 'bundled'}; + if (!hasBabelConfig) { + babelConfig.presets = ['@babel/preset-env']; + } - stream = stream.pipe(gulp.dest(dest)); + rollupPlugins.push(babel(babelConfig)); - if (browserSync !== false) { - stream.pipe(browserSync.stream({match: '**/*.js'})); - } + // Terser (minify) + rollupPlugins.push(terser()); - stream.on('end', resolve); - }) - ); + return rollup({ + input: src, + plugins: rollupPlugins + }); } -function jsConcat({src, dest, name, browserSync = false}) { - return new Promise( - (async resolve => { // eslint-disable-line no-async-promise-executor - let stream = gulp.src(src); +async function jsCompile({src, dest, cwd, browserSync = false}) { + const files = await glob(src.join(), {absolute: true}); + if (files.length === 0) { + return; + } + + const bundle = await generateBundle({src, cwd}); + + if (browserSync) { + browserSync.watch(bundle.watchFiles).on('change', browserSync.reload); + } - // Prevent errors from aborting task when files are being watched - if (process.argv.includes('watch')) { - stream = stream.pipe(plumber()); - } + return bundle.write({ + dir: dest, + format: 'amd', + sourcemap: process.env.NODE_ENV !== 'production' + }); +} - stream = stream.pipe(plumber()) - .pipe(babel({ - presets: [presetEnv] - })) - .pipe(concat(name)); +async function jsConcat({src, dest, name, browserSync = false, cwd}) { + // Abort if there are no files + const files = await glob(src.join(), {absolute: true}); + if (files.length === 0) { + return; + } - if (process.env.NODE_ENV === 'production') { - stream = stream.pipe(terser()); - } + // Allow multiple entry points to a single output + const plugins = [multi()]; - stream = stream.pipe(gulp.dest(dest)); + const bundle = await generateBundle({src, cwd, plugins}); - if (browserSync !== false) { - stream.pipe(browserSync.stream({match: '**/*.js'})); - } + if (browserSync) { + browserSync.watch(bundle.watchFiles).on('change', browserSync.reload); + } - stream.on('end', resolve); - }) - ); + return bundle.write({ + file: path.join(dest, name), + format: 'amd', + sourcemap: process.env.NODE_ENV !== 'production' + }); } -module.exports = {js, jsCompile, jsConcat}; +module.exports = {js, jsCompile, jsConcat, generateBundle}; diff --git a/package-lock.json b/package-lock.json index 948271a..577e4bc 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1025,6 +1025,82 @@ "fastq": "^1.6.0" } }, + "@rollup/plugin-babel": { + "version": "5.0.2", + "resolved": "https://registry.npmjs.org/@rollup/plugin-babel/-/plugin-babel-5.0.2.tgz", + "integrity": "sha512-GiL7jL+FGppzQ1Sn4y2ER4UYXlgXFFEt+sHm4WJEzQwI76Yf9oy2QDqIvcon6xApZWlik3L8fezRGC6Mj2vRXg==", + "dev": true, + "requires": { + "@babel/helper-module-imports": "^7.7.4", + "@rollup/pluginutils": "^3.0.8" + } + }, + "@rollup/plugin-commonjs": { + "version": "12.0.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-commonjs/-/plugin-commonjs-12.0.0.tgz", + "integrity": "sha512-8+mDQt1QUmN+4Y9D3yCG8AJNewuTSLYPJVzKKUZ+lGeQrI+bV12Tc5HCyt2WdlnG6ihIL/DPbKRJlB40DX40mw==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.0.8", + "commondir": "^1.0.1", + "estree-walker": "^1.0.1", + "glob": "^7.1.2", + "is-reference": "^1.1.2", + "magic-string": "^0.25.2", + "resolve": "^1.11.0" + }, + "dependencies": { + "estree-walker": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", + "dev": true + } + } + }, + "@rollup/plugin-multi-entry": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/@rollup/plugin-multi-entry/-/plugin-multi-entry-3.0.1.tgz", + "integrity": "sha512-Gcp9E8y68Kx+Jo8zy/ZpiiAkb0W01cSqnxOz6h9bPR7MU3gaoTEdRf7xXYplwli1SBFEswXX588ESj+50Brfxw==", + "dev": true, + "requires": { + "matched": "^1.0.2" + } + }, + "@rollup/plugin-node-resolve": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-8.0.0.tgz", + "integrity": "sha512-5poJCChrkVggXXND/sQ7yNqwjUNT4fP31gpRWCnSNnlXuUXTCMHT33xZrTGxgjm5Rl18MHj7iEzlCT8rYWwQSA==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^3.0.8", + "@types/resolve": "0.0.8", + "builtin-modules": "^3.1.0", + "deep-freeze": "^0.0.1", + "deepmerge": "^4.2.2", + "is-module": "^1.0.0", + "resolve": "^1.14.2" + } + }, + "@rollup/pluginutils": { + "version": "3.0.10", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-3.0.10.tgz", + "integrity": "sha512-d44M7t+PjmMrASHbhgpSbVgtL6EFyX7J4mYxwQ/c5eoaE6N2VgCgEcWVzNnwycIloti+/MpwFr8qfw+nRw00sw==", + "dev": true, + "requires": { + "@types/estree": "0.0.39", + "estree-walker": "^1.0.1", + "picomatch": "^2.2.2" + }, + "dependencies": { + "estree-walker": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-1.0.1.tgz", + "integrity": "sha512-1fMXF3YP4pZZVozF8j/ZLfvnR8NSIljt56UhbZ5PeeDmmGHpgpdwQt7ITlGvYaQukCvuBRMLEiKiYC+oeIg4cg==", + "dev": true + } + } + }, "@sindresorhus/is": { "version": "0.7.0", "resolved": "https://registry.npmjs.org/@sindresorhus/is/-/is-0.7.0.tgz", @@ -1067,6 +1143,12 @@ "integrity": "sha512-OCutwjDZ4aFS6PB1UZ988C4YgwlBHJd6wCeQqaLdmadZ/7e+w79+hbMUFC1QXDNCmdyoRfAFdm0RypzwR+Qpag==", "dev": true }, + "@types/estree": { + "version": "0.0.39", + "resolved": "https://registry.npmjs.org/@types/estree/-/estree-0.0.39.tgz", + "integrity": "sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw==", + "dev": true + }, "@types/events": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/@types/events/-/events-3.0.0.tgz", @@ -1118,6 +1200,15 @@ "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.2.tgz", "integrity": "sha512-ce5d3q03Ex0sy4R14722Rmt6MT07Ua+k4FwDfdcToYJcMKNtRVQvJ6JCAPdAmAnbRb6CsX6aYb9m96NGod9uTw==" }, + "@types/resolve": { + "version": "0.0.8", + "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-0.0.8.tgz", + "integrity": "sha512-auApPaJf3NPfe18hSoJkp8EbZzer2ISk7o8mCC3M9he/a04+gbMF97NkpD2S8riMGvm4BMRI59/SZQSaLTKpsQ==", + "dev": true, + "requires": { + "@types/node": "*" + } + }, "@types/unist": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.3.tgz", @@ -1728,6 +1819,12 @@ "lodash": "^4.17.14" } }, + "async-array-reduce": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/async-array-reduce/-/async-array-reduce-0.2.1.tgz", + "integrity": "sha1-yL4BCitc0A3qlsgRFgNGk9/dgtE=", + "dev": true + }, "async-done": { "version": "1.3.2", "resolved": "https://registry.npmjs.org/async-done/-/async-done-1.3.2.tgz", @@ -2934,6 +3031,12 @@ "integrity": "sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=", "dev": true }, + "builtin-modules": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-3.1.0.tgz", + "integrity": "sha512-k0KL0aWZuBt2lrxrcASWDfwOLMnodeQjodT/1SxEQAXsHANgo6ZC/VEaSEHCXt7aSTZ4/4H5LKa+tBXmW7Vtvw==", + "dev": true + }, "builtin-status-codes": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz", @@ -4231,6 +4334,12 @@ "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", "integrity": "sha512-LOHxIOaPYdHlJRtCQfDIVZtfw/ufM8+rVj649RIHzcm/vGwQRXFt6OPqIFWsm2XEMrNIEtWR64sY1LEKD2vAOA==" }, + "deep-freeze": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/deep-freeze/-/deep-freeze-0.0.1.tgz", + "integrity": "sha1-OgsABd4YZygZ39OM0x+RF5yJPoQ=", + "dev": true + }, "deep-is": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/deep-is/-/deep-is-0.1.3.tgz", @@ -4245,6 +4354,12 @@ "core-assert": "^0.2.0" } }, + "deepmerge": { + "version": "4.2.2", + "resolved": "https://registry.npmjs.org/deepmerge/-/deepmerge-4.2.2.tgz", + "integrity": "sha512-FJ3UgI4gIl+PHZm53knsuSFpE+nESMr7M4v9QcgB7S63Kj/6WqMiFQJpBBYz1Pt+66bZpP3Q7Lye0Oo9MPKEdg==", + "dev": true + }, "default-compare": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/default-compare/-/default-compare-1.0.0.tgz", @@ -5620,6 +5735,12 @@ "resolved": "https://registry.npmjs.org/estraverse/-/estraverse-4.3.0.tgz", "integrity": "sha512-39nnKffWz8xN1BU/2c79n9nB9HDzo0niYUqx6xyqUnyoAnQyyWpOTdZEeiCch8BBu515t4wp9ZmgVfVhn9EBpw==" }, + "estree-walker": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz", + "integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w==", + "dev": true + }, "esutils": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/esutils/-/esutils-2.0.3.tgz", @@ -8283,6 +8404,26 @@ "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", "integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0=" }, + "has-glob": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/has-glob/-/has-glob-1.0.0.tgz", + "integrity": "sha1-mqqe7b/7G6OZCnsAEPtnjuAIEgc=", + "dev": true, + "requires": { + "is-glob": "^3.0.0" + }, + "dependencies": { + "is-glob": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-3.1.0.tgz", + "integrity": "sha1-e6WuJCF4BKxwcHuWkiVnSGzD6Eo=", + "dev": true, + "requires": { + "is-extglob": "^2.1.0" + } + } + } + }, "has-symbol-support-x": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/has-symbol-support-x/-/has-symbol-support-x-1.4.2.tgz", @@ -9124,6 +9265,12 @@ "js-types": "^1.0.0" } }, + "is-module": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-module/-/is-module-1.0.0.tgz", + "integrity": "sha1-Mlj7afeMFNW4FdZkM2tM/7ZEFZE=", + "dev": true + }, "is-natural-number": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/is-natural-number/-/is-natural-number-4.0.1.tgz", @@ -9208,6 +9355,15 @@ "proto-props": "^2.0.0" } }, + "is-reference": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-1.1.4.tgz", + "integrity": "sha512-uJA/CDPO3Tao3GTrxYn6AwkM4nUPJiGGYu5+cB8qbC7WGFlrKZbiRo7SFKxUAEpFUfiHofWCXBUNhvYJMh+6zw==", + "dev": true, + "requires": { + "@types/estree": "0.0.39" + } + }, "is-regex": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.5.tgz", @@ -9341,6 +9497,27 @@ "is-object": "^1.0.1" } }, + "jest-worker": { + "version": "24.9.0", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-24.9.0.tgz", + "integrity": "sha512-51PE4haMSXcHohnSMdM42anbvZANYTqMrr52tVKPqqsPJMzoP6FYYDVqahX/HrAoKEKz3uUPzSvKs9A3qR4iVw==", + "dev": true, + "requires": { + "merge-stream": "^2.0.0", + "supports-color": "^6.1.0" + }, + "dependencies": { + "supports-color": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", + "integrity": "sha512-qe1jfm1Mg7Nq/NSh6XE24gPXROEVsWHxC1LIx//XNlD9iw7YZQGjZNjYN7xGaEG6iKdA8EtNFW6R0gjnVXp+wQ==", + "dev": true, + "requires": { + "has-flag": "^3.0.0" + } + } + } + }, "js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -9996,6 +10173,15 @@ "es5-ext": "~0.10.2" } }, + "magic-string": { + "version": "0.25.7", + "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.25.7.tgz", + "integrity": "sha512-4CrMT5DOHTDk4HYDlzmwu4FVCcIYI8gauveasrdCu2IKIFOJ3f0v/8MDGJCDL9oD2ppz/Av1b0Nj345H9M+XIA==", + "dev": true, + "requires": { + "sourcemap-codec": "^1.4.4" + } + }, "make-dir": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.0.2.tgz", @@ -10185,6 +10371,20 @@ } } }, + "matched": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/matched/-/matched-1.0.2.tgz", + "integrity": "sha512-7ivM1jFZVTOOS77QsR+TtYHH0ecdLclMkqbf5qiJdX2RorqfhsL65QHySPZgDE0ZjHoh+mQUNHTanNXIlzXd0Q==", + "dev": true, + "requires": { + "arr-union": "^3.1.0", + "async-array-reduce": "^0.2.1", + "glob": "^7.1.2", + "has-glob": "^1.0.0", + "is-valid-glob": "^1.0.0", + "resolve-dir": "^1.0.0" + } + }, "mathml-tag-names": { "version": "2.1.3", "resolved": "https://registry.npmjs.org/mathml-tag-names/-/mathml-tag-names-2.1.3.tgz", @@ -12808,6 +13008,56 @@ "inherits": "^2.0.1" } }, + "rollup": { + "version": "2.10.7", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-2.10.7.tgz", + "integrity": "sha512-rofUSH2i4GymWhQq6bfRaSiVbz4LEB4h/7+AhuXCaeOSwQqClD0hINjs59j8SyfQwcqe83NcVJAY2kjp0h33bQ==", + "dev": true, + "requires": { + "fsevents": "~2.1.2" + }, + "dependencies": { + "fsevents": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.1.3.tgz", + "integrity": "sha512-Auw9a4AxqWpa9GUfj370BMPzzyncfBABW8Mab7BGWBYDj4Isgq+cDKtx0i6u9jcX9pQDnswsaaOTgTmA5pEjuQ==", + "dev": true, + "optional": true + } + } + }, + "rollup-plugin-eslint": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-eslint/-/rollup-plugin-eslint-7.0.0.tgz", + "integrity": "sha512-u35kXiY11ULeNQGTlRkYx7uGJ/hS/Dx3wj8f9YVC3oMLTGU9fOqQJsAKYtBFZU3gJ8Vt3gu8ppB1vnKl+7gatQ==", + "dev": true, + "requires": { + "eslint": "^6.0.0", + "rollup-pluginutils": "^2.7.1" + } + }, + "rollup-plugin-terser": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/rollup-plugin-terser/-/rollup-plugin-terser-5.3.0.tgz", + "integrity": "sha512-XGMJihTIO3eIBsVGq7jiNYOdDMb3pVxuzY0uhOE/FM4x/u9nQgr3+McsjzqBn3QfHIpNSZmFnpoKAwHBEcsT7g==", + "dev": true, + "requires": { + "@babel/code-frame": "^7.5.5", + "jest-worker": "^24.9.0", + "rollup-pluginutils": "^2.8.2", + "serialize-javascript": "^2.1.2", + "terser": "^4.6.2" + } + }, + "rollup-pluginutils": { + "version": "2.8.2", + "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", + "integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==", + "dev": true, + "requires": { + "estree-walker": "^0.6.1" + } + }, "run-async": { "version": "2.4.0", "resolved": "https://registry.npmjs.org/run-async/-/run-async-2.4.0.tgz", @@ -12928,6 +13178,12 @@ "semver": "^5.3.0" } }, + "serialize-javascript": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-2.1.2.tgz", + "integrity": "sha512-rs9OggEUF0V4jUSecXazOYsLfu7OGK2qIn3c7IPBiffz32XniEp/TX9Xmc9LQfK2nQ2QKHvZ2oygKUGU0lG4jQ==", + "dev": true + }, "serve-index": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/serve-index/-/serve-index-1.9.1.tgz", @@ -13516,6 +13772,12 @@ "resolved": "https://registry.npmjs.org/source-map-url/-/source-map-url-0.4.0.tgz", "integrity": "sha1-PpNdfd1zYxuXZZlW1VEo6HtQhKM=" }, + "sourcemap-codec": { + "version": "1.4.8", + "resolved": "https://registry.npmjs.org/sourcemap-codec/-/sourcemap-codec-1.4.8.tgz", + "integrity": "sha512-9NykojV5Uih4lgo5So5dtw+f0JgJX30KCNI8gwhz2J9A15wD0Ml6tjHKwf6fTSa6fAdVBdZeNOs9eJ71qCk8vA==", + "dev": true + }, "sparkles": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/sparkles/-/sparkles-1.0.1.tgz", diff --git a/package.json b/package.json index b31acbd..330f993 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,15 @@ "vinyl-sourcemaps-apply": "^0.2.1" }, "devDependencies": { + "@rollup/plugin-babel": "^5.0.2", + "@rollup/plugin-commonjs": "^12.0.0", + "@rollup/plugin-multi-entry": "^3.0.1", + "@rollup/plugin-node-resolve": "^8.0.0", "npm-run-all": "^4.1.5", "rfs": "^9.0.3", + "rollup": "^2.10.7", + "rollup-plugin-eslint": "^7.0.0", + "rollup-plugin-terser": "^5.3.0", "xo": "^0.30.0" }, "scripts": { @@ -60,6 +67,7 @@ "test-config-search": "node bin/buildozer build --cwd=test/config-search", "test-stylelint": "node bin/buildozer build --cwd=test/stylelint", "test-eslint": "node bin/buildozer build --cwd=test/eslint", + "test-js": "node bin/buildozer build --cwd=test/js", "test-fails": "node test/fail-tests.js", "diff-check": "node test/check-diff.js" }, diff --git a/test/config-search/dist/js/concat/test.js b/test/config-search/dist/js/concat/test.js deleted file mode 100644 index ef81d7c..0000000 --- a/test/config-search/dist/js/concat/test.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";var q=3,test=function(t){console.log(t)};test(q); \ No newline at end of file diff --git a/test/config-search/dist/js/concat/test2.js b/test/config-search/dist/js/concat/test2.js deleted file mode 100644 index bcdb326..0000000 --- a/test/config-search/dist/js/concat/test2.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";var b=3,test2=function(t){console.log(t)};test2(b); \ No newline at end of file diff --git a/test/config-search/dist/js/test.js b/test/config-search/dist/js/test.js index ef81d7c..9bbebf6 100644 --- a/test/config-search/dist/js/test.js +++ b/test/config-search/dist/js/test.js @@ -1 +1 @@ -"use strict";var q=3,test=function(t){console.log(t)};test(q); \ No newline at end of file +define((function(){"use strict";var e;e=3,console.log(e)})); diff --git a/test/config-search/dist/js/test2.js b/test/config-search/dist/js/test2.js new file mode 100644 index 0000000..9bbebf6 --- /dev/null +++ b/test/config-search/dist/js/test2.js @@ -0,0 +1 @@ +define((function(){"use strict";var e;e=3,console.log(e)})); diff --git a/test/config-search/nested/dist/js/all.js b/test/config-search/nested/dist/js/all.js index 82717ac..d1ffb09 100644 --- a/test/config-search/nested/dist/js/all.js +++ b/test/config-search/nested/dist/js/all.js @@ -1 +1 @@ -"use strict";var q=3,test=function(t){console.log(t)};test(q);var b=3,test2=function(t){console.log(t)};test2(b); \ No newline at end of file +define((function(){"use strict";var o;o=3,console.log(o);!function(o){console.log(o)}(3)})); diff --git a/test/config-search/nested/dist/js/concat/test.js b/test/config-search/nested/dist/js/concat/test.js deleted file mode 100644 index ef81d7c..0000000 --- a/test/config-search/nested/dist/js/concat/test.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";var q=3,test=function(t){console.log(t)};test(q); \ No newline at end of file diff --git a/test/config-search/nested/dist/js/concat/test2.js b/test/config-search/nested/dist/js/concat/test2.js deleted file mode 100644 index bcdb326..0000000 --- a/test/config-search/nested/dist/js/concat/test2.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";var b=3,test2=function(t){console.log(t)};test2(b); \ No newline at end of file diff --git a/test/config-search/nested/dist/js/test.js b/test/config-search/nested/dist/js/test.js new file mode 100644 index 0000000..9bbebf6 --- /dev/null +++ b/test/config-search/nested/dist/js/test.js @@ -0,0 +1 @@ +define((function(){"use strict";var e;e=3,console.log(e)})); diff --git a/test/config-search/nested/dist/js/test2.js b/test/config-search/nested/dist/js/test2.js new file mode 100644 index 0000000..9bbebf6 --- /dev/null +++ b/test/config-search/nested/dist/js/test2.js @@ -0,0 +1 @@ +define((function(){"use strict";var e;e=3,console.log(e)})); diff --git a/test/default/dist/js/all.js b/test/default/dist/js/all.js index 82717ac..d1ffb09 100644 --- a/test/default/dist/js/all.js +++ b/test/default/dist/js/all.js @@ -1 +1 @@ -"use strict";var q=3,test=function(t){console.log(t)};test(q);var b=3,test2=function(t){console.log(t)};test2(b); \ No newline at end of file +define((function(){"use strict";var o;o=3,console.log(o);!function(o){console.log(o)}(3)})); diff --git a/test/default/dist/js/concat/test.js b/test/default/dist/js/concat/test.js deleted file mode 100644 index ef81d7c..0000000 --- a/test/default/dist/js/concat/test.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";var q=3,test=function(t){console.log(t)};test(q); \ No newline at end of file diff --git a/test/default/dist/js/concat/test2.js b/test/default/dist/js/concat/test2.js deleted file mode 100644 index bcdb326..0000000 --- a/test/default/dist/js/concat/test2.js +++ /dev/null @@ -1 +0,0 @@ -"use strict";var b=3,test2=function(t){console.log(t)};test2(b); \ No newline at end of file diff --git a/test/default/dist/js/test.js b/test/default/dist/js/test.js index ef81d7c..9bbebf6 100644 --- a/test/default/dist/js/test.js +++ b/test/default/dist/js/test.js @@ -1 +1 @@ -"use strict";var q=3,test=function(t){console.log(t)};test(q); \ No newline at end of file +define((function(){"use strict";var e;e=3,console.log(e)})); diff --git a/test/default/dist/js/test2.js b/test/default/dist/js/test2.js new file mode 100644 index 0000000..9bbebf6 --- /dev/null +++ b/test/default/dist/js/test2.js @@ -0,0 +1 @@ +define((function(){"use strict";var e;e=3,console.log(e)})); diff --git a/test/env/dist/js/all.js b/test/env/dist/js/all.js index 4d53693..af3f3d9 100644 --- a/test/env/dist/js/all.js +++ b/test/env/dist/js/all.js @@ -1,18 +1,2 @@ -"use strict"; - -var q = 3; - -var test = function test(value) { - console.log(value); -}; - -test(q); -"use strict"; - -var b = 3; - -var test2 = function test2(value) { - console.log(value); -}; - -test2(b); \ No newline at end of file +define((function(){"use strict";var o;o=3,console.log(o);!function(o){console.log(o)}(3)})); +//# sourceMappingURL=all.js.map diff --git a/test/env/dist/js/all.js.map b/test/env/dist/js/all.js.map new file mode 100644 index 0000000..d3e0166 --- /dev/null +++ b/test/env/dist/js/all.js.map @@ -0,0 +1 @@ +{"version":3,"file":"all.js","sources":["../../js/concat/test.js","../../js/concat/test2.js"],"sourcesContent":["const q = 3;\n\nconst test = value => {\n console.log(value);\n};\n\ntest(q);\n","const b = 3;\n\nconst test2 = value => {\n console.log(value);\n};\n\ntest2(b);\n"],"names":["value","console","log","test2"],"mappings":"gCAAA,IAEaA,EAAAA,EAFH,EAGRC,QAAQC,IAAIF,ICDA,SAAAA,GACZC,QAAQC,IAAIF,GAGdG,CANU"} \ No newline at end of file diff --git a/test/env/dist/js/concat/test.js b/test/env/dist/js/concat/test.js deleted file mode 100644 index 076d23f..0000000 --- a/test/env/dist/js/concat/test.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; - -var q = 3; - -var test = function test(value) { - console.log(value); -}; - -test(q); \ No newline at end of file diff --git a/test/env/dist/js/concat/test2.js b/test/env/dist/js/concat/test2.js deleted file mode 100644 index 3e4efb3..0000000 --- a/test/env/dist/js/concat/test2.js +++ /dev/null @@ -1,9 +0,0 @@ -"use strict"; - -var b = 3; - -var test2 = function test2(value) { - console.log(value); -}; - -test2(b); \ No newline at end of file diff --git a/test/env/dist/js/test.js b/test/env/dist/js/test.js index 076d23f..d5eb00c 100644 --- a/test/env/dist/js/test.js +++ b/test/env/dist/js/test.js @@ -1,9 +1,2 @@ -"use strict"; - -var q = 3; - -var test = function test(value) { - console.log(value); -}; - -test(q); \ No newline at end of file +define((function(){"use strict";var e;e=3,console.log(e)})); +//# sourceMappingURL=test.js.map diff --git a/test/env/dist/js/test.js.map b/test/env/dist/js/test.js.map new file mode 100644 index 0000000..d18f9d4 --- /dev/null +++ b/test/env/dist/js/test.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test.js","sources":["../../js/concat/test.js"],"sourcesContent":["const q = 3;\n\nconst test = value => {\n console.log(value);\n};\n\ntest(q);\n"],"names":["value","console","log"],"mappings":"gCAAA,IAEaA,EAAAA,EAFH,EAGRC,QAAQC,IAAIF"} \ No newline at end of file diff --git a/test/env/dist/js/test2.js b/test/env/dist/js/test2.js new file mode 100644 index 0000000..f3257b7 --- /dev/null +++ b/test/env/dist/js/test2.js @@ -0,0 +1,2 @@ +define((function(){"use strict";var e;e=3,console.log(e)})); +//# sourceMappingURL=test2.js.map diff --git a/test/env/dist/js/test2.js.map b/test/env/dist/js/test2.js.map new file mode 100644 index 0000000..0628679 --- /dev/null +++ b/test/env/dist/js/test2.js.map @@ -0,0 +1 @@ +{"version":3,"file":"test2.js","sources":["../../js/concat/test2.js"],"sourcesContent":["const b = 3;\n\nconst test2 = value => {\n console.log(value);\n};\n\ntest2(b);\n"],"names":["value","console","log"],"mappings":"gCAAA,IAEcA,EAAAA,EAFJ,EAGRC,QAAQC,IAAIF"} \ No newline at end of file diff --git a/test/eslint/dist/js/main.js b/test/eslint/dist/js/main.js index c95433b..bd2e53b 100644 --- a/test/eslint/dist/js/main.js +++ b/test/eslint/dist/js/main.js @@ -1 +1 @@ -"use strict";var t=3; \ No newline at end of file +define((function(){})); diff --git a/test/js/.buildozerrc b/test/js/.buildozerrc new file mode 100644 index 0000000..48f7476 --- /dev/null +++ b/test/js/.buildozerrc @@ -0,0 +1,21 @@ +src_base_path: ./ +dest_base_path: ./ +img: [] +js: + - src: + - js/index.js + - js/b.js + dest: dist/js + - src: js/c.js + dest: dist/js/c +js-concat: + - src: js/concat/*.js + name: all.js + dest: dist/js/concat +svg-sprite: [] +browsersync: + server: null # Static sites + proxy: null # Dynamic sites + reload: null # Glob to watch for reload +config_search: + enabled: false diff --git a/test/js/dist/js/b.js b/test/js/dist/js/b.js new file mode 100644 index 0000000..0c5968c --- /dev/null +++ b/test/js/dist/js/b.js @@ -0,0 +1 @@ +define((function(){"use strict";function n(){console.log("b")}return n(),n})); diff --git a/test/js/dist/js/c/c.js b/test/js/dist/js/c/c.js new file mode 100644 index 0000000..a2a4b64 --- /dev/null +++ b/test/js/dist/js/c/c.js @@ -0,0 +1 @@ +define((function(){"use strict";function n(){console.log("c")}return n(),n})); diff --git a/test/js/dist/js/concat/all.js b/test/js/dist/js/concat/all.js new file mode 100644 index 0000000..56d11f3 --- /dev/null +++ b/test/js/dist/js/concat/all.js @@ -0,0 +1 @@ +define(["exports"],(function(e){"use strict";e.a=function(){console.log("a")},e.b=function(){console.log("b")},Object.defineProperty(e,"__esModule",{value:!0})})); diff --git a/test/js/dist/js/index.js b/test/js/dist/js/index.js new file mode 100644 index 0000000..9f65724 --- /dev/null +++ b/test/js/dist/js/index.js @@ -0,0 +1 @@ +define((function(){"use strict";console.log((function(){console.log("a")}))})); diff --git a/test/js/js/a.js b/test/js/js/a.js new file mode 100644 index 0000000..b0e029b --- /dev/null +++ b/test/js/js/a.js @@ -0,0 +1,3 @@ +export default function a () { + console.log('a') +} diff --git a/test/js/js/b.js b/test/js/js/b.js new file mode 100644 index 0000000..78ed1a1 --- /dev/null +++ b/test/js/js/b.js @@ -0,0 +1,4 @@ +export default function b() { + console.log('b') +} +b(); diff --git a/test/js/js/c.js b/test/js/js/c.js new file mode 100644 index 0000000..3592525 --- /dev/null +++ b/test/js/js/c.js @@ -0,0 +1,4 @@ +export default function c() { + console.log('c') +} +c(); diff --git a/test/js/js/concat/a.js b/test/js/js/concat/a.js new file mode 100644 index 0000000..92a9625 --- /dev/null +++ b/test/js/js/concat/a.js @@ -0,0 +1,3 @@ +export function a() { + console.log('a') +} diff --git a/test/js/js/concat/b.js b/test/js/js/concat/b.js new file mode 100644 index 0000000..e040f51 --- /dev/null +++ b/test/js/js/concat/b.js @@ -0,0 +1,3 @@ +export function b() { + console.log('b') +} diff --git a/test/js/js/concat/c.js b/test/js/js/concat/c.js new file mode 100644 index 0000000..52e07b8 --- /dev/null +++ b/test/js/js/concat/c.js @@ -0,0 +1,3 @@ +function c() { + console.log('c') +} diff --git a/test/js/js/index.js b/test/js/js/index.js new file mode 100644 index 0000000..6767d98 --- /dev/null +++ b/test/js/js/index.js @@ -0,0 +1,2 @@ +import a from "./a"; +console.log(a);