-
Notifications
You must be signed in to change notification settings - Fork 13
/
webpack.config.js
139 lines (138 loc) · 5.25 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
const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const extractElementsCss = new ExtractTextPlugin({ filename: 'css/elements.css' });
const extractElementsNPCss = new ExtractTextPlugin({ filename: 'css/elementsNoPlain.css' });
const extractDemoCss = new ExtractTextPlugin({ filename: 'css/demo.css' });
const demo = `${__dirname}/demo/demo.js`;
const demoScss = `${__dirname}/demo/demo.scss`;
const main = `${__dirname}/demo/main.js`;
const compounds = `${__dirname}/index.js`;
const elements = `${__dirname}/mainElements.js`;
const elementsNP = `${__dirname}/src/styles/elementsNoPlain.scss`;
const icons = `${__dirname}/src/styles/assets/icons/p-icons-sprite-1.1.svg`;
const osItalicWoff = `${__dirname}/src/styles/assets/fonts/opensans-italic.woff`;
const osItalicWoffII = `${__dirname}/src/styles/assets/fonts/opensans-italic.woff2`;
const osLightWoff = `${__dirname}/src/styles/assets/fonts/opensans-light.woff`;
const osLightWoffII = `${__dirname}/src/styles/assets/fonts/opensans-light.woff2`;
const osLightItalicWoff = `${__dirname}/src/styles/assets/fonts/opensans-lightitalic.woff`;
const osLightItalicWoffII = `${__dirname}/src/styles/assets/fonts/opensans-lightitalic.woff2`;
const osRegularWoff = `${__dirname}/src/styles/assets/fonts/opensans-regular.woff`;
const osRegularWoffII = `${__dirname}/src/styles/assets/fonts/opensans-regular.woff2`;
const osSemiBoldWoff = `${__dirname}/src/styles/assets/fonts/opensans-semibold.woff`;
const osSemiBoldWoffII = `${__dirname}/src/styles/assets/fonts/opensans-semibold.woff2`;
const osSemiBoldItalicWoff = `${__dirname}/src/styles/assets/fonts/opensans-semibolditalic.woff`;
const osSemiBoldItalicWoffII = `${__dirname}/src/styles/assets/fonts/opensans-semibolditalic.woff2`;
const imgDarkOctocat = `${__dirname}/src/styles/assets/images/dark-octocat.svg`;
const imgPearsonSprite = `${__dirname}/src/styles/assets/images/pearson-sprite.svg`;
const imgPearsonIcon = `${__dirname}/src/styles/assets/images/PearsonIcon.svg`;
const imgPearsonLogo = `${__dirname}/src/styles/assets/images/PearsonLogo.svg`;
module.exports = {
entry: {
demo : [ demo, demoScss ],
dev : [ icons, osItalicWoff, osItalicWoffII, osLightWoff, osLightWoffII, osLightItalicWoff, osLightItalicWoffII, osRegularWoff, osRegularWoffII, osSemiBoldWoff, osSemiBoldWoffII, osSemiBoldItalicWoff, osSemiBoldItalicWoffII, imgDarkOctocat, imgPearsonSprite, imgPearsonIcon, imgPearsonLogo ],
eventInstantiator : [ main ],
dist : [ compounds ]
},
output: {
path : path.resolve(__dirname, 'build'),
filename : '[name].elements-sdk.js',
publicPath : '/elements-sdk/',
libraryTarget : 'umd'
},
devtool: 'source-map',
devServer: {
host : '0.0.0.0',
port : 8081,
publicPath : '/elements-sdk/',
https : false,
overlay : true,
watchContentBase : true,
disableHostCheck : true,
historyApiFallback : true,
watchOptions : { poll: true },
staticOptions : { redirect: false },
contentBase : path.join(__dirname, 'build')
},
externals: [
{
react: {
root: 'React',
commonjs2: 'react',
commonjs: 'react',
amd: 'react'
},
'react-dom': {
root: 'ReactDOM',
commonjs2: 'react-dom',
commonjs: 'react-dom',
amd: 'react-dom'
}
}
],
module: {
rules: [
{
test: /elements\.scss/,
use: extractElementsCss.extract(['css-loader', 'sass-loader'])
},
{
test: /elementsNoPlain\.scss/,
use: extractElementsNPCss.extract(['css-loader', 'sass-loader'])
},
{
test: /demo\.scss/,
use: extractDemoCss.extract(['css-loader', 'sass-loader'])
},
{
test: /(components)\S*\.(css|scss)/,
use: [{
loader: 'style-loader'
},{
loader: 'css-loader'
},{
loader: 'sass-loader'
}]
},
{
test: /\.(js|jsx)$/,
exclude: /node_modules/,
loader: 'babel-loader'
},
{
test: /\.(ttf|woff|woff2)$/,
loader: 'file-loader',
options: {
name: '/fonts/[name].[ext]?[hash]'
}
},
{
test: /\/icons\/\S+\.svg$/,
loader: 'file-loader',
options: {
name: '/icons/[name].[ext]?[hash]'
}
},
{
test: /\/images\/\S+\.(gif|jpg|png|svg)$/,
loader: 'file-loader',
options: {
name: '/images/[name].[ext]?[hash]'
},
}
]
},
plugins: [
extractElementsCss,
extractElementsNPCss,
extractDemoCss,
new HtmlWebpackPlugin({
template: 'demo/index.html'
}),
new webpack.DefinePlugin({
'process.env.NODE_ENV' : JSON.stringify(process.env.NODE_ENV)
}),
new webpack.NamedModulesPlugin()
]
};