Skip to content

Commit

Permalink
build: split vendor chunk
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jun 30, 2019
1 parent 901696f commit 96d15bb
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 32 deletions.
5 changes: 3 additions & 2 deletions Dockerfile
Expand Up @@ -5,8 +5,9 @@ COPY docs/config-docker.yml /root/.salty-dog.yml

# copy package first, to invalidate other layers when version changes
COPY package.json /salty-dog/package.json
COPY out/vendor.js /salty-dog/out/vendor.js
COPY out/main.js /salty-dog/out/main.js

COPY rules /salty-dog/rules
COPY out/bundle.js /salty-dog/out/bundle.js

ENTRYPOINT [ "node", "/salty-dog/out/bundle.js" ]
ENTRYPOINT [ "node", "/salty-dog/out/main.js" ]
4 changes: 2 additions & 2 deletions Makefile
Expand Up @@ -121,7 +121,7 @@ run-rules: ## validate the rules directory
find $(ROOT_PATH)/rules -maxdepth 1 -name '*.yml' | while read file; \
do \
echo "Validating $${file}..."; \
node out/bundle.js \
node out/main.js \
--config-path $(ROOT_PATH)/docs \
--config-name config-stderr.yml \
--rules $(ROOT_PATH)/rules/salty-dog.yml \
Expand All @@ -130,7 +130,7 @@ run-rules: ## validate the rules directory
done

run-stream: ## validate stdin and write it to stdout, errors to stderr
@node out/bundle.js \
@node out/main.js \
--config-path $(ROOT_PATH)/docs \
--config-name config-stderr.yml \
--dest - \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -141,7 +141,7 @@ This project is written in Typescript and requires `node` and `yarn` to build.
> make
```

After building, run with: `node out/bundle.js`
After building, run with: `node out/main.js`

`make` targets are provided for some common arguments:

Expand Down
50 changes: 25 additions & 25 deletions config/rollup.js
Expand Up @@ -8,24 +8,40 @@ import resolve from 'rollup-plugin-node-resolve';
import typescript from 'rollup-plugin-typescript2';

const metadata = require('../package.json');

// `npm run build` -> `production` is true
// `npm run dev` -> `production` is false
const production = !process.env.ROLLUP_WATCH;
const shebang = '#! /usr/bin/env node';
const license = fs.readFileSync('LICENSE.md', 'utf-8').split('\n').map(ln => ` * ${ln}`);

const bundle = {
input: 'src/index.ts',
input: [
'src/index.ts',
'test/harness.ts',
'test/**/Test*.ts',
],
manualChunks(id) {
if (id.includes('/node_modules/')) {
return 'vendor';
}

if (id.includes('/test/')) {
return 'test'
}

if (id.includes('/src/')) {
return 'main';
}
},
output: {
file: 'out/bundle.js',
dir: 'out/',
chunkFileNames: '[name].js',
entryFileNames: 'index.js',
format: 'cjs',
sourcemap: true,
banner: () => {
const shebang = '#! /usr/bin/env node';
const license = fs.readFileSync('LICENSE.md', 'utf-8').split('\n').map(ln => ` * ${ln}`);
return [shebang, '/**', ...license, ' **/'].join('\n');
},
},
plugins: [
multiEntry(),
json(),
replace({
delimiters: ['{{ ', ' }}'],
Expand Down Expand Up @@ -83,20 +99,4 @@ const bundle = {

export default [
bundle,
{
...bundle,
input: [
'test/harness.ts',
'test/**/Test*.ts',
],
output: {
file: 'out/test.js',
format: 'cjs',
sourcemap: true,
},
plugins: [
multiEntry(),
...bundle.plugins,
]
},
];
];
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -2,9 +2,9 @@
"name": "salty-dog",
"version": "0.4.1",
"description": "YAML linter, transformer, and validator",
"main": "out/bundle.js",
"main": "out/main.js",
"bin": {
"salty-dog": "out/bundle.js"
"salty-dog": "out/main.js"
},
"directories": {
"doc": "docs",
Expand Down

0 comments on commit 96d15bb

Please sign in to comment.