forked from clay/clay-kiln
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
145 lines (142 loc) · 4.29 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const path = require('path'),
ExtractTextPlugin = require('extract-text-webpack-plugin'),
docs = new ExtractTextPlugin('docs/inputs.md'),
styles = new ExtractTextPlugin('dist/clay-kiln-[name].css'),
webpack = require('webpack'),
LodashModuleReplacementPlugin = require('lodash-webpack-plugin'),
OptimizeCSSAssetsPlugin = require('optimize-css-assets-webpack-plugin'),
cssnano = require('cssnano'),
prod = process.argv.indexOf('-p') !== -1,
kilnVersion = require('./package.json').version;
let plugins = [
styles,
docs,
new LodashModuleReplacementPlugin({
shorthands: true, // allow _.map(collection, prop)
cloning: true, // used by edit
caching: true, // cache _.cloneDeep, etc
collections: true, // allow objects in collection methods
deburring: true, // remove diacritical marks
unicode: true, // support unicode
memoizing: true, // used by cache
coercions: true, // allow coercions
flattening: true, // allow flattening methods
paths: true, // allow deep _.get, _.set, _.has
// note: we're explicitly not allowing chaining or currying
}),
new webpack.DefinePlugin({
'process.env': {
KILN_VERSION: `"${kilnVersion}"`,
LOG: '"trace"'
}
}),
new webpack.optimize.ModuleConcatenationPlugin(),
new webpack.ContextReplacementPlugin(/moment[\/\\]locale$/, /en/) // some dependency (chrono-node) is using moment.js (allow that, but make them drop their 300kB of locales)
];
if (prod) {
plugins = plugins.concat([
new webpack.DefinePlugin({
'process.env': {
NODE_ENV: '"production"'
}
}),
new webpack.optimize.UglifyJsPlugin({
compress: {
sequences: true,
properties: true,
dead_code: true,
conditionals: true,
comparisons: true,
booleans: true,
loops: true,
unused: true,
if_return: true,
reduce_vars: true,
passes: 2,
unsafe: true,
warnings: false
},
output: {
inline_script: true
}
}),
new OptimizeCSSAssetsPlugin({
cssProcessor: cssnano,
cssProcessorOptions: {
discardComments: {
removeAll: true,
},
safe: true // run cssnano in safe mode
},
canPrint: false
})
]);
}
module.exports = {
target: 'web',
node: {
__filename: true, // actually expand filenames, used for logging
__dirname: true
},
entry: {
edit: './edit.js',
view: './view.js',
'view-public': './view-public.js'
},
output: {
path: __dirname,
filename: 'dist/clay-kiln-[name].js'
},
module: {
rules: [{
// todo: remove vue-unit (and update vue-unit dep) once vue-unit hits 0.3.0
test: /node_modules\/(@tom-kitchin\/vue-unit|keen-ui|striptags|clayutils)\//,
loader: 'babel-loader'
}, {
test: /\.js$/,
exclude: /node_modules/,
loader: 'babel-loader'
}, {
test: /\.scss|.css$/,
use: styles.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader', 'sass-loader']
})
}, {
test: /\.svg$/,
use: 'raw-loader'
}, {
test: /\.vue$/,
loader: 'vue-loader',
options: {
esModule: false, // todo: enable this when we can use it with keenUI
extractCSS: true,
loaders: {
css: styles.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader', 'sass-loader?data=@import "styleguide/keen-variables.scss";']
}),
sass: styles.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader', 'sass-loader?data=@import "styleguide/keen-variables.scss";']
}),
scss: styles.extract({
fallback: 'style-loader',
use: ['css-loader', 'postcss-loader', 'sass-loader?data=@import "styleguide/keen-variables.scss";']
}),
docs: docs.extract('raw-loader')
}
}
}]
},
resolve: {
// note: when importing vue components, you don't have to specify .vue
// also, when importing keen-ui components, do so as `keen/UiComponentName`,
// so they get imported correctly when testing
extensions: ['.js', '.json', '.vue'],
alias: {
keen: path.resolve(__dirname, 'node_modules/keen-ui/src')
}
},
plugins: plugins
};