-
Notifications
You must be signed in to change notification settings - Fork 26
/
webpack.config.js
72 lines (65 loc) · 1.65 KB
/
webpack.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const webpack = require('webpack')
const path = require('path')
const env = require('yargs').argv.env;
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const OptimizeCssAssetsPlugin = require('optimize-css-assets-webpack-plugin')
const PackageJson = require('./package.json')
const resolve = dir => path.join(__dirname, '.', dir)
const banner = `CanvasTools v${PackageJson.version}
(github)${PackageJson.homepage}
(url) https://smohan.net/lab/canvastools
(c) smohan <https://smohan.net>
license ${PackageJson.license}`
let plugins = [],
outputFile;
if (env === 'build') {
plugins = [
new ExtractTextPlugin('canvastools.min.css'),
new webpack.optimize.UglifyJsPlugin({
minimize: true,
comments: false,
sourceMap: false,
}),
new OptimizeCssAssetsPlugin(),
new webpack.BannerPlugin(banner),
];
outputFile = 'canvastools.min.js';
} else {
plugins = [
new ExtractTextPlugin('canvastools.css'),
new webpack.BannerPlugin(banner),
]
outputFile = 'canvastools.js';
}
module.exports = {
entry: './src/js/main',
devtool: env !== 'build' ? 'source-map' : false,
output: {
path: __dirname + '/dist',
filename: outputFile,
library: 'CanvasTools',
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
rules: [{
test: /\.js$/,
loader: 'babel-loader',
include: [resolve('src')]
}, {
test: /\.css$/,
use: ExtractTextPlugin.extract(['css-loader', 'postcss-loader'])
}, {
test: /\.scss$/,
use: ExtractTextPlugin.extract(['css-loader', 'sass-loader', 'postcss-loader'])
}]
},
resolve: {
modules: [resolve('src')],
extensions: ['.json', '.js'],
alias: {
'@': resolve('src')
}
},
plugins: plugins
}