Skip to content

Commit

Permalink
build: use rollup to build vendor/autoprefixer.js
Browse files Browse the repository at this point in the history
  • Loading branch information
albb0920 committed Sep 9, 2020
1 parent 6800e4f commit 4afc942
Show file tree
Hide file tree
Showing 8 changed files with 19,515 additions and 67,292 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
pkg/

.bundle
*.lock
Gemfile.lock

build/node_modules/
22 changes: 22 additions & 0 deletions build/autoprefixer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import postcss from 'postcss'
import autoprefixer from 'autoprefixer'

export default {
process: (css, processOptions, pluginOptions) => {
// execjs does not support passing callback from ruby,
// which makes waiting for the promise to settle from async function impossible
var result = postcss([autoprefixer(pluginOptions)]).process(css, processOptions)

var warns = result.warnings().map(function (i) {
delete i.plugin
return i.toString()
})

var map = result.map ? result.map.toString() : null
return { css: result.css, map: map, warnings: warns }
},

info: (options) => {
return autoprefixer(options).info()
}
}
29 changes: 29 additions & 0 deletions build/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "build",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"browser": true,
"dependencies": {
"autoprefixer": "postcss/autoprefixer",
"nop": "^1.0.0",
"postcss": "postcss/postcss#ose",
"synchronous-promise": "^2.0.13",
"yarn": "^1.22.5"
},
"devDependencies": {
"@rollup/plugin-alias": "^3.1.1",
"@rollup/plugin-commonjs": "^15.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^9.0.0",
"@rollup/plugin-replace": "^2.3.3",
"rollup": "^2.26.10",
"rollup-plugin-node-polyfills": "^0.2.1"
},
"resolutions": {
"autoprefixer/postcss": "postcss/postcss#ose"
},
"scripts": {
"build": "yarn run rollup -c rollup.config.js"
}
}
42 changes: 42 additions & 0 deletions build/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import path from 'path'
import alias from '@rollup/plugin-alias'
import nodeResolve from '@rollup/plugin-node-resolve'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import nodePolyfills from 'rollup-plugin-node-polyfills'
import replace from '@rollup/plugin-replace'

export default {
input: 'autoprefixer.js',
output: {
file: '../vendor/autoprefixer.js',
format: 'iife',
name: 'autoprefixer',
sourcemap: 'inline'
},
plugins: [
// this line slips into browser build, patch for now
replace({
"terminalHighlight.registerInput(Input)": '',
include: "node_modules/postcss/lib/input.js",
delimiters: ['', '']
}),
json(),
alias({
entries: [
{ find: '@babel/register', replacement: 'nop' },
{ find: '@babel/core', replacement: 'nop' },
{ find: 'url', replacement: path.resolve(__dirname, 'url.js') }
]
}),
commonjs({
transformMixedEsModules: true
}),
nodeResolve({
browser: true,
preferBuiltins: false,
extensions: [".mjs", ".js", ".json", ".node", ".es6"]
}),
nodePolyfills()
]
}
8 changes: 8 additions & 0 deletions build/url.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = Object.assign(
{},
require("rollup-plugin-node-polyfills/polyfills/url.js"),
{
pathToFileURL: (path)=> { return `file:///${encodeURIComponent(path)}` },
fileURLToPath: (fileURL)=> { return decodeURIComponent(fileURL.repalce(/^file:\/\/\//, '')) }
}
)
Loading

0 comments on commit 4afc942

Please sign in to comment.