polymer-project-config
- Version 4.0.3
- Published
- 194 kB
- 6 dependencies
- BSD-3-Clause license
Install
npm i polymer-project-config
yarn add polymer-project-config
pnpm add polymer-project-config
Overview
reads, validates, and shapes your polymer.json project configuration
Index
Variables
variable defaultSourceGlobs
const defaultSourceGlobs: string[];
The default globs for matching all user application source files.
Functions
function applyBuildPreset
applyBuildPreset: (config: ProjectBuildOptions) => ProjectBuildOptions;
Apply a build preset (if a valid one exists on the config object) by deep merging the given config with the preset values.
Classes
class ProjectConfig
class ProjectConfig {}
constructor
constructor(options: ProjectOptions);
constructor - given a ProjectOptions object, create the correct project configuration for those options. This involves setting the correct defaults, validating options, warning on deprecated options, and calculating some additional properties.
property allFragments
readonly allFragments: string[];
property autoBasePath
readonly autoBasePath: boolean;
property builds
readonly builds: ProjectBuildOptions[];
property componentDir
readonly componentDir?: string;
property entrypoint
readonly entrypoint: string;
property extraDependencies
readonly extraDependencies: string[];
property fragments
readonly fragments: string[];
property lint
readonly lint: LintOptions;
property moduleResolution
readonly moduleResolution: ModuleResolutionStrategy;
property npm
readonly npm?: boolean;
property root
readonly root: string;
property shell
readonly shell?: string;
property sources
readonly sources: string[];
method initializeAnalyzer
initializeAnalyzer: () => Promise<{ urlLoader: FsUrlLoader; urlResolver: PackageUrlResolver; analyzer: Analyzer; warningFilter: WarningFilter;}>;
Get an analyzer (and other related objects) with configuration determined by this ProjectConfig.
method initializeAnalyzerFromDirectory
static initializeAnalyzerFromDirectory: ( dirname: string) => Promise<{ urlLoader: FsUrlLoader; urlResolver: PackageUrlResolver; analyzer: Analyzer; warningFilter: WarningFilter;}>;
Given a project directory, return an Analyzer (and related objects) with configuration inferred from polymer.json (and possibly other config files that we find and interpret).
method isFragment
isFragment: (filepath: string) => boolean;
method isShell
isShell: (filepath: string) => boolean;
method isSource
isSource: (filepath: string) => boolean;
method loadConfigFromFile
static loadConfigFromFile: (filepath: string) => ProjectConfig | null;
Given an absolute file path to a polymer.json-like ProjectOptions object, return a new ProjectConfig instance created with those options.
method loadOptionsFromFile
static loadOptionsFromFile: (filepath: string) => ProjectOptions | null;
Given an absolute file path to a polymer.json-like ProjectOptions object, read that file. If no file exists, null is returned. If the file exists but there is a problem reading or parsing it, throw an exception.
TODO: in the next major version we should make this method and the one below async.
method toJSON
toJSON: () => string;
Generate a JSON string serialization of this configuration. File paths will be relative to root.
method validate
validate: () => boolean;
Validates that a configuration is accurate, and that all paths are contained within the project root.
method validateAndCreate
static validateAndCreate: (configJsonObject: {}) => ProjectConfig;
Returns a new ProjectConfig from the given JSON object if it's valid.
TODO(rictic): For the next major version we should mark the constructor private, or perhaps make it validating. Also, we should standardize the naming scheme across the static methods on this class.
Throws if the given JSON object is an invalid ProjectOptions.
method validateOptions
static validateOptions: (configJsonObject: {}) => ProjectOptions;
Returns the given configJsonObject if it is a valid ProjectOptions object, otherwise throws an informative error message.
Interfaces
interface LintOptions
interface LintOptions {}
property filesToIgnore
filesToIgnore?: string[];
An array of file globs to never report warnings for.
The globs follow [minimatch] syntax, and any file that matches any of the listed globs will never show any linter warnings. This will typically not have a performance benefit, as the file will usually still need to be analyzed.
[minimatch]: https://github.com/isaacs/minimatch
property ignoreWarnings
ignoreWarnings?: string[];
Deprecated way of spelling the
warningsToIgnore
lint option.Used only if
warningsToIgnore
is not specified.
property rules
rules: string[];
The lint rules to run. Can be the code of a collection of rules like "polymer-2" or an individual rule like "dom-module-invalid-attrs".
property warningsToIgnore
warningsToIgnore?: string[];
Warnings to ignore. After the rules are run, any warning that matches one of these codes is ignored, project-wide.
interface ProjectBuildOptions
interface ProjectBuildOptions {}
property addPushManifest
addPushManifest?: boolean;
If
true
, generate an [HTTP/2 Push Manifest](https://github.com/GoogleChrome/http2-push-manifest) for your application.
property addServiceWorker
addServiceWorker?: boolean;
Generate a service worker for your application to cache all files and assets on the client.
Polymer CLI will generate a service worker for your build using the [sw-precache library](https://github.com/GoogleChrome/sw-precache). To customize your service worker, create a sw-precache-config.js file in your project directory that exports your configuration. See the [sw-precache README](https://github.com/GoogleChrome/sw-precache) for a list of all supported options.
Note that the sw-precache library uses a cache-first strategy for maximum speed and makes some other assumptions about how your service worker should behave. Read the "Considerations" section of the sw-precache README to make sure that this is suitable for your application.
property basePath
basePath?: boolean | string;
Update the entrypoint's
<base>
tag, to support serving this build from a non-root path, such as when doing differential serving based on user agent. Requires that a<base>
tag already exists. This works well in conjunction with the convention of using relative URLs for static resources and absolute URLs for application routes.If
true
, use the buildname
. If astring
, use that value. Leading/trailing slashes are optional.
property browserCapabilities
browserCapabilities?: BrowserCapability[];
Capabilities required for a browser to consume this build. Values include
es2015
andpush
. See canonical list at: https://github.com/Polymer/prpl-server-node/blob/master/src/capabilities.tsThis field is purely a hint to servers reading this configuration, and does not affect the build process. A server supporting differential serving (e.g. prpl-server) can use this field to help decide which build to serve to a given user agent.
property bundle
bundle?: | boolean | { /** URLs of files and/or folders that should not be inlined. */ excludes?: string[]; /** Inline external CSS file contents into <style> tags. */ inlineCss?: boolean; /** Inline external Javascript file contents into <script> tags. */ inlineScripts?: boolean; /** Rewrite element attributes inside of templates when inlining html. */ rewriteUrlsInTemplates?: boolean; /** Create identity source maps for inline scripts. */ sourcemaps?: boolean; /** * Remove all comments except those tagged '@license', or starting with * `<!--!` or `<!--#`, when true. */ stripComments?: boolean; /** Remove unreachable/unused code when bundling. */ treeshake?: boolean; };
By default, fragments are unbundled. This is optimal for HTTP/2-compatible servers and clients.
If the --bundle flag is supplied, all fragments are bundled together to reduce the number of file requests. This is optimal for sending to clients or serving from servers that are not HTTP/2 compatible.
property css
css?: { /** Minify inlined and external CSS. */ minify?: | boolean | { /** CSS files listed here will not be minified. */ exclude?: string[]; };};
Options for processing CSS.
property html
html?: { /** Minify HTMl by removing comments and whitespace. */ minify?: | boolean | { /** HTML files listed here will not be minified. */ exclude?: string[]; };};
Options for processing HTML.
property insertPrefetchLinks
insertPrefetchLinks?: boolean;
Insert prefetch link elements into your fragments so that all dependencies are prefetched immediately. Add dependency prefetching by inserting `
tags into entrypoint and
` tags into fragments and shell for all dependencies.Note this option may trigger duplicate requests. See https://github.com/Polymer/polymer-build/issues/239 for details.
property js
js?: { /** Minify inlined and external JavaScript. */ minify?: | boolean | { /** JavaScript files listed here will not be minified. */ exclude?: string[]; }; /** Use babel to compile all ES6 JS down to ES5 for older browsers. */ compile?: | boolean | JsCompileTarget | { target?: JsCompileTarget; /** JavaScript files listed here will not be compiled. */ exclude?: string[]; }; /** Transform ES modules to AMD modules. */ transformModulesToAmd?: boolean;};
Options for processing JavaScript.
property name
name?: string;
The name of this build, used to determine the output directory name.
property preset
preset?: string;
A build preset for this build. A build can inherit some base configuration from a named preset.
property swPrecacheConfig
swPrecacheConfig?: string;
A config file that's passed to the [sw-precache library](https://github.com/GoogleChrome/sw-precache). See [its README](https://github.com/GoogleChrome/sw-precache) for details of the format of this file.
Ignored if
addServiceWorker
is nottrue
.Defaults to
"sw-precache-config.js
.
interface ProjectOptions
interface ProjectOptions {}
property autoBasePath
autoBasePath?: boolean;
Set
basePath: true
on all builds. See that option for more details.
property builds
builds?: ProjectBuildOptions[];
List of build option configurations.
property componentDir
componentDir?: string;
The directory containing this project's dependencies.
property entrypoint
entrypoint?: string;
The path relative to
root
of the entrypoint file that will be served for app-shell style projects. Usually this is index.html.
property extraDependencies
extraDependencies?: string[];
List of file paths, relative to the project directory, that should be included as extraDependencies in the build target.
property fragments
fragments?: string[];
The path relative to
root
of the lazily loaded fragments. Usually the pages of an app or other bundles of on-demand resources.
property lint
lint?: LintOptions;
Options for the Polymer Linter.
property moduleResolution
moduleResolution?: ModuleResolutionStrategy;
Algorithm to use for resolving module specifiers in import and export statements when rewriting them to be web-compatible. Valid values are:
"none": Disable module specifier rewriting. This is the default. "node": Use Node.js resolution to find modules.
property npm
npm?: boolean;
Sets other options' defaults to NPM-appropriate values:
- 'componentDir': 'node_modules/'
property root
root?: string;
Path to the root of the project on the filesystem. This can be an absolute path, or a path relative to the current working directory. Defaults to the current working directory of the process.
property shell
shell?: string;
The path relative to
root
of the app shell element.
property sources
sources?: string[];
List of glob patterns, relative to root, of this project's sources to read from the file system.
Type Aliases
type JsCompileTarget
type JsCompileTarget = 'es5' | 'es2015' | 'es2016' | 'es2017' | 'es2018';
type ModuleResolutionStrategy
type ModuleResolutionStrategy = 'none' | 'node';
Namespaces
namespace minimatch-all
module 'minimatch-all' {}
function minimatchAll
minimatchAll: (filePath: string, globs: string[]) => boolean;
Package Files (3)
Dependencies (6)
Dev Dependencies (2)
Peer Dependencies (1)
Badge
To add a badge like this oneto your package's README, use the codes available below.
You may also use Shields.io to create a custom badge linking to https://www.jsdocs.io/package/polymer-project-config
.
- Markdown[](https://www.jsdocs.io/package/polymer-project-config)
- HTML<a href="https://www.jsdocs.io/package/polymer-project-config"><img src="https://img.shields.io/badge/jsDocs.io-reference-blue" alt="jsDocs.io"></a>
- Updated .
Package analyzed in 3238 ms. - Missing or incorrect documentation? Open an issue for this package.