Merge pull request #762 from 30-seconds/packager

[FIX] Packager script: Babel 7, named exports
This commit is contained in:
Angelos Chalaris
2018-10-08 20:08:41 +03:00
committed by GitHub
9 changed files with 7505 additions and 5716 deletions

View File

@ -31,7 +31,6 @@ try {
}
// Write `imports.js`
fs.writeFileSync(IMPORTS, '');
let exportStr = 'export default {';
// Read all snippets and store them appropriately
for (const snippet of snippets) {
const snippetData = fs.readFileSync(path.join(SNIPPETS_PATH, snippet), 'utf8');
@ -42,12 +41,11 @@ try {
.split('\n')[0]
.includes('node');
// Read `imports.js` and write the data
const importData = fs.readFileSync(IMPORTS);
const importData = fs.readFileSync(IMPORTS, 'utf8');
fs.writeFileSync(
IMPORTS,
importData + `\nimport { ${snippetName} } from './temp/${snippetName}.js'`
importData + `\nexport { ${snippetName} } from './temp/${snippetName}.js'`
);
exportStr += `${snippetName},`;
// Find the code in each snippet
const code = snippetData.match(codeRE)[1].replace('\n', '');
// Store the data to be written
@ -61,8 +59,6 @@ try {
fs.writeFileSync(`${TEMP_PATH}/${snippetName}.js`, toWrite);
}
// Write to the proper files and start the `rollup` script
exportStr += '}';
fs.appendFileSync(IMPORTS, `\n${exportStr}`);
cp.execSync('node ./scripts/rollup.js');
// Clean up temporary data
fs.removeSync(TEMP_PATH);

View File

@ -13,30 +13,31 @@ const DIST = './dist';
// Create `dist` folder if not existing
if (!fs.existsSync(DIST)) fs.mkdirSync(DIST);
// Setup babel and minification
const es5 = babel({ presets: [['env', { modules: false }]] });
const es5 = babel({
presets: ['@babel/preset-env']
});
const min = minify({ comments: false });
// Create the bundles
(async () => {
const bundle = await rollup({ input: INPUT_FILE });
const bundleES5 = await rollup({ input: INPUT_FILE, plugins: [es5] });
const bundleMin = await rollup({ input: INPUT_FILE, plugins: [min] });
const bundleES5Min = await rollup({
input: INPUT_FILE,
plugins: [es5, min]
});
// UMD ES2017
// UMD ES2018
await bundle.write({
file: `${DIST}/${MODULE_NAME}.js`,
name: MODULE_NAME,
format: 'umd'
});
// UMD ES2017 minified
await bundleMin.write({
file: `${DIST}/${MODULE_NAME}.min.js`,
// ESM ES2018
await bundle.write({
file: `${DIST}/${MODULE_NAME}.esm.js`,
name: MODULE_NAME,
format: 'umd'
format: 'es'
});
// UMD ES5
@ -52,11 +53,4 @@ const min = minify({ comments: false });
name: MODULE_NAME,
format: 'umd'
});
// ESM ES2017
await bundle.write({
file: `${DIST}/${MODULE_NAME}.esm.js`,
name: MODULE_NAME,
format: 'es'
});
})();