1 |
|
2 | import os from "os";
|
3 | import path from "path";
|
4 |
|
5 | import autoprefixer from "autoprefixer";
|
6 | import babel from "rollup-plugin-babel";
|
7 | import commonjs from "rollup-plugin-commonjs";
|
8 | import cssnano from "cssnano";
|
9 | import nodeResolve from "rollup-plugin-node-resolve";
|
10 | import nodeSass from "node-sass";
|
11 | import postcss from "postcss";
|
12 | import filesize from "rollup-plugin-filesize";
|
13 | import sass from "rollup-plugin-sass";
|
14 | import sizes from "rollup-plugin-sizes";
|
15 | import sourcemaps from "rollup-plugin-sourcemaps";
|
16 | import { terser } from "rollup-plugin-terser";
|
17 | import typescript from "rollup-plugin-typescript2";
|
18 | import visualizer from "rollup-plugin-visualizer";
|
19 |
|
20 | import { version } from "./package.json";
|
21 |
|
22 | const config = {
|
23 | input: "src/index.ts",
|
24 | output: {
|
25 | sourcemap: true,
|
26 | banner: `/*!
|
27 | * @license
|
28 | *
|
29 | * Scandit Barcode Scanner SDK for the Web
|
30 | * v. ${version}
|
31 | *
|
32 | * Copyright © 2019 Scandit AG. All Rights Reserved.
|
33 | *
|
34 | * The use of this software is governed by the Scandit Terms and Conditions.
|
35 | * https://ssl.scandit.com/terms/test.pdf
|
36 | *
|
37 | * The following sets forth attribution notices for third party software that may be contained in portions of the product.
|
38 | * https://docs.scandit.com/stable/web/LICENSE
|
39 | */`
|
40 | },
|
41 | plugins: [
|
42 | nodeResolve({
|
43 | mainFields: ["module", "main", "browser"]
|
44 | }),
|
45 | commonjs({
|
46 | namedExports: {
|
47 | "node_modules/eventemitter3/index.js": ["EventEmitter"]
|
48 | }
|
49 | }),
|
50 | sass({
|
51 | insert: true,
|
52 | runtime: nodeSass,
|
53 | processor: css => {
|
54 | return postcss([autoprefixer, cssnano])
|
55 | .process(css, {
|
56 | from: undefined
|
57 | })
|
58 | .then(result => {
|
59 | return result.css;
|
60 | });
|
61 | }
|
62 | }),
|
63 | typescript({
|
64 | tsconfig: "./tsconfig.module.json",
|
65 | typescript: require("typescript"),
|
66 | cacheRoot: "./node_modules/.cache/.rts2_cache/" + process.env.CACHE_FOLDER,
|
67 | useTsconfigDeclarationDir: true,
|
68 | clean: process.env.ROLLUP_MODE === "size-info",
|
69 | objectHashIgnoreUnknownHack: process.env.ROLLUP_MODE === "size-info"
|
70 | }),
|
71 | babel({
|
72 | extensions: [".js", ".jsx", ".ts", ".tsx"],
|
73 | presets: [
|
74 | [
|
75 | "@babel/preset-env",
|
76 | {
|
77 | modules: false
|
78 | }
|
79 | ]
|
80 | ],
|
81 | plugins: [
|
82 | [
|
83 | "@babel/plugin-transform-runtime",
|
84 | {
|
85 | corejs: 2
|
86 | }
|
87 | ]
|
88 | ],
|
89 | overrides: [
|
90 | {
|
91 | test: "**/engineWorker.ts",
|
92 | presets: [
|
93 | [
|
94 | "@babel/preset-env",
|
95 | {
|
96 | targets: {
|
97 | browsers: [
|
98 | "Chrome >= 57",
|
99 | "ChromeAndroid >= 59",
|
100 | "Firefox >= 52",
|
101 | "FirefoxAndroid >= 55",
|
102 | "Opera >= 44",
|
103 | "OperaMobile >= 46",
|
104 | "Safari >= 11",
|
105 | "iOS >= 11",
|
106 | "Edge >= 16",
|
107 | "Samsung >= 7"
|
108 | ]
|
109 | },
|
110 | modules: false,
|
111 | include: [
|
112 | "transform-template-literals",
|
113 | "transform-function-name",
|
114 | "transform-arrow-functions",
|
115 | "transform-parameters"
|
116 | ],
|
117 | exclude: ["transform-typeof-symbol", "transform-for-of"]
|
118 | }
|
119 | ]
|
120 | ],
|
121 | plugins: [
|
122 | [
|
123 | "@babel/plugin-transform-runtime",
|
124 | {
|
125 | corejs: false,
|
126 | helpers: false,
|
127 | regenerator: false
|
128 | }
|
129 | ]
|
130 | ]
|
131 | }
|
132 | ],
|
133 | babelrc: false,
|
134 | runtimeHelpers: true,
|
135 | exclude: "node_modules/**"
|
136 | })
|
137 | ],
|
138 | onwarn: function(message) {
|
139 | if (/Circular dependency:/.test(message)) {
|
140 | return;
|
141 | }
|
142 | if (/The "ongenerate" hook used by plugin rollup-plugin-sizes is deprecated./.test(message)) {
|
143 | return;
|
144 | }
|
145 | if (/The \'this\' keyword is equivalent to \'undefined\' at the top level of an ES module/.test(message)) {
|
146 | return;
|
147 | }
|
148 | console.error(message);
|
149 | }
|
150 | };
|
151 |
|
152 | if (process.env.ROLLUP_MODE === "size-info") {
|
153 | config.plugins.push(sizes());
|
154 | config.plugins.push(filesize());
|
155 | config.plugins.push(
|
156 | visualizer({
|
157 | filename: path.join(os.tmpdir(), "size-info.html"),
|
158 | open: true,
|
159 | title: "WebSDK Bundle Size",
|
160 | template: "sunburst"
|
161 | })
|
162 | );
|
163 | }
|
164 |
|
165 | if (process.env.ROLLUP_MODE === "minify") {
|
166 | config.plugins.push(
|
167 | terser({
|
168 | warnings: true,
|
169 | output: {
|
170 | comments: /Scandit Barcode Scanner SDK for the Web/i
|
171 | },
|
172 | compress: {
|
173 | passes: 3
|
174 | }
|
175 | })
|
176 | );
|
177 | config.plugins.push(sourcemaps());
|
178 | } else {
|
179 | config.plugins.push(sourcemaps());
|
180 | }
|
181 |
|
182 | export default config;
|