-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
179 additions
and
34 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 |
---|---|---|
|
@@ -4,3 +4,6 @@ node_modules/ | |
|
||
#test | ||
test/build | ||
|
||
#example | ||
example/css-pack/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
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,68 @@ | ||
css-pack | ||
======================= | ||
|
||
|
||
Working example for extracting non-minified css asset | ||
|
||
## Installation ## | ||
|
||
```bash | ||
npm install | ||
``` | ||
|
||
## Usage ## | ||
|
||
```bash | ||
npm run build | ||
``` | ||
|
||
>You would see, `app.js`, `app.min.js`, `app.css`, `app.min.css` are generated at `dist` folder | ||
## Configuration ## | ||
|
||
**You should not minify css via `css-loader`, but leave it to [optimize-css-assets-webpack-plugin](https://github.com/NMFR/optimize-css-assets-webpack-plugin)** | ||
|
||
```javascript | ||
const path = require('path'); | ||
const webpack = require('webpack'); | ||
const UnminifiedWebpackPlugin = require('../../'); | ||
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | ||
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); | ||
const cssnano = require('cssnano'); | ||
|
||
module.exports = { | ||
entry: { | ||
app: './src/index.js' | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: '[name].min.js' | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: ExtractTextPlugin.extract({ | ||
fallback: 'style-loader', | ||
use: 'css-loader' | ||
}) | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new webpack.optimize.UglifyJsPlugin({ | ||
compress: { | ||
warnings: false | ||
} | ||
}), | ||
new UnminifiedWebpackPlugin(), | ||
new ExtractTextPlugin('[name].min.css'), | ||
//use optimize-css-assets-webpack-plugin to minify css assets | ||
new OptimizeCssAssetsPlugin({ | ||
//IMPORTANT: only minify asset ends with .min.css | ||
assetNameRegExp: /\.min\.css$/g, | ||
cssProcessor: cssnano | ||
}) | ||
] | ||
}; | ||
``` |
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,19 @@ | ||
{ | ||
"name": "css-pack", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "src/index.js", | ||
"scripts": { | ||
"build": "rm -rf dist && webpack" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"devDependencies": { | ||
"css-loader": "^0.28.7", | ||
"cssnano": "^3.10.0", | ||
"extract-text-webpack-plugin": "^3.0.1", | ||
"optimize-css-assets-webpack-plugin": "^3.2.0", | ||
"style-loader": "^0.19.0", | ||
"webpack": "^3.6.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,6 @@ | ||
|
||
body { | ||
color: #fff; | ||
font-size: 16px; | ||
opacity: 0.9; | ||
} |
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 @@ | ||
|
||
import './index.css'; | ||
|
||
function test() { | ||
console.log('fuck you'); | ||
} | ||
|
||
test(); |
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,41 @@ | ||
const path = require('path'); | ||
const webpack = require('webpack'); | ||
const UnminifiedWebpackPlugin = require('../../'); | ||
const ExtractTextPlugin = require('extract-text-webpack-plugin'); | ||
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin'); | ||
const cssnano = require('cssnano'); | ||
|
||
module.exports = { | ||
entry: { | ||
app: './src/index.js' | ||
}, | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: '[name].min.js' | ||
}, | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: ExtractTextPlugin.extract({ | ||
fallback: 'style-loader', | ||
use: 'css-loader' | ||
}) | ||
} | ||
] | ||
}, | ||
plugins: [ | ||
new webpack.optimize.UglifyJsPlugin({ | ||
compress: { | ||
warnings: false | ||
} | ||
}), | ||
new UnminifiedWebpackPlugin(), | ||
new ExtractTextPlugin('[name].min.css'), | ||
new OptimizeCssAssetsPlugin({ | ||
//IMPORTANT: only minify asset ends with .min.css | ||
assetNameRegExp: /\.min\.css$/g, | ||
cssProcessor: cssnano | ||
}) | ||
] | ||
}; |
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