Add cleanup step to js dev builds to remove unused files
parent
e3ceb855a1
commit
39096e6c3d
|
@ -77,6 +77,7 @@
|
|||
"mocha-loader": "^0.7.1",
|
||||
"mustache": "^2.2.1",
|
||||
"node-sass": "^4.5.3",
|
||||
"on-build-webpack": "^0.1.0",
|
||||
"postcss-browser-reporter": "^0.4.0",
|
||||
"postcss-calc": "^5.2.0",
|
||||
"postcss-loader": "^0.8.0",
|
||||
|
|
|
@ -1,11 +1,16 @@
|
|||
var webpack = require('webpack');
|
||||
var path = require('path');
|
||||
var ExtractTextPlugin = require("extract-text-webpack-plugin");
|
||||
var HtmlWebpackPlugin = require("html-webpack-plugin");
|
||||
var package = require('../package.json');
|
||||
var dependencies = package.dependencies;
|
||||
var webpack = require('webpack')
|
||||
var path = require('path')
|
||||
var ExtractTextPlugin = require('extract-text-webpack-plugin')
|
||||
var HtmlWebpackPlugin = require('html-webpack-plugin')
|
||||
var package = require('../package.json')
|
||||
const WebpackOnBuildPlugin = require('on-build-webpack')
|
||||
const fs = require('fs')
|
||||
var dependencies = package.dependencies
|
||||
|
||||
const buildDir = path.resolve(__dirname, '../build')
|
||||
|
||||
module.exports = {
|
||||
watch: true,
|
||||
devtool: 'source-map',
|
||||
entry: {
|
||||
app: path.resolve(__dirname, '..', 'src', 'index.js'),
|
||||
|
@ -48,15 +53,21 @@ module.exports = {
|
|||
},
|
||||
{
|
||||
test: /\.scss$/,
|
||||
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!sass-loader!resolve-url!sass?sourceMap'),
|
||||
loader: ExtractTextPlugin.extract(
|
||||
'style-loader',
|
||||
'css-loader!sass-loader!resolve-url!sass?sourceMap'
|
||||
),
|
||||
},
|
||||
{
|
||||
test: /\.css$/,
|
||||
loader: ExtractTextPlugin.extract('style-loader', 'css-loader!postcss-loader'),
|
||||
loader: ExtractTextPlugin.extract(
|
||||
'style-loader',
|
||||
'css-loader!postcss-loader'
|
||||
),
|
||||
},
|
||||
{
|
||||
test : /\.(ico|png|cur|jpg|ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
|
||||
loader : 'file',
|
||||
test: /\.(ico|png|cur|jpg|ttf|eot|svg|woff(2)?)(\?[a-z0-9]+)?$/,
|
||||
loader: 'file',
|
||||
},
|
||||
{
|
||||
test: /\.js$/,
|
||||
|
@ -70,7 +81,7 @@ module.exports = {
|
|||
],
|
||||
},
|
||||
sassLoader: {
|
||||
includePaths: [path.resolve(__dirname, "node_modules")],
|
||||
includePaths: [path.resolve(__dirname, 'node_modules')],
|
||||
},
|
||||
eslint: {
|
||||
failOnWarning: false,
|
||||
|
@ -78,10 +89,10 @@ module.exports = {
|
|||
},
|
||||
plugins: [
|
||||
new webpack.ProvidePlugin({
|
||||
$: "jquery",
|
||||
jQuery: "jquery",
|
||||
$: 'jquery',
|
||||
jQuery: 'jquery',
|
||||
}),
|
||||
new ExtractTextPlugin("chronograf.css"),
|
||||
new ExtractTextPlugin('chronograf.css'),
|
||||
new HtmlWebpackPlugin({
|
||||
template: path.resolve(__dirname, '..', 'src', 'index.template.html'),
|
||||
inject: 'body',
|
||||
|
@ -93,7 +104,32 @@ module.exports = {
|
|||
new webpack.DefinePlugin({
|
||||
VERSION: JSON.stringify(require('../package.json').version),
|
||||
}),
|
||||
new WebpackOnBuildPlugin(function(stats) {
|
||||
const newlyCreatedAssets = stats.compilation.assets
|
||||
|
||||
const unlinked = []
|
||||
fs.readdir(path.resolve(buildDir), (err, files) => {
|
||||
files.forEach(file => {
|
||||
if (!newlyCreatedAssets[file]) {
|
||||
console.log('Removed ', file)
|
||||
const del = path.resolve(buildDir + file)
|
||||
fs.stat(del, function(err, stat) {
|
||||
if (err == null) {
|
||||
try {
|
||||
fs.unlink(path.resolve(buildDir + file))
|
||||
console.log('Removed ', file)
|
||||
unlinked.push(file)
|
||||
} catch (e) {}
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
if (unlinked.length > 0) {
|
||||
console.log('Removed old assets: ', unlinked)
|
||||
}
|
||||
})
|
||||
}),
|
||||
],
|
||||
postcss: require('./postcss'),
|
||||
target: 'web',
|
||||
};
|
||||
}
|
||||
|
|
|
@ -5134,6 +5134,10 @@ object.values@^1.0.3:
|
|||
function-bind "^1.1.0"
|
||||
has "^1.0.1"
|
||||
|
||||
on-build-webpack@^0.1.0:
|
||||
version "0.1.0"
|
||||
resolved "https://registry.yarnpkg.com/on-build-webpack/-/on-build-webpack-0.1.0.tgz#a287c0e17766e6141926e5f2cbb0d8bb53b76814"
|
||||
|
||||
on-finished@~2.3.0:
|
||||
version "2.3.0"
|
||||
resolved "https://registry.yarnpkg.com/on-finished/-/on-finished-2.3.0.tgz#20f1336481b083cd75337992a16971aa2d906947"
|
||||
|
|
Loading…
Reference in New Issue