This repository has been archived by the owner on Apr 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.config.js
113 lines (104 loc) · 3.07 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
const path = require('path');
const webpack = require('webpack');
const CleanWebpackPlugin = require('clean-webpack-plugin');
const OUTPUT_FILE_NAME = 'uncharted.cards';
const isProduction = (process.env.NODE_ENV === 'production'); // eslint-disable-line
const isServing = (process.env.WEBPACK_ENV === 'serve'); // eslint-disable-line
const outputFileName = isProduction ? `${OUTPUT_FILE_NAME}.min` : OUTPUT_FILE_NAME;
const HANDLEBAR_RUNTIME_PATH = isProduction ? 'handlebars/dist/handlebars.runtime.min' : 'handlebars/runtime';
/** Base config */
const config = {
entry: ['./src/main.scss', './src/index.js'],
output: {
filename: `${outputFileName}.js`,
path: path.resolve(__dirname, 'dist'),
library: ['Uncharted', 'Cards'],
libraryTarget: 'umd',
},
resolve: {
alias: {
handlebars: HANDLEBAR_RUNTIME_PATH,
},
},
module: {
rules: [
{
enforce: 'pre',
test: /\.js$/,
exclude: /node_modules/,
loader: 'eslint-loader',
},
{
test: /\.js$/,
loader: 'babel-loader',
options: {
presets: [
['latest', { es2015: { modules: false } }],
],
},
exclude: /node_modules/,
},
{
test: /\.scss$|\.css$/,
use: [
{
loader: "style-loader", // creates style nodes from JS strings
},
{
loader: "css-loader", // translates CSS into CommonJS
},
{
loader: "sass-loader", // compiles Sass to CSS
},
],
},
{
test: /\.handlebars$/,
loader: 'handlebars-loader',
query: {
helperDirs: [
path.resolve(__dirname, 'src/handlebarHelper'),
],
runtime: HANDLEBAR_RUNTIME_PATH,
},
},
],
},
externals: {
jquery: 'jQuery',
},
plugins: [
new webpack.optimize.ModuleConcatenationPlugin(),
],
devServer: {
disableHostCheck: true,
},
};
if (!isServing) {
config.plugins.push(...[
new CleanWebpackPlugin(['dist']),
]);
}
// Environment specific configs
if (isProduction) {
config.devtool = 'source-map';
config.plugins.push(...[
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('production'),
},
}),
]);
config.mode = 'production';
} else {
config.devtool = 'inline-source-map';
config.plugins.push(...[
new webpack.DefinePlugin({
'process.env': {
'NODE_ENV': JSON.stringify('dev'),
},
}),
]);
config.mode = 'development';
}
module.exports = config;