Skip to content

Commit 74c56b8

Browse files
committed
build: unignore webpack config
1 parent 76bf416 commit 74c56b8

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ node_modules
77
/*.js
88
/*.js.flow
99
!/.babelrc.js
10+
!/webpack.config.js

webpack.config.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
'use strict'
2+
3+
/* eslint-env node */
4+
5+
const webpack = require('webpack')
6+
const path = require('path')
7+
const ProgressPlugin = require('webpack/lib/ProgressPlugin')
8+
const env = process.env.NODE_ENV
9+
const isTest = env === 'test'
10+
const isProd = env === 'production'
11+
12+
const plugins = [
13+
new webpack.DefinePlugin({
14+
'process.env.NODE_ENV': JSON.stringify(env),
15+
}),
16+
new ProgressPlugin({ profile: false }),
17+
]
18+
19+
const externals = isTest
20+
? {
21+
cheerio: 'window',
22+
'react/addons': true,
23+
'react/lib/ExecutionEnvironment': true,
24+
'react/lib/ReactContext': true,
25+
}
26+
: {}
27+
28+
module.exports = {
29+
mode: isProd ? 'production' : 'development',
30+
devtool: isTest ? 'source-map' : 'eval',
31+
output: isTest
32+
? {
33+
library: 'reactViewSlider',
34+
libraryTarget: 'umd',
35+
}
36+
: {
37+
path: path.join(__dirname, 'demo'),
38+
filename: 'bundle.js',
39+
},
40+
plugins,
41+
resolve: {
42+
alias: {
43+
'react-view-slider': path.join(__dirname, 'src'),
44+
},
45+
},
46+
module: {
47+
rules: [
48+
{
49+
loader: 'babel-loader',
50+
exclude: /node_modules/,
51+
options: {
52+
cacheDirectory: true,
53+
plugins: [
54+
'@babel/plugin-transform-flow-strip-types',
55+
'@babel/plugin-syntax-dynamic-import',
56+
'@babel/plugin-proposal-export-default-from',
57+
'@babel/plugin-proposal-export-namespace-from',
58+
'@babel/plugin-proposal-object-rest-spread',
59+
'@babel/plugin-proposal-class-properties',
60+
],
61+
presets: [
62+
['@babel/preset-env', { targets: { browsers: 'last 2 versions' } }],
63+
'@babel/preset-react',
64+
'@babel/preset-flow',
65+
],
66+
},
67+
test: /\.js$/,
68+
},
69+
],
70+
},
71+
externals,
72+
}
73+
74+
if (!isTest) {
75+
module.exports.entry = ['@babel/polyfill', './demo/index.js']
76+
module.exports.devServer = {
77+
port: 3000,
78+
contentBase: path.join(__dirname, 'demo'),
79+
}
80+
}

0 commit comments

Comments
 (0)