Skip to content

Commit

Permalink
feat(*): initial commit of less plugin (should be working)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vheissu committed Jun 28, 2016
1 parent 1e7bb0b commit bf3ae96
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 3 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/node_modules
.idea
.vscode
npm-debug.log*
/typings
/dist
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/typings
/.vscode
19 changes: 19 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
sudo: false
language: node_js
cache:
directories:
- node_modules
notifications:
email: false
node_js:
- 6
before_install:
- npm i -g npm
before_script:
- npm prune
- npm install @easy-webpack/core webpack@beta
after_success:
- npm run semantic-release
branches:
except:
- /^v\d+\.\d+\.\d+$/
6 changes: 3 additions & 3 deletions LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)
MIT License

Copyright (c) 2016 easy-webpack
Copyright (c) 2016 Dwayne Charrington

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand All @@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
SOFTWARE.
58 changes: 58 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
"name": "@easy-webpack/config-less",
"description": "Easy Webpack configuration module for using Less in your Webpack applications.",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"scripts": {
"test": "TS_NODE_FAST=true TS_NODE_NO_PROJECT=true ava",
"prepublish": "typings install",
"build": "rimraf dist && tsc -p .",
"semantic-release": "npm run build && semantic-release pre && npm publish --access=public && semantic-release post"
},
"repository": {
"type": "git",
"url": "https://github.com/easy-webpack/config-less.git"
},
"keywords": [
"css",
"webpack",
"easy",
"configurator",
"configuration",
"config",
"simple"
],
"author": "Dwayne Charrington <dwaynecharrington@gmail.com> (http://ilikekillnerds.com)",
"license": "MIT",
"bugs": {
"url": "https://github.com/easy-webpack/config-less/issues"
},
"homepage": "https://github.com/easy-webpack/config-less#readme",
"devDependencies": {
"ava": "^0.15.2",
"semantic-release": "^4.3.5",
"ts-node": "^0.9.1",
"tslint": "^3.11.0",
"tslint-config-standard": "^1.2.2",
"typescript": ">=1.9.0-dev.20160619-1.0 || ^2.0.0",
"typings": "^1.3.0"
},
"dependencies": {
"css-loader": "^0.23.1",
"extract-text-webpack-plugin": "^1.0.1",
"less-loader": "^2.2.3",
"style-loader": "^0.13.1"
},
"peerDependencies": {
"@easy-webpack/core": "*"
},
"ava": {
"files": [
"test/**/*.{ts,js}"
],
"tap": false,
"require": [
"ts-node/register"
]
}
}
34 changes: 34 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import {WebpackConfig, get} from '@easy-webpack/core'
const ExtractTextPlugin = require('extract-text-webpack-plugin')

/**
* CSS loader support for *.less
* @param sourceMap enable generating source maps (slower build)
* @param extractCss leave empty to skip extracting CSS or define an object with filename and optionally allChunks (boolean)
*/
export = function less(extractCss = { filename: '[name].css', allChunks: false, sourceMap: false }) {
return function less(this: WebpackConfig): WebpackConfig {
const extractCSSinstance = extractCss ? new ExtractTextPlugin(extractCss.filename || '[name].css', extractCss) : null
const cssLoader = `css${extractCss.sourceMap ? '?sourceMap!less' : '!less'}`
const config = {
module: {
loaders: get(this, 'module.loaders', []).concat([{
test: /\.less$/i,
loaders: extractCss ? extractCSSinstance.extract('style', cssLoader) : ['style', cssLoader]
}])
}
} as WebpackConfig
if (extractCSSinstance) {
config.plugins = [
/**
* Plugin: ExtractTextPlugin
* It moves every import "style.css" in entry chunks into a single concatenated css output file.
* So your styles are no longer inlined into the javascript, but separate in a css bundle file (styles.css).
* If your total stylesheet volume is big, it will be faster because the stylesheet bundle is loaded in parallel to the javascript bundle.
*/
extractCSSinstance
].concat(get(this, 'plugins', []))
}
return config
}
}
6 changes: 6 additions & 0 deletions test/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import test from 'ava'
import {assign} from '../src'

test(`dummy`, t => {
t.true(true)
})
20 changes: 20 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"experimentalDecorators": true,
"moduleResolution": "node",
"allowJs": false,
"declaration": true,
"outDir": "dist",
"rootDir": "src",
"sourceMap": true,
"lib": ["es6"]
},
"exclude": [
"node_modules",
"dist",
"test",
"example"
]
}
3 changes: 3 additions & 0 deletions tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "tslint-config-standard"
}
9 changes: 9 additions & 0 deletions typings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"dependencies": {
"debug": "registry:npm/debug#2.0.0+20160511151334",
"lodash": "registry:npm/lodash#4.0.0+20160416211519"
},
"globalDependencies": {
"node": "registry:env/node#6.0.0+20160610031852"
}
}

0 comments on commit bf3ae96

Please sign in to comment.