johnagan / clean-webpack-plugin

A webpack plugin to remove your build folder(s) before building
MIT License
1.96k stars 135 forks source link

work in production only #69

Closed rashanoureldin closed 6 years ago

rashanoureldin commented 6 years ago

Hi how i can make clean run in production only below is my package json and webpack config file

`var HtmlWebpackPlugin = require('html-webpack-plugin'); var ExtractTextPlugin = require('extract-text-webpack-plugin'); var CleanWebpackPlugin = require('clean-webpack-plugin'); var webpack = require('webpack'); var path = require('path');

var isProd = process.env.NODE_ENV === 'production' var cssDev = ['style-loader','css-loader','sass-loader'] var cssProd = ExtractTextPlugin.extract({ fallback:'style-loader', use: ['css-loader', 'sass-loader'], publicPath: './dist' }) var cssConfig = isProd ? cssProd : cssDev

module.exports = { entry: './src/app.js', output: { path: path.resolve( __dirname , './dist'), filename: '[name].bundle.js' }, module: { rules: [ { test: /.scss$/, use: cssConfig }, { test: /.js$/, exclude: /node_modules/, loader: "babel-loader" }, { test: /.pug$/, loaders: ['html-loader', 'pug-html-loader'] }, { test: /.(jpe?g|png|gif|svg)$/i, use:['file-loader?name=images/[name].[ext]','image-webpack-loader'] } //file-loader?name=[name].[ext]&outputPath=images/&publicPath=images/ ] }, devtool: 'inline-source-map', devServer:{ contentBase: path.join(__dirname, "dist"), compress: true, hot:true, port: 9000, stats: "errors-only", open: true }, plugins: [ // new CleanWebpackPlugin(['dist/.','dist//.','dist//*/.']), new CleanWebpackPlugin(['dist/.*']), new HtmlWebpackPlugin({ title: 'Webpack Project Demo', // minify: { // collapseWhitespace:true // }, hash: true, template: './src/index.pug', // Load a custom template (lodash by default see the FAQ for details) }), new ExtractTextPlugin({ filename:'app.css', disable: !isProd , allChunks:true }), new webpack.NamedModulesPlugin(), new webpack.HotModuleReplacementPlugin(), ] }`

my json is { "name": "bcreation", "version": "1.0.0", "description": "Building Wordpress site using Bedrock", "main": "index.js", "scripts": { "dev": "webpack-dev-server", "prod": "cross-env NODE_ENV=production webpack -p" }, "repository": { "type": "git", "url": "git+ssh://git@bitbucket.org/rashanoureldin/bcreations.git" }, "author": "Rasha Noureldin", "license": "ISC", "homepage": "https://bitbucket.org/rashanoureldin/bcreations#readme", "devDependencies": { "babel": "^6.23.0", "babel-core": "^6.26.0", "babel-loader": "^7.1.2", "babel-preset-es2015": "^6.24.1", "babel-preset-react": "^6.24.1", "bootstrap-loader": "^2.2.0", "bootstrap-sass": "^3.3.7", "clean-webpack-plugin": "^0.1.17", "cross-env": "^5.1.1", "css-loader": "^0.28.7", "extract-text-webpack-plugin": "^3.0.2", "file-loader": "^1.1.5", "html-loader": "^0.5.1", "html-webpack-plugin": "^2.30.1", "image-webpack-loader": "^3.4.2", "imports-loader": "^0.7.1", "jquery": "^3.2.1", "node-sass": "^4.7.2", "pug": "^2.0.0-rc.4", "pug-html-loader": "^1.1.5", "react": "^16.1.1", "react-dom": "^16.1.1", "resolve-url-loader": "^2.2.0", "rimraf": "^2.6.2", "sass-loader": "^6.0.6", "style-loader": "^0.19.0", "url-loader": "^0.6.2", "webpack": "^3.8.1", "webpack-dev-server": "^2.9.4" } }

johnagan commented 6 years ago

Your plugins are just an array. You could append the Clean plugin if isProd