UNPKG

22.1 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.extractCSS = exports.injectCSS = exports.injectStyleLoader = exports.CSS = exports.img = exports.url = exports.markdown = exports.JS = exports.extractCSSPlugin = undefined;
7
8var _objectWithoutProperties2 = require('babel-runtime/helpers/objectWithoutProperties');
9
10var _objectWithoutProperties3 = _interopRequireDefault(_objectWithoutProperties2);
11
12var _stringify = require('babel-runtime/core-js/json/stringify');
13
14var _stringify2 = _interopRequireDefault(_stringify);
15
16var _extends2 = require('babel-runtime/helpers/extends');
17
18var _extends3 = _interopRequireDefault(_extends2);
19
20exports.defaultConfig = defaultConfig;
21exports.mergeConfig = mergeConfig;
22exports.moduleRequest = moduleRequest;
23exports.loader = loader;
24exports.configureWebpack = configureWebpack;
25exports.readConfigSync = readConfigSync;
26
27var _invariant = require('invariant');
28
29var _invariant2 = _interopRequireDefault(_invariant);
30
31var _fs = require('fs');
32
33var _fs2 = _interopRequireDefault(_fs);
34
35var _path = require('path');
36
37var _path2 = _interopRequireDefault(_path);
38
39var _webpack = require('webpack');
40
41var _webpack2 = _interopRequireDefault(_webpack);
42
43var _babelCore = require('babel-core');
44
45var _extractTextWebpackPlugin = require('extract-text-webpack-plugin');
46
47var _extractTextWebpackPlugin2 = _interopRequireDefault(_extractTextWebpackPlugin);
48
49var _minimatch = require('minimatch');
50
51var _utils = require('./compiler/utils');
52
53function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
54
55/**
56 * @copyright 2016-present, Sitegen team
57 */
58
59var BABEL_PRESET_ES2015 = require.resolve('babel-preset-es2015');
60var BABEL_PRESET_STAGE_1 = require.resolve('babel-preset-stage-1');
61var BABEL_PRESET_REACT = require.resolve('babel-preset-react');
62
63function defaultConfig(_ref) {
64 var env = _ref.env;
65
66
67 var deployCSS = env.development ? injectCSS : extractCSS;
68
69 return {
70
71 devtool: env.development ? 'cheap-module-source-map' : undefined,
72
73 babel: {
74 presets: [BABEL_PRESET_ES2015, BABEL_PRESET_STAGE_1, BABEL_PRESET_REACT]
75 },
76
77 loaders: {
78 '**/*.js': JS,
79 '**/*.md': [JS, markdown]
80 },
81
82 globalLoaders: {
83 '**/*.css': deployCSS(CSS({ minimize: env.production })),
84 '**/*.png': img,
85 '**/*.jpg': img,
86 '**/*.jpeg': img,
87 '**/*.gif': img,
88 '**/*.ico': img
89 },
90
91 plugins: [(env.content || env.production) && extractCSSPlugin, env.production && new _webpack2.default.optimize.UglifyJsPlugin({
92 compress: { warnings: false }
93 })]
94 };
95}
96
97function mergeConfig() {
98 for (var _len = arguments.length, config = Array(_len), _key = 0; _key < _len; _key++) {
99 config[_key] = arguments[_key];
100 }
101
102 config = config.filter(Boolean);
103 (0, _invariant2.default)(config.length > 0, 'Trying to merge empty list of configurations');
104 if (config.length === 1) {
105 return config[0];
106 } else {
107 return config.reduce(mergeConfigImpl);
108 }
109}
110
111function mergeArray(a, b) {
112 return [].concat(a).concat(b).filter(Boolean);
113}
114
115function mergeConfigImpl(a, b) {
116 return (0, _extends3.default)({}, a, b, {
117 entry: mergeArray(a.entry, b.entry),
118 babel: (0, _extends3.default)({}, a.babel, b.babel, {
119 presets: mergeArray(a.presets, b.presets),
120 plugins: mergeArray(a.babel && a.babel.plugins, b.babel && b.babel.plugins)
121 }),
122 output: (0, _extends3.default)({}, a.output, b.output),
123 loaders: (0, _extends3.default)({}, a.loaders, b.loaders),
124 globalLoaders: (0, _extends3.default)({}, a.globalLoaders, b.globalLoaders),
125 plugins: mergeArray(a.plugins, b.plugins)
126 });
127}
128
129function moduleRequest(id) {
130 for (var _len2 = arguments.length, loader = Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
131 loader[_key2 - 1] = arguments[_key2];
132 }
133
134 loader.reverse();
135 return normalizeLoader(loader) + '!' + id;
136}
137
138function loader(loader) {
139 return loaderImpl({ loader: loader });
140}
141
142function loaderImpl(config) {
143 var mergeQuery = config.mergeQuery || function (a, b) {
144 return (0, _extends3.default)({}, a, b);
145 };
146 var configurator = function configurator(query) {
147 return loaderImpl((0, _extends3.default)({}, config, {
148 query: mergeQuery(config.query, query)
149 }));
150 };
151 configurator.config = config;
152 configurator.toLoaderString = function toLoaderString() {
153 return normalizeLoader(config);
154 };
155 configurator.toString = configurator.toLoaderString;
156 return configurator;
157}
158
159function normalizeLoader(element) {
160 if (Array.isArray(element)) {
161 return element.map(normalizeLoader).join('!');
162 } else if (typeof element === 'string') {
163 return element;
164 } else if (element.toLoaderString) {
165 return element.toLoaderString();
166 } else {
167 if (element.query) {
168 return element.loader + '?' + (0, _stringify2.default)(element.query);
169 } else {
170 return element.loader;
171 }
172 }
173}
174
175function makePatterMatcher(pattern) {
176 var patterMatcher = new _minimatch.Minimatch(pattern);
177
178 var matcher = function matcher(filename) {
179 return patterMatcher.match(filename);
180 };
181 matcher.toString = function () {
182 return '[PatternMatcher ' + pattern + ']';
183 };
184 matcher.inspect = matcher.toString;
185
186 return matcher;
187}
188
189function configureWebpackLoader(context, pattern, loader, global) {
190 if (!global) {
191 pattern = _path2.default.join(context, pattern);
192 }
193 var test = makePatterMatcher(pattern);
194 return {
195 loader: normalizeLoader(loader),
196 test: test
197 };
198}
199
200function configureWebpackLoaderList(context, loaders, global) {
201 var result = [];
202 for (var pattern in loaders) {
203 var _loader = loaders[pattern];
204 result.push(configureWebpackLoader(context, pattern, _loader, global));
205 }
206 return result;
207}
208
209function configureWebpack(_ref2) {
210 var context = _ref2.context;
211 var loaders = _ref2.loaders;
212 var globalLoaders = _ref2.globalLoaders;
213 var config = (0, _objectWithoutProperties3.default)(_ref2, ['context', 'loaders', 'globalLoaders']);
214
215 loaders = configureWebpackLoaderList(context, loaders);
216 globalLoaders = configureWebpackLoaderList(context, globalLoaders, true);
217 return (0, _extends3.default)({}, config, {
218 context: context,
219 output: (0, _extends3.default)({}, config.output, {
220 path: _path2.default.resolve(config.context, config.output.path)
221 }),
222 module: {
223 loaders: loaders.concat(globalLoaders)
224 }
225 });
226}
227
228function readConfigSync(filename) {
229 var source = _fs2.default.readFileSync(filename, 'utf8');
230 source = (0, _babelCore.transform)(source, {
231 filename: filename,
232 presets: [BABEL_PRESET_ES2015, BABEL_PRESET_STAGE_1]
233 }).code;
234 return (0, _utils.evalAsModule)(source, filename);
235}
236
237var extractCSSPlugin = exports.extractCSSPlugin = new _extractTextWebpackPlugin2.default('bundle.css');
238
239var JS = exports.JS = loader(require.resolve('babel-loader'));
240
241var markdown = exports.markdown = loader(require.resolve('reactdown/webpack'));
242
243var url = exports.url = loader(require.resolve('url-loader'));
244
245var img = exports.img = url({ limit: 10000 });
246
247var CSS = exports.CSS = loader(require.resolve('css-loader'));
248
249var injectStyleLoader = exports.injectStyleLoader = loader(require.resolve('style-loader'));
250
251var injectCSS = exports.injectCSS = function injectCSS() {
252 for (var _len3 = arguments.length, loader = Array(_len3), _key3 = 0; _key3 < _len3; _key3++) {
253 loader[_key3] = arguments[_key3];
254 }
255
256 return normalizeLoader([injectStyleLoader].concat(loader)).split('!');
257};
258
259var extractCSS = exports.extractCSS = function extractCSS() {
260 for (var _len4 = arguments.length, loader = Array(_len4), _key4 = 0; _key4 < _len4; _key4++) {
261 loader[_key4] = arguments[_key4];
262 }
263
264 return extractCSSPlugin.extract(normalizeLoader(injectStyleLoader), normalizeLoader(loader)).split('!');
265};
266//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9Vc2Vycy9hbmRyZXlwb3BwL1dvcmtzcGFjZS9zaXRlZ2VuL3NyYy9jb25maWcuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7Ozs7Ozs7Ozs7Ozs7OztRQWlCZ0IsYSxHQUFBLGE7UUF1Q0EsVyxHQUFBLFc7UUE0Q0EsYSxHQUFBLGE7UUFLQSxNLEdBQUEsTTtRQWtFQSxnQixHQUFBLGdCO1FBZ0JBLGMsR0FBQSxjOztBQXZMaEI7Ozs7QUFDQ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