-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add support for handling assets directly in reptar.config.js.
BREAKING CHANGE: Themes are removed. You must now configure assets in your reptar.config.js. This requires removing config.path.themes, config.theme, and optionally adding config.assets.
- Loading branch information
Showing
40 changed files
with
316 additions
and
625 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,43 @@ | ||
import browserify from 'browserify'; | ||
import babelify from 'babelify'; | ||
import uglifyify from 'uglifyify'; | ||
|
||
export default { | ||
calculateDestination(destination) { | ||
return destination; | ||
}, | ||
|
||
write(file) { | ||
const { path: filePath } = file; | ||
|
||
const bundle = browserify(); | ||
bundle.add(filePath); | ||
|
||
bundle.transform( | ||
babelify.configure({ | ||
presets: [ | ||
['env', { | ||
targets: { | ||
browsers: ['last 2 versions'], | ||
}, | ||
uglify: true, | ||
}], | ||
], | ||
}) | ||
); | ||
|
||
bundle.transform( | ||
uglifyify | ||
); | ||
|
||
return new Promise((resolve, reject) => { | ||
bundle.bundle((err, buffer) => { | ||
if (err) { | ||
reject(err); | ||
} else { | ||
resolve(buffer.toString('utf8')); | ||
} | ||
}); | ||
}); | ||
}, | ||
}; |
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,49 @@ | ||
import path from 'path'; | ||
import fs from 'fs-extra'; | ||
import less from 'less'; | ||
import LessPluginAutoPrefix from 'less-plugin-autoprefix'; | ||
import LessPluginCleanCSS from 'less-plugin-clean-css'; | ||
import LessPluginNpmImport from 'less-plugin-npm-import'; | ||
|
||
export default { | ||
calculateDestination(destination) { | ||
return destination.replace( | ||
/\.less$/, | ||
'.css' | ||
); | ||
}, | ||
|
||
write(file) { | ||
const { path: filePath } = file; | ||
|
||
// Derive source path from the input source file. | ||
const sourcePath = path.dirname(filePath); | ||
|
||
const lessPlugins = [ | ||
new LessPluginNpmImport({ | ||
basedir: sourcePath, | ||
}), | ||
new LessPluginAutoPrefix({ | ||
browsers: ['last 2 versions'], | ||
}), | ||
new LessPluginCleanCSS(), | ||
]; | ||
|
||
const rawAsset = fs.readFileSync(filePath, 'utf8'); | ||
|
||
return new Promise((resolve, reject) => { | ||
less.render(rawAsset, { | ||
// Specify search paths for @import directives. | ||
paths: [sourcePath], | ||
plugins: lessPlugins, | ||
}, (e, output) => { | ||
if (e) { | ||
reject(e); | ||
return; | ||
} | ||
|
||
resolve(output.css); | ||
}); | ||
}); | ||
}, | ||
}; |
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
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
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
Oops, something went wrong.