-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from kimulaco/feat/support-postcss-v8
feat: support postcss v8
- Loading branch information
Showing
18 changed files
with
4,136 additions
and
3,663 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 @@ | ||
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 |
---|---|---|
|
@@ -3,4 +3,4 @@ module.exports = { | |
env: { | ||
jest: true | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
.node-version | ||
npm-debug.log | ||
node_modules | ||
test/**/dist |
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 |
---|---|---|
@@ -1,4 +1,8 @@ | ||
.DS_Store | ||
.node-version | ||
npm-debug.log | ||
node_modules | ||
.github | ||
test | ||
.editorconfig | ||
.eslintrc.js | ||
.eslintignore |
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,8 @@ | ||
# Change Log | ||
|
||
## 1.4.0 | ||
|
||
- Support PostCSS v7 and v8. | ||
- Updated [amp-custom](https://github.com/kimulaco/amp-custom) to v1.4.0. | ||
- Updated devDependencies. | ||
- Fixed CI config. |
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
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,36 @@ | ||
const postcss = require('postcss') | ||
const compileAmpCustom = require('./libs/compileAmpCustom') | ||
const isPostCSSv8 = require('./libs/isPostCSSv8') | ||
const PLUGIN_NAME = 'postcss-amp-custom' | ||
|
||
module.exports = (option = {}) => { | ||
option = Object.assign({ | ||
enableByteLimit: false | ||
}, option || {}) | ||
|
||
if (isPostCSSv8(postcss)) { | ||
return { | ||
postcssPlugin: PLUGIN_NAME, | ||
Root (root, postcss) { | ||
postcss.result.root = compileAmpCustom(root, postcss, option) | ||
} | ||
} | ||
} else { | ||
return postcss.plugin(PLUGIN_NAME, (option) => { | ||
return (root, result) => { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
const postcss = require('postcss') | ||
const style = compileAmpCustom(root, postcss, option) | ||
result.root = postcss.parse(style) | ||
resolve() | ||
} catch (error) { | ||
reject(error) | ||
} | ||
}) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
module.exports.postcss = true |
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,17 @@ | ||
const AmpCustom = require('amp-custom') | ||
const ampCustom = new AmpCustom() | ||
|
||
const compileAmpCustom = (root, postcss, option = {}) => { | ||
const style = ampCustom.optimize(root.toString()) | ||
|
||
if ( | ||
option.enableByteLimit && | ||
ampCustom.isOverMaxByte(style) | ||
) { | ||
throw new Error('AMP stylesheet exceeds the 75KB limit.') | ||
} | ||
|
||
return postcss.parse(style) | ||
} | ||
|
||
module.exports = compileAmpCustom |
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 @@ | ||
const isPostCSSv8 = (postcss) => { | ||
return typeof postcss.Root !== 'undefined' | ||
} | ||
|
||
module.exports = isPostCSSv8 |
Oops, something went wrong.