Skip to content

Commit

Permalink
chore(build): del /dist + refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
jfactory-es committed Nov 2, 2024
1 parent a6b0d83 commit 9210bf9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 55 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
const terserPlugin = require('@rollup/plugin-terser');
const del = require('rollup-plugin-delete');
const copy = require('rollup-plugin-copy');
const terser = require('@rollup/plugin-terser');

const {
PRODUCTION,
DEVELOPMENT,
commonOptions,
commonOutputUMD,
commonOutputCJS,
commonOutputES,
bannerProd
} = require('./buildConfig.js');
commonOutputES
} = require('./rollup.config.js');

module.exports = [

// ----------------------------------------------------------------------------------
// index.cjs
// Production
// ----------------------------------------------------------------------------------
{
input: 'src/index-loader.cjs',
input: 'src/index.mjs',
...commonOptions(PRODUCTION),
plugins: [
del({
targets: [
'dist/*'
// 'dist/cjs',
// 'dist/cjs-devel',
// 'dist/es',
// 'dist/es-devel',
// 'dist/umd',
// 'dist/cjs-devel',
// 'dist/index.js',
// 'dist/jFactory.d.mts'
],
runOnce: true
}),
copy({
targets: [
{
Expand All @@ -29,38 +44,20 @@ module.exports = [
verbose: true,
copyOnce: true
})
],
output: [
{
format: 'cjs',
entryFileNames: 'index.js',
banner: bannerProd,
strict: false,
dir: 'dist'
}
]
},

// ----------------------------------------------------------------------------------
// Production
// ----------------------------------------------------------------------------------
{
input: 'src/index.mjs',
...commonOptions(PRODUCTION),
].concat(commonOptions(PRODUCTION).plugins),
output: [
{
...commonOutputUMD(PRODUCTION),
sourcemap: true,
plugins: [
terserPlugin(/*terserOptions*/)
terser(/*terserOptions*/)
]
},
{
...commonOutputES(PRODUCTION)
},
{
...commonOutputCJS(PRODUCTION),
sourcemap: true
...commonOutputCJS(PRODUCTION)
}
]
},
Expand All @@ -80,8 +77,7 @@ module.exports = [
...commonOutputES(DEVELOPMENT)
},
{
...commonOutputCJS(DEVELOPMENT),
sourcemap: true
...commonOutputCJS(DEVELOPMENT)
}
]
}
Expand Down
27 changes: 16 additions & 11 deletions scripts/build/buildConfig.js → scripts/build/rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const project = {
const commonOptions = function(devel = false) {
return {
treeshake: {
moduleSideEffects: []
preset: 'recommended'
// moduleSideEffects: []
},
external: [
'jquery',
Expand Down Expand Up @@ -50,7 +51,8 @@ const commonOutput = {
constBindings: true,
objectShorthand: true
},
exports: 'named',
// interop: 'auto',
// exports: 'named',
globals: function(name) {
if (name === 'jquery') {
return '$'
Expand All @@ -77,12 +79,12 @@ const commonOutputCJS = function(devel = false) {
return {
format: 'cjs',
entryFileNames: '[name].cjs',
plugins: [
// terserPlugin(terserOptions)
],
// !! modules must be preserved to allow module Tree Shaking in application bundler
preserveModules: true,
preserveModulesRoot: 'src',
dir: devel ? 'dist/cjs-devel' : 'dist/cjs',
banner: function(chunk) {
return chunk.fileName === 'index.mjs' ? devel ? bannerDevel : bannerProd : '';
return chunk.fileName === 'index.cjs' ? devel ? bannerDevel : bannerProd : '';
},
...commonOutput
}
Expand All @@ -95,12 +97,15 @@ const commonOutputES = function(devel = false) {
// !! modules must be preserved to allow module Tree Shaking in application bundler
preserveModules: true,
preserveModulesRoot: 'src',
plugins: [
// terserPlugin(terserOptions)
],
dir: devel ? 'dist/es-devel' : 'dist/es',
banner: function(chunk) {
return chunk.fileName === 'index.mjs' ? devel ? bannerDevel : bannerProd : '';
if (chunk.fileName === 'index.mjs') {
return devel ? bannerDevel : bannerProd;
} else {
if (chunk.fileName === 'jFactory-env.mjs') {
return 'globalThis.JFACTORY_ENV_ESM = 1;';
}
}
},
...commonOutput
}
Expand All @@ -123,7 +128,7 @@ module.exports = {
commonOutputCJS,
commonOutputES,
bannerProd
}
};

function getComputedValues(devel = false) {
return {
Expand Down
15 changes: 0 additions & 15 deletions scripts/build/rollup.test_export.config.cjs

This file was deleted.

0 comments on commit 9210bf9

Please sign in to comment.