-
Notifications
You must be signed in to change notification settings - Fork 0
/
stencil.config.ts
93 lines (86 loc) · 2.37 KB
/
stencil.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import fs from 'fs';
import { Config } from '@stencil/core';
import { postcss } from '@stencil/postcss';
import { sass } from '@stencil/sass';
import cssnano from 'cssnano';
import postCSSPresetEnv from 'postcss-preset-env';
import replace from '@rollup/plugin-replace';
import { createFilter } from 'rollup-pluginutils';
interface Options {
include?: string;
exclude?: string;
}
const pkgManifest = JSON.parse(fs.readFileSync('package.json', 'utf8'));
function gql(opts: Options = {}) {
const filter = createFilter(opts.include || 'src/**/*.graphql', opts.exclude);
return {
name: 'gql',
// eslint-disable-next-line consistent-return
transform(code, id) {
if (filter(id)) {
return {
code: `export default ${JSON.stringify(code)}`,
};
}
},
};
}
function svg(opts: Options = {}) {
const filter = createFilter(opts.include || '**/*.svg', opts.exclude);
return {
name: 'svg',
// eslint-disable-next-line consistent-return
transform(code, id) {
if (filter(id)) {
// Rollup by default returns a base64 URL. Decode that back into HTML for SVGs
const transformed = code.replace(/'[^']+'/, (data) =>
JSON.stringify(
Buffer.from(data.replace('data:image/svg+xml;base64,', ''), 'base64').toString('utf8')
)
);
return { code: transformed };
}
},
};
}
export const config: Config = {
namespace: 'manifold-plan-table',
excludeSrc: ['**/*-happo.*'],
globalStyle: 'src/styles/styles.scss',
outputTargets: [
{
type: 'dist',
esmLoaderPath: '../loader',
},
{
type: 'www',
serviceWorker: null, // disable service workers
},
],
testing: {
moduleNameMapper: {
'\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$':
'<rootDir>/__mocks__/fileMock.js',
},
testPathIgnorePatterns: ['/node_modules/'],
transformIgnorePatterns: ['node_modules/(?!@manifoldco/manifold-init)'],
transform: {
'\\.graphql$': './jest-transform-graphql',
},
},
plugins: [
gql(),
svg(), // import SVGs from Mercury
sass(),
postcss({
plugins: [cssnano(), postCSSPresetEnv()],
}),
replace({
exclude: 'node_modules/**',
delimiters: ['<@', '@>'],
values: {
NPM_PACKAGE_VERSION: pkgManifest.version,
},
}),
],
};