Skip to content

Commit fe136fd

Browse files
committed
- Fixed eslint warning
- Fixed dev and production builds for faster testing
1 parent b7c09f9 commit fe136fd

File tree

6 files changed

+50
-48
lines changed

6 files changed

+50
-48
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- node_modules
2020
- run:
2121
name: build
22-
command: yarn run build
22+
command: yarn run release
2323
- run:
2424
name: test
2525
command: yarn run test:coverage

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ language: node_js
22
node_js:
33
- node
44
script:
5-
- npm run build
5+
- npm run release
66
- npm run test:coverage
77
- npm run codecov

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@
4343
"src/templates/**/*.ts"
4444
],
4545
"scripts": {
46-
"clean": "rimraf ./dist ./test/result ./coverage ./samples/examples",
47-
"build": "rollup --config",
46+
"clean": "rimraf ./dist ./test/result ./coverage ./samples/examples ./node_modules/.cache",
47+
"build": "rollup --config --environment NODE_ENV:development",
48+
"build:watch": "rollup --config --environment NODE_ENV:development --watch",
49+
"release": "rollup --config --environment NODE_ENV:production",
4850
"run": "node ./test/index.js",
4951
"test": "jest",
5052
"test:update": "jest --updateSnapshot",
@@ -54,6 +56,7 @@
5456
"eslint:fix": "eslint \"./src/**/*.ts\" \"./bin/index.js\" --fix",
5557
"prettier": "prettier \"./src/**/*.ts\" \"./bin/index.js\" --check",
5658
"prettier:fix": "prettier \"./src/**/*.ts\" \"./bin/index.js\" --write",
59+
"prepublish": "yarn run clean && yarn run release",
5760
"codecov": "codecov --token=66c30c23-8954-4892-bef9-fbaed0a2e42b"
5861
},
5962
"dependencies": {

rollup.config.js

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict';
22

33
const commonjs = require('@rollup/plugin-commonjs');
4-
const { nodeResolve } = require('@rollup/plugin-node-resolve');
5-
const { terser } = require('rollup-plugin-terser');
4+
const {nodeResolve} = require('@rollup/plugin-node-resolve');
5+
const {terser} = require('rollup-plugin-terser');
66
const typescript = require('rollup-plugin-typescript2');
77
const handlebars = require('handlebars');
88
const path = require('path');
@@ -11,37 +11,49 @@ const fs = require('fs');
1111
const pkg = require('./package.json');
1212
const external = Object.keys(pkg.dependencies);
1313

14+
1415
/**
1516
* Custom plugin to parse handlebar imports and precompile
1617
* the template on the fly. This reduces runtime by about
1718
* half on large projects.
1819
*/
19-
function handlebarsPlugin() {
20-
return {
21-
resolveId(file, importer) {
22-
if (file.endsWith('.hbs')) {
23-
return path.resolve(path.dirname(importer), file);
24-
}
25-
return null;
26-
},
27-
load(file) {
28-
if (file.endsWith('.hbs')) {
29-
const template = fs.readFileSync(file, 'utf8').toString().trim();
30-
const templateSpec = handlebars.precompile(template, {
31-
strict: true,
32-
noEscape: true,
33-
preventIndent: true,
34-
knownHelpersOnly: true,
35-
knownHelpers: {
36-
equals: true,
37-
notEquals: true,
38-
},
39-
});
40-
return `export default ${templateSpec};`;
41-
}
42-
return null;
43-
},
44-
};
20+
const handlebarsPlugin = () => ({
21+
resolveId: (file, importer) => {
22+
if (path.extname(file) === '.hbs') {
23+
return path.resolve(path.dirname(importer), file);
24+
}
25+
return null;
26+
},
27+
load: (file) => {
28+
if (path.extname(file) === '.hbs') {
29+
const template = fs.readFileSync(file, 'utf8').toString().trim();
30+
const templateSpec = handlebars.precompile(template, {
31+
strict: true,
32+
noEscape: true,
33+
preventIndent: true,
34+
knownHelpersOnly: true,
35+
knownHelpers: {
36+
equals: true,
37+
notEquals: true,
38+
},
39+
});
40+
return `export default ${templateSpec};`;
41+
}
42+
return null;
43+
}
44+
});
45+
46+
const getPlugins = () => {
47+
const plugins = [
48+
handlebarsPlugin(),
49+
typescript(),
50+
nodeResolve(),
51+
commonjs(),
52+
]
53+
if (process.env.NODE_ENV === 'development') {
54+
return plugins;
55+
}
56+
return [...plugins, terser()];
4557
}
4658

4759
export default {
@@ -59,17 +71,5 @@ export default {
5971
'handlebars/runtime',
6072
...external,
6173
],
62-
plugins: [
63-
handlebarsPlugin(),
64-
typescript({
65-
clean: true,
66-
}),
67-
nodeResolve(),
68-
commonjs(),
69-
terser({
70-
output: {
71-
comments: false,
72-
},
73-
}),
74-
],
74+
plugins: getPlugins(),
7575
};

src/typings/hbs.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ declare module '*.hbs' {
1010
export default {
1111
compiler: [8, '>= 4.3.0'],
1212
useData: true,
13-
main: function (container, depth0, helpers, partials, data) {
13+
main: function () {
1414
return '';
1515
},
1616
};

tsconfig.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
"strictFunctionTypes": true,
2222
"removeComments": true,
2323
"forceConsistentCasingInFileNames": true,
24-
"allowSyntheticDefaultImports": true,
25-
"isolatedModules": true
24+
"allowSyntheticDefaultImports": true
2625
},
2726

2827
"files": [

0 commit comments

Comments
 (0)