Skip to content

Commit

Permalink
feat: Add build script for publishing
Browse files Browse the repository at this point in the history
  • Loading branch information
Trygve Lie committed Sep 16, 2024
1 parent 11cac13 commit 939222c
Show file tree
Hide file tree
Showing 6 changed files with 231 additions and 146 deletions.
49 changes: 49 additions & 0 deletions dev-utils/dev-build.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import rollupPluginCommonjs from "@rollup/plugin-commonjs";
import rollupPluginResolve from "@rollup/plugin-node-resolve";
import rollupPluginReplace from "@rollup/plugin-replace";
import rollupPluginTerser from "@rollup/plugin-terser";
import { rollup } from "rollup";

const inputOptions = {
input: ["./src/alpaca-map.js"],
plugins: [
rollupPluginResolve({
preferBuiltins: true
}),
rollupPluginCommonjs({
include: /node_modules/
}),
rollupPluginReplace({
"process.env.NODE_ENV": JSON.stringify("production"),
preventAssignment: true,
}),
/*
rollupPluginTerser({
format: {
comments: false
}
}),
*/
],
};

const outputOptionsList = [
{
preserveModules: true,
dir: './public/build',
// file: "./public/build/alpaca-map.js",
format: "es",
// sourcemap: true,
interop: 'esModule',
},
];

let bundle = await rollup(inputOptions);

for (const outputOptions of outputOptionsList) {
await bundle.write(outputOptions);
}

if (bundle) {
await bundle.close();
}
2 changes: 1 addition & 1 deletion dev-server.js → dev-utils/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const fastify = Fastify({
});

fastify.register(fastifyStatic, {
root: path.join(import.meta.dirname, "./public"),
root: path.join(import.meta.dirname, "../public"),
prefix: "/",
});

Expand Down
19 changes: 11 additions & 8 deletions build.js → dev-utils/pub-build.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
import rollupPluginCommonjs from "@rollup/plugin-commonjs";
import rollupPluginResolve from "@rollup/plugin-node-resolve";
import rollupPluginReplace from "@rollup/plugin-replace";
import rollupPluginTerser from "@rollup/plugin-terser";
import { rollup } from "rollup";

const inputOptions = {
input: ["./src/alpaca-map.js"],
external: ['lit'],
plugins: [
rollupPluginResolve({ preferBuiltins: true }),
rollupPluginCommonjs({ include: /node_modules/ }),
rollupPluginResolve({
preferBuiltins: true
}),
rollupPluginCommonjs({
include: /node_modules/
}),
rollupPluginReplace({
"process.env.NODE_ENV": JSON.stringify("production"),
preventAssignment: true,
}),
rollupPluginTerser({ format: { comments: false } }),
],
};

const outputOptionsList = [
{
// preserveModules: true,
// dir: './public/build',
file: "./public/build/alpaca-map.js",
preserveModules: true,
entryFileNames: '[name].mjs',
dir: './build/node',
format: "es",
sourcemap: true,
interop: 'esModule',
},
];

Expand Down
22 changes: 13 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,41 @@
"name": "@purplebugs/alpaca-map",
"type": "module",
"version": "0.0.4",
"main": "src/alpaca-map.js",
"exports": {
".": "./build/node/src/alpaca-map.mjs"
},
"files": [
"package.json",
"README.md",
"build",
"src"
],
"scripts": {
"build:watch": "node --watch-path=./src build.js",
"build": "node build.js",
"build:publish:node": "node ./dev-utils/pub-build.js",
"build:watch": "node --watch-path=./src ./dev-utils/dev-build.js",
"build": "node ./dev-utils/dev-build.js",
"prettier": "prettier . --write",
"start": "node dev-server.js",
"start": "node ./dev-utils/dev-server.js",
"test": "node --test",
"test-ui": "playwright test"
},
"author": "",
"license": "MIT",
"description": "",
"devDependencies": {
"@googlemaps/markerclusterer": "^2.5.3",
"@fastify/static": "7.0.4",
"@playwright/test": "^1.45.1",
"@rollup/plugin-commonjs": "26.0.1",
"@rollup/plugin-node-resolve": "15.2.3",
"@rollup/plugin-replace": "5.0.7",
"@rollup/plugin-terser": "0.4.4",
"@types/node": "^20.14.10",
"fastify": "4.28.0",
"prettier": "3.3.2",
"rollup": "4.18.0"
"@types/node": "20.14.10",
"fastify": "4.28.1",
"prettier": "3.3.3",
"rollup": "4.21.3"
},
"dependencies": {
"@googlemaps/markerclusterer": "^2.5.3",
"lit": "^3.1.4"
}
}
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ <h1>Alpaca Map web component - index.html page header</h1>
</p>
</div>

<script type="module" src="/build/alpaca-map.js"></script>
<script type="module" src="/build/src/alpaca-map.js"></script>
</body>
</html>
Loading

0 comments on commit 939222c

Please sign in to comment.