diff --git a/.circleci/config.yml b/.circleci/config.yml index 0231ff38..b3ad2141 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -19,7 +19,7 @@ jobs: - node_modules - run: name: build - command: yarn run build + command: yarn run release - run: name: test command: yarn run test:coverage diff --git a/.travis.yml b/.travis.yml index 91111b97..95e30524 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,6 @@ language: node_js node_js: - node script: - - npm run build + - npm run release - npm run test:coverage - npm run codecov diff --git a/package.json b/package.json index 15c0599b..d64a801c 100644 --- a/package.json +++ b/package.json @@ -43,8 +43,10 @@ "src/templates/**/*.ts" ], "scripts": { - "clean": "rimraf ./dist ./test/result ./coverage ./samples/examples", - "build": "rollup --config", + "clean": "rimraf ./dist ./test/result ./coverage ./samples/examples ./node_modules/.cache", + "build": "rollup --config --environment NODE_ENV:development", + "build:watch": "rollup --config --environment NODE_ENV:development --watch", + "release": "rollup --config --environment NODE_ENV:production", "run": "node ./test/index.js", "test": "jest", "test:update": "jest --updateSnapshot", @@ -54,6 +56,7 @@ "eslint:fix": "eslint \"./src/**/*.ts\" \"./bin/index.js\" --fix", "prettier": "prettier \"./src/**/*.ts\" \"./bin/index.js\" --check", "prettier:fix": "prettier \"./src/**/*.ts\" \"./bin/index.js\" --write", + "prepublish": "yarn run clean && yarn run release", "codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b" }, "dependencies": { diff --git a/rollup.config.js b/rollup.config.js index d6050c46..64c08d9f 100644 --- a/rollup.config.js +++ b/rollup.config.js @@ -1,8 +1,8 @@ 'use strict'; const commonjs = require('@rollup/plugin-commonjs'); -const { nodeResolve } = require('@rollup/plugin-node-resolve'); -const { terser } = require('rollup-plugin-terser'); +const {nodeResolve} = require('@rollup/plugin-node-resolve'); +const {terser} = require('rollup-plugin-terser'); const typescript = require('rollup-plugin-typescript2'); const handlebars = require('handlebars'); const path = require('path'); @@ -11,37 +11,49 @@ const fs = require('fs'); const pkg = require('./package.json'); const external = Object.keys(pkg.dependencies); + /** * Custom plugin to parse handlebar imports and precompile * the template on the fly. This reduces runtime by about * half on large projects. */ -function handlebarsPlugin() { - return { - resolveId(file, importer) { - if (file.endsWith('.hbs')) { - return path.resolve(path.dirname(importer), file); - } - return null; - }, - load(file) { - if (file.endsWith('.hbs')) { - const template = fs.readFileSync(file, 'utf8').toString().trim(); - const templateSpec = handlebars.precompile(template, { - strict: true, - noEscape: true, - preventIndent: true, - knownHelpersOnly: true, - knownHelpers: { - equals: true, - notEquals: true, - }, - }); - return `export default ${templateSpec};`; - } - return null; - }, - }; +const handlebarsPlugin = () => ({ + resolveId: (file, importer) => { + if (path.extname(file) === '.hbs') { + return path.resolve(path.dirname(importer), file); + } + return null; + }, + load: (file) => { + if (path.extname(file) === '.hbs') { + const template = fs.readFileSync(file, 'utf8').toString().trim(); + const templateSpec = handlebars.precompile(template, { + strict: true, + noEscape: true, + preventIndent: true, + knownHelpersOnly: true, + knownHelpers: { + equals: true, + notEquals: true, + }, + }); + return `export default ${templateSpec};`; + } + return null; + } +}); + +const getPlugins = () => { + const plugins = [ + handlebarsPlugin(), + typescript(), + nodeResolve(), + commonjs(), + ] + if (process.env.NODE_ENV === 'development') { + return plugins; + } + return [...plugins, terser()]; } export default { @@ -59,17 +71,5 @@ export default { 'handlebars/runtime', ...external, ], - plugins: [ - handlebarsPlugin(), - typescript({ - clean: true, - }), - nodeResolve(), - commonjs(), - terser({ - output: { - comments: false, - }, - }), - ], + plugins: getPlugins(), }; diff --git a/src/typings/hbs.d.ts b/src/typings/hbs.d.ts index 5e6b066b..f8ab7b40 100644 --- a/src/typings/hbs.d.ts +++ b/src/typings/hbs.d.ts @@ -10,7 +10,7 @@ declare module '*.hbs' { export default { compiler: [8, '>= 4.3.0'], useData: true, - main: function (container, depth0, helpers, partials, data) { + main: function () { return ''; }, }; diff --git a/tsconfig.json b/tsconfig.json index 969ecbe0..8c0d6f78 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -21,8 +21,7 @@ "strictFunctionTypes": true, "removeComments": true, "forceConsistentCasingInFileNames": true, - "allowSyntheticDefaultImports": true, - "isolatedModules": true + "allowSyntheticDefaultImports": true }, "files": [