From 96d15bb480f21374bbd8f1176ba04b07a9f8ca8c Mon Sep 17 00:00:00 2001 From: ssube Date: Sat, 29 Jun 2019 19:20:50 -0500 Subject: [PATCH] build: split vendor chunk --- Dockerfile | 5 +++-- Makefile | 4 ++-- README.md | 2 +- config/rollup.js | 50 ++++++++++++++++++++++++------------------------ package.json | 4 ++-- 5 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Dockerfile b/Dockerfile index adb1462..bea446c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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" ] \ No newline at end of file +ENTRYPOINT [ "node", "/salty-dog/out/main.js" ] \ No newline at end of file diff --git a/Makefile b/Makefile index 4e0618f..00f70e3 100755 --- a/Makefile +++ b/Makefile @@ -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 \ @@ -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 - \ diff --git a/README.md b/README.md index b287b23..5d371b9 100644 --- a/README.md +++ b/README.md @@ -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: diff --git a/config/rollup.js b/config/rollup.js index d8e918a..05cc285 100644 --- a/config/rollup.js +++ b/config/rollup.js @@ -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: ['{{ ', ' }}'], @@ -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, - ] - }, -]; +]; \ No newline at end of file diff --git a/package.json b/package.json index d71cd15..4b3bf64 100644 --- a/package.json +++ b/package.json @@ -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",