Skip to content
This repository has been archived by the owner on May 1, 2022. It is now read-only.

Commit

Permalink
Auto delete dist directory on build (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobdeichert committed Feb 11, 2020
1 parent 3f6a680 commit 364397c
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,10 @@ Add a few simple scripts as seen [here][basic_example_package]:
"scripts": {
// This starts svelvet in watch mode and runs snowpack once to generate dist/web_modules.
// It also starts a live reloading dev server on localhost:8080
"dev": "npm run clean && svelvet",
"dev": "svelvet",

// This builds the dist directory optimized for production with snowpack
"build": "NODE_ENV=production npm run dev",

// Remove generated files for a clean build
"clean": "rm -rf dist/*"
"build": "NODE_ENV=production svelvet"
},
~~~

Expand Down
5 changes: 2 additions & 3 deletions examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"name": "svelvet-example-basic",
"private": true,
"scripts": {
"dev": "npm run clean && svelvet",
"build": "NODE_ENV=production npm run dev",
"clean": "rm -rf dist"
"dev": "svelvet",
"build": "NODE_ENV=production svelvet"
},
"dependencies": {
"svelte": "^3.7.1"
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"chokidar": "^3.3.1",
"glob": "^7.1.6",
"p-limit": "^2.2.2",
"rimraf": "^3.0.2",
"servor": "^3.1.0",
"snowpack": "1.2.0",
"terser": "^4.6.3"
Expand All @@ -29,6 +30,7 @@
"@types/babel__core": "^7.1.3",
"@types/glob": "^7.1.1",
"@types/node": "^13.1.8",
"@types/rimraf": "^2.0.3",
"@typescript-eslint/eslint-plugin": "^2.16.0",
"@typescript-eslint/parser": "^2.16.0",
"prettier": "^1.16.1",
Expand Down
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import * as glob from 'glob';
import * as terser from 'terser';
import pLimit from 'p-limit';
import * as servor from 'servor';
import * as rimraf from 'rimraf';

const exec = util.promisify(execSync);

Expand All @@ -31,6 +32,11 @@ const BABEL_CONFIG = existsSync('./babel.config.js')
],
};

async function cleanDist(): Promise<void> {
if (process.argv.includes('--no-clean')) return;
await new Promise(resolve => rimraf('dist', resolve));
}

async function compile(
srcPath: string
): Promise<{
Expand Down Expand Up @@ -274,6 +280,7 @@ async function startDevServer(): Promise<void> {
}

async function main(): Promise<void> {
await cleanDist();
await initialBuild();
if (IS_PRODUCTION_MODE) return;
startWatchMode();
Expand Down
5 changes: 2 additions & 3 deletions tests/snapshot-babel-override/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"name": "svelvet-test",
"private": true,
"scripts": {
"dev": "npm run clean && svelvet",
"build": "NODE_ENV=production npm run dev",
"clean": "rm -rf dist"
"dev": "svelvet",
"build": "NODE_ENV=production svelvet"
},
"dependencies": {
"svelte": "3.18.1"
Expand Down
5 changes: 2 additions & 3 deletions tests/snapshot/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"name": "svelvet-test",
"private": true,
"scripts": {
"dev": "npm run clean && svelvet",
"build": "NODE_ENV=production npm run dev",
"clean": "rm -rf dist"
"dev": "svelvet",
"build": "NODE_ENV=production svelvet"
},
"dependencies": {
"svelte": "3.18.1"
Expand Down

0 comments on commit 364397c

Please sign in to comment.