This repository has been archived by the owner on Jun 20, 2019. It is now read-only.
forked from yuri-karadzhov/interactive-logo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebpack.config.babel.js
140 lines (134 loc) · 3.56 KB
/
webpack.config.babel.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
import path from 'path';
import webpack from 'webpack';
import browserslist from 'browserslist';
import autoprefixer from 'autoprefixer';
import ExtractTextPlugin from 'extract-text-webpack-plugin';
import HtmlWebpackPlugin from 'html-webpack-plugin';
import cfg from './build.config';
const IS_DEVELOPMENT = process.env.NODE_ENV !== 'production';
const IS_GLOBAL = process.env.DISTRIBUTION === 'global';
const rootPath = path.join(__dirname, cfg.src.root);
const outputPath = path.join(__dirname, cfg.src.output);
const texturesPath = path.join(__dirname, cfg.src.textures);
const modelsPath = path.join(__dirname, cfg.src.models);
const fontsPath = path.join(__dirname, cfg.src.fonts);
const config = {
context: rootPath,
entry: {
index: [
IS_DEVELOPMENT || IS_GLOBAL
? './index.global'
: './index'
]
},
output: {
path: outputPath,
publicPath: '/',
filename: '[name].js',
libraryTarget: IS_DEVELOPMENT ? 'var' : 'commonjs2'
},
resolve: {
extensions: ['.js', '.scss']
},
devtool: IS_DEVELOPMENT ? false : 'source-map',
plugins: [
new webpack.LoaderOptionsPlugin({
options: {
sassLoader: {
data: `$is_development: ${IS_DEVELOPMENT};`
},
postcss: [autoprefixer({
browsers: browserslist(null, {
path: cfg.ext.browserslist
})
})],
debug: IS_DEVELOPMENT,
// temporary until the following issues wouldn't be resolved:
// - https://github.com/bholloway/resolve-url-loader/issues/33
// - https://github.com/webpack/webpack/issues/3018
context: rootPath,
output: {
path: outputPath
}
}
}),
new webpack.NoErrorsPlugin(),
new webpack.DefinePlugin({
IS_DEVELOPMENT: JSON.stringify(IS_DEVELOPMENT)
}),
new ExtractTextPlugin({
filename: '[name].css',
allChunks: true,
disable: !IS_GLOBAL
})
],
module: {
loaders: [{
test: /\.scss$/,
include: rootPath,
loader: IS_DEVELOPMENT
? 'style!css!resolve-url!sass'
: ExtractTextPlugin.extract('css?minimize!postcss!resolve-url!sass')
}, {
test: /\.view.html/,
loader: 'html-loader'
}]
},
devServer: {
watchOptions: {
aggregateTimeout: 100
},
contentPath: 'dist/',
historyApiFalback: true
}
};
if (!IS_DEVELOPMENT) {
config.module.loaders.push({
test: /\.(png|jpg|svg|ttf|eot|woff|woff2|json)$/,
loader: 'url-loader?limit=30000&name=[path][name].[ext]'
}, {
test: /\.js$/,
include: rootPath,
loader: 'babel'
});
config.plugins.push(
new webpack.optimize.UglifyJsPlugin({
compress: {
warnings: false,
'drop_console': true,
unsafe: true
}
})
);
} else {
config.module.loaders.push({
test: /\.(png|jpg|svg|ttf|eot|woff|woff2)$/,
include: texturesPath,
loader: 'file-loader?name=[path][name].[ext]'
}, {
test: /\.(png|jpg|svg|ttf|eot|woff|woff2)$/,
exclude: texturesPath,
loader: 'url-loader?limit=10000&name=[path][name].[ext]'
}, {
test: /\.json/,
include: modelsPath,
loader: 'file-loader?name=[path][name].[ext]'
}, {
test: /\.json/,
include: fontsPath,
loader: 'file-loader?name=[path][name].[ext]'
});
}
if (IS_DEVELOPMENT || IS_GLOBAL) {
config.plugins.push(
new HtmlWebpackPlugin({
inject: true,
template: 'index.html',
minify: IS_DEVELOPMENT ? false : {
includeAutoGeneratedTags: true,
collapseWhitespace: true
}
})
);
}
export default config;