Skip to content

Commit 6dc6132

Browse files
authored
Merge pull request #179 from ant-tool/feat-theme
support theme config, Close #176
2 parents c86bbf4 + 11eb491 commit 6dc6132

File tree

9 files changed

+148
-4
lines changed

9 files changed

+148
-4
lines changed

src/getWebpackCommonConfig.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ExtractTextPlugin from 'extract-text-webpack-plugin';
33
import getBabelCommonConfig from './getBabelCommonConfig';
44
import getTSCommonConfig from './getTSCommonConfig';
55
import { existsSync } from 'fs';
6-
import { join } from 'path';
6+
import { join, resolve } from 'path';
77
import rucksack from 'rucksack-css';
88
import autoprefixer from 'autoprefixer';
99

@@ -17,8 +17,17 @@ export default function getWebpackCommonConfig(args) {
1717

1818
const babelQuery = getBabelCommonConfig();
1919
const tsQuery = getTSCommonConfig();
20-
2120
tsQuery.declaration = false;
21+
22+
let theme = {};
23+
if (pkg.theme && typeof(pkg.theme) === 'string' && existsSync(pkg.theme)) {
24+
const cfgPath = resolve(pkg.theme);
25+
const getThemeConfig = require(cfgPath);
26+
theme = getThemeConfig();
27+
} else if (pkg.theme && typeof(pkg.theme) === 'object') {
28+
theme = pkg.theme;
29+
}
30+
2231
const emptyBuildins = [
2332
'child_process',
2433
'cluster',
@@ -111,15 +120,15 @@ export default function getWebpackCommonConfig(args) {
111120
loader: ExtractTextPlugin.extract(
112121
'css?sourceMap!' +
113122
'postcss!' +
114-
`less-loader?{"sourceMap":true,"modifyVars":${JSON.stringify(pkg.theme || {})}}`
123+
`less-loader?{"sourceMap":true,"modifyVars":${JSON.stringify(theme)}}`
115124
),
116125
},
117126
{
118127
test: /\.module\.less$/,
119128
loader: ExtractTextPlugin.extract(
120129
'css?sourceMap&modules&localIdentName=[local]___[hash:base64:5]!!' +
121130
'postcss!' +
122-
`less-loader?{"sourceMap":true,"modifyVars":${JSON.stringify(pkg.theme || {})}}`
131+
`less-loader?{"sourceMap":true,"modifyVars":${JSON.stringify(theme)}}`
123132
),
124133
},
125134
{ test: /\.woff(\?v=\d+\.\d+\.\d+)?$/, loader: 'url?limit=10000&minetype=application/font-woff' },

test/build-test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,7 @@ describe('lib/build', function () {
9191
it('should support typescript', () => {
9292
return testBuild({}, 'build-typescript');
9393
});
94+
it('should support theme', () => {
95+
return testBuild({}, 'build-theme');
96+
});
9497
});

test/expect/build-theme/common.js

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/******/ (function(modules) { // webpackBootstrap
2+
/******/ // install a JSONP callback for chunk loading
3+
/******/ var parentJsonpFunction = window["webpackJsonp"];
4+
/******/ window["webpackJsonp"] = function webpackJsonpCallback(chunkIds, moreModules) {
5+
/******/ // add "moreModules" to the modules object,
6+
/******/ // then flag all "chunkIds" as loaded and fire callback
7+
/******/ var moduleId, chunkId, i = 0, callbacks = [];
8+
/******/ for(;i < chunkIds.length; i++) {
9+
/******/ chunkId = chunkIds[i];
10+
/******/ if(installedChunks[chunkId])
11+
/******/ callbacks.push.apply(callbacks, installedChunks[chunkId]);
12+
/******/ installedChunks[chunkId] = 0;
13+
/******/ }
14+
/******/ for(moduleId in moreModules) {
15+
/******/ modules[moduleId] = moreModules[moduleId];
16+
/******/ }
17+
/******/ if(parentJsonpFunction) parentJsonpFunction(chunkIds, moreModules);
18+
/******/ while(callbacks.length)
19+
/******/ callbacks.shift().call(null, __webpack_require__);
20+
/******/ if(moreModules[0]) {
21+
/******/ installedModules[0] = 0;
22+
/******/ return __webpack_require__(0);
23+
/******/ }
24+
/******/ };
25+
26+
/******/ // The module cache
27+
/******/ var installedModules = {};
28+
29+
/******/ // object to store loaded and loading chunks
30+
/******/ // "0" means "already loaded"
31+
/******/ // Array means "loading", array contains callbacks
32+
/******/ var installedChunks = {
33+
/******/ 0:0
34+
/******/ };
35+
36+
/******/ // The require function
37+
/******/ function __webpack_require__(moduleId) {
38+
39+
/******/ // Check if module is in cache
40+
/******/ if(installedModules[moduleId])
41+
/******/ return installedModules[moduleId].exports;
42+
43+
/******/ // Create a new module (and put it into the cache)
44+
/******/ var module = installedModules[moduleId] = {
45+
/******/ exports: {},
46+
/******/ id: moduleId,
47+
/******/ loaded: false
48+
/******/ };
49+
50+
/******/ // Execute the module function
51+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
52+
53+
/******/ // Flag the module as loaded
54+
/******/ module.loaded = true;
55+
56+
/******/ // Return the exports of the module
57+
/******/ return module.exports;
58+
/******/ }
59+
60+
/******/ // This file contains only the entry chunk.
61+
/******/ // The chunk loading function for additional chunks
62+
/******/ __webpack_require__.e = function requireEnsure(chunkId, callback) {
63+
/******/ // "0" is the signal for "already loaded"
64+
/******/ if(installedChunks[chunkId] === 0)
65+
/******/ return callback.call(null, __webpack_require__);
66+
67+
/******/ // an array means "currently loading".
68+
/******/ if(installedChunks[chunkId] !== undefined) {
69+
/******/ installedChunks[chunkId].push(callback);
70+
/******/ } else {
71+
/******/ // start chunk loading
72+
/******/ installedChunks[chunkId] = [callback];
73+
/******/ var head = document.getElementsByTagName('head')[0];
74+
/******/ var script = document.createElement('script');
75+
/******/ script.type = 'text/javascript';
76+
/******/ script.charset = 'utf-8';
77+
/******/ script.async = true;
78+
79+
/******/ script.src = __webpack_require__.p + "" + ({"1":"index"}[chunkId]||chunkId) + ".js";
80+
/******/ head.appendChild(script);
81+
/******/ }
82+
/******/ };
83+
84+
/******/ // expose the modules object (__webpack_modules__)
85+
/******/ __webpack_require__.m = modules;
86+
87+
/******/ // expose the module cache
88+
/******/ __webpack_require__.c = installedModules;
89+
90+
/******/ // __webpack_public_path__
91+
/******/ __webpack_require__.p = "";
92+
/******/ })
93+
/************************************************************************/
94+
/******/ ([]);

test/expect/build-theme/index.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
button {
2+
color: #333333;
3+
}

test/expect/build-theme/index.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
webpackJsonp([1,0],[
2+
/* 0 */
3+
/***/ function(module, exports, __webpack_require__) {
4+
5+
'use strict';
6+
7+
console.log(1);
8+
__webpack_require__(1);
9+
10+
/***/ },
11+
/* 1 */
12+
/***/ function(module, exports) {
13+
14+
// removed by extract-text-webpack-plugin
15+
16+
/***/ }
17+
]);
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = function() {
2+
return {
3+
'@buttonTxtColor': '#333333'
4+
};
5+
};

test/fixtures/build-theme/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log(1);
2+
require('./index.less');

test/fixtures/build-theme/index.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
@buttonTxtColor: #222222;
2+
3+
button {
4+
color: @buttonTxtColor;
5+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"entry": {
3+
"index": "./index.js"
4+
},
5+
"theme": "./antui-config.js"
6+
}

0 commit comments

Comments
 (0)