This repository has been archived by the owner on Mar 28, 2024. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: stub out project and make 1 test work
- Loading branch information
0 parents
commit 18b8e31
Showing
9 changed files
with
2,505 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
dist/ | ||
node_modules/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './dist/critical'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
__export(require('./dist/critical')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"name": "webpack-plugin-critical", | ||
"version": "1.0.0", | ||
"description": "Webpack plugin for the critical CSS inliner library.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "tsc && jasmine" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/nrwl/webpack-plugin-critical.git" | ||
}, | ||
"keywords": [ | ||
"webpack", | ||
"critical" | ||
], | ||
"author": "jeffbcross", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/nrwl/webpack-plugin-critical/issues" | ||
}, | ||
"homepage": "https://github.com/nrwl/webpack-plugin-critical#readme", | ||
"devDependencies": { | ||
"jasmine": "^2.5.2", | ||
"typescript": "^2.1.4" | ||
}, | ||
"dependencies": { | ||
"@types/jasmine": "^2.5.38", | ||
"@types/node": "^6.0.53", | ||
"critical": "^0.8.1", | ||
"webpack-util-cleantmp": "^1.0.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"spec_dir": "dist", | ||
"spec_files": [ | ||
"**/*[sS]pec.js" | ||
], | ||
"helpers": [ | ||
"helpers/**/*.js" | ||
], | ||
"stopSpecOnExpectationFailure": false, | ||
"random": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { CriticalPlugin } from './critical'; | ||
|
||
const mockCompilation = { | ||
assets: { | ||
'foo.json': { | ||
source: () => '{"foo": "bar"}', | ||
size: () => 14 | ||
} | ||
} | ||
}; | ||
|
||
const mockCompiler = { | ||
plugin: (lifecycle) => { | ||
|
||
} | ||
} | ||
|
||
describe('CriticalPlugin', () => { | ||
describe('apply', () => { | ||
it('should register for emit lifecycle', () => { | ||
let plugin = new CriticalPlugin(); | ||
let compiler = jasmine.createSpyObj('compiler', ['plugin']); | ||
plugin.apply(compiler); | ||
|
||
let args = (<jasmine.Spy>compiler.plugin).calls.first().args; | ||
expect(args[0]).toBe('emit'); | ||
expect(typeof args[1]).toBe('function'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { resolve } from 'path'; | ||
const critical = require('critical'); | ||
import { cleantmp } from 'webpack-util-cleantmp'; | ||
|
||
export interface CriticalPluginOptions { | ||
base?: string; | ||
inline?: boolean; | ||
minify?: boolean; | ||
extract?: boolean; | ||
timeout?: number | ||
} | ||
|
||
export class CriticalPlugin { | ||
constructor(public options: CriticalPluginOptions = {}) { | ||
const opts = {...this.options}; | ||
this.options = {...{ | ||
base: '', | ||
inline: true, | ||
minify: true, | ||
extract: true, | ||
timeout: 30000 | ||
}, ...options}; | ||
} | ||
|
||
|
||
emit(compilation, callback) { | ||
const options = this.options; | ||
const subscription = cleantmp({ | ||
prefix: 'criticalcss', | ||
globToDisk: '**/*.+(css|html)', | ||
globFromDisk: '**/*.+(css|html)', | ||
assets: compilation.assets | ||
}) | ||
.subscribe((tmp) => { | ||
const opts = {...options, ...{ | ||
base: resolve(tmp, options.base) | ||
}}; | ||
|
||
critical.generate(opts, (err, output) => { | ||
// TODO: Make recursive and start at root of tmp | ||
subscription.unsubscribe(); | ||
callback(err); | ||
}); | ||
}) | ||
} | ||
|
||
apply(compiler) { | ||
compiler.plugin("emit", (compilation, callback) => { | ||
this.emit(compilation, callback); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es5", | ||
"rootDir": "src", | ||
"outDir": "dist", | ||
"declaration": true, | ||
"noImplicitAny": false, | ||
"moduleResolution": "node", | ||
"sourceMap": true, | ||
"sourceRoot": "src", | ||
"lib": [ | ||
"es2015", | ||
"dom" | ||
], | ||
"typeRoots": [ | ||
"node_modules/@types" | ||
] | ||
}, | ||
"files": [ | ||
"src/critical.ts", | ||
"src/critical.spec.ts" | ||
] | ||
} |
Oops, something went wrong.