-
Notifications
You must be signed in to change notification settings - Fork 0
/
webpack.riot.config.js
187 lines (163 loc) · 3.96 KB
/
webpack.riot.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
const path = require('path')
const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const CleanWebpackPlugin = require('clean-webpack-plugin')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const CopyWebpackPlugin = require('copy-webpack-plugin')
const FriendlyErrorsWebpackPlugin = require('friendly-errors-webpack-plugin')
const isProduction = process.env.NODE_ENV === `production`
const isDevelopment = process.env.NODE_ENV === `development`
const cssLoaders = [
{
loader: 'css-loader',
options: {
sourceMap: false,
'import': false,
minimize: isProduction,
},
},
{
loader: 'postcss-loader',
options: {
sourceMap: false,
plugins: () => [require('autoprefixer')({grid: false})],
},
},
{
loader: 'sass-loader',
options: {
sourceMap: false,
includePaths: [path.resolve(__dirname,'./node_modules')],
},
},
];
const rules = [
{
test: /\.tag$/,
loader: 'riot-tag-loader',
options: {
hot: true
}
},
{
test: /\.js$/,
loader: 'babel-loader',
include: [
path.resolve(__dirname, 'riot'),
path.resolve(__dirname, 'node_modules/')
]
},
{
test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
}
},
{
test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
}
}
]
const plugins = [
// create index.html
new HtmlWebpackPlugin({
filename: 'index.html',
template: 'riot/index.html',
// inject: 'body',
minify: false,
chunksSortMode: 'dependency'
})
// add riot dependencies
// new WebpackCdnPlugin({
// modules: [
// {
// name: 'riot',
// var: 'riot',
// path: isProduction ? 'dist/riot.runtime.min.js' : 'dist/riot.runtime.js'
// },
// {
// name: 'riot-router',
// var: 'riotRouter',
// path: isProduction ? 'dist/riot-router.min.js' : 'dist/riot-router.js'
// }
// ],
// }),
]
const config = {
entry: {
'riot': path.resolve(__dirname,'riot/main.js'),
},
output: {
filename: isProduction ? '[name].[chunkhash].js' : '[name].js',
chunkFilename: isProduction ? '[name].[chunkhash].js' : '[name].js',
path: path.resolve(__dirname, isProduction ? 'public/riot-mdc-adapter' : 'dev'),
},
resolve: {
// alias: {
// 'riot-mdc-adapter': path.resolve(__dirname,'components/index.js'),
// 'riot': path.resolve(__dirname,'riot/')
// }
},
externals: {},
devtool: isProduction ? 'source-map' : 'cheap-eval-source-map',
module: { rules },
plugins
}
// Optimize for prod
if (isProduction) {
config.mode = 'production'
config.output.publicPath = '/riot-mdc-adapter/'
// extract css rule
config.module.rules.push({
test: /\.(css|scss)$/,
use: ExtractTextPlugin.extract({
use: cssLoaders,
fallback: 'style-loader'
})
})
config.plugins.push(
// clean output path
new CleanWebpackPlugin(config.output.path),
// split css
new ExtractTextPlugin({
filename: '[name].[chunkhash].css',
allChunks: true
}),
// copy assets
new CopyWebpackPlugin([
{
from: path.resolve(__dirname, 'static'),
to: config.output.path,
ignore: ['.*']
}
]),
);
}
// Enable dev server
if (isDevelopment) {
config.mode = 'development'
// laod css rule
config.module.rules.push({
test: /\.(css|scss)$/,
use: ['style-loader'].concat(cssLoaders)
})
config.plugins.push(
// HMR
new webpack.HotModuleReplacementPlugin(),
new FriendlyErrorsWebpackPlugin()
)
config.devServer = {
contentBase: path.resolve(__dirname, 'static'),
disableHostCheck: true,
hot: true,
quiet: true
}
// cloud9 support
process.env.IP && (config.devServer.host = process.env.IP)
process.env.PORT && (config.devServer.port = process.env.PORT)
}
module.exports = config