Skip to content

Commit a2bd75a

Browse files
stylesuxxsthzg
authored andcommitted
V4 -- Updates to support PostCSS installation
* Updated tessts to successfully run against current master of the template * Updated postcss attachement to new webpack config. Adjusted tests. * Updated dependencies * Use newest template * Updated Esprima
1 parent b581e5b commit a2bd75a

File tree

3 files changed

+48
-32
lines changed

3 files changed

+48
-32
lines changed

Diff for: generators/app/postcss.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,22 @@ module.exports = {
3939
const postcss = postcssAst.body[0].declarations[0].init.properties[0];
4040

4141
// The postcss loader item to add
42-
const postcssLoader = { type: 'Literal', value: 'postcss', raw: '\'postcss\'' };
42+
const postcssLoaderObject = 'var postcss = [{ loader: \'postcss-loader\'}]';
43+
const postcssLoaderAst = esprima.parse(postcssLoaderObject);
44+
const postcssLoader = postcssLoaderAst.body[0].declarations[0].init.elements[0];
45+
4346

4447
// Add postcss to the loaders array
4548
walk.walkAddParent(ast, (node) => {
4649

50+
4751
// Add the postcss key to the global configuration
52+
4853
if(
4954
node.type === 'MethodDefinition' &&
5055
node.key.name === 'defaultSettings'
5156
) {
52-
const returnStatement = node.value.body.body[0];
57+
const returnStatement = node.value.body.body[1];
5358
returnStatement.argument.properties.push(postcss);
5459
}
5560

@@ -64,13 +69,12 @@ module.exports = {
6469

6570
// Regular css usage
6671
if(cssDialects.indexOf(node.value.regex.pattern) !== -1) {
67-
6872
const loaderData = node.parent.properties[1];
6973
loaderData.value.elements.push(postcssLoader);
7074
}
7175

72-
if(preprocessorDialects.indexOf(node.value.regex.pattern) !== -1) {
7376

77+
if(preprocessorDialects.indexOf(node.value.regex.pattern) !== -1) {
7478
const loaderData = node.parent.properties[1];
7579
const lastElm = loaderData.value.elements.pop();
7680
loaderData.value.elements.push(postcssLoader);

Diff for: package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@
4848
},
4949
"dependencies": {
5050
"escodegen": "^1.7.0",
51-
"esprima": "^2.7.0",
51+
"esprima": "^3.1.1",
5252
"esprima-walk": "^0.1.0",
53-
"react-webpack-template": "^2.0.1-0",
53+
"react-webpack-template": "^2.0.1-5",
5454
"underscore.string": "^3.2.2",
5555
"yeoman-generator": "^0.24.0",
5656
"yeoman-welcome": "^1.0.1"

Diff for: test/generators/app/indexTest.js

+38-26
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ describe('react-webpack:app', () => {
101101

102102
assert.file([
103103
'src/actions/README.md',
104-
'src/index.js',
104+
'src/client.js',
105105
'src/components/App.js',
106106
'src/components/app.css',
107-
'src/favicon.ico',
107+
'src/static/favicon.ico',
108108
'src/images/yeoman.png',
109109
'src/index.html',
110110
'src/sources/README.md',
@@ -226,28 +226,40 @@ describe('react-webpack:app with PostCSS support', () => {
226226
});
227227

228228
it('should insert the postcss loader into the style pipes', () => {
229-
assert.fileContent('conf/webpack/Base.js', `'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
230-
'postcss'`);
231-
assert.fileContent('conf/webpack/Base.js', `'css',
232-
'postcss'`);
233-
assert.fileContent('conf/webpack/Base.js', `'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
234-
'postcss',
235-
'sass'`);
236-
assert.fileContent('conf/webpack/Base.js', `'css',
237-
'postcss',
238-
'sass'`);
239-
assert.fileContent('conf/webpack/Base.js', `'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
240-
'postcss',
241-
'less'`);
242-
assert.fileContent('conf/webpack/Base.js', `'css',
243-
'postcss',
244-
'less'`);
245-
assert.fileContent('conf/webpack/Base.js', `'css?modules&importLoaders=1&localIdentName=[name]-[local]-[hash:base64:5]',
246-
'postcss',
247-
'stylus'`);
248-
assert.fileContent('conf/webpack/Base.js', `'css',
249-
'postcss',
250-
'stylus'`);
229+
assert.fileContent('conf/webpack/Base.js', `{
230+
loader: 'css-loader',
231+
query: cssModulesQuery
232+
},
233+
{ loader: 'postcss-loader' }`);
234+
assert.fileContent('conf/webpack/Base.js', `{ loader: 'css-loader' },
235+
{ loader: 'postcss-loader' }`);
236+
assert.fileContent('conf/webpack/Base.js', `{
237+
loader: 'css-loader',
238+
query: cssModulesQuery
239+
},
240+
{ loader: 'postcss-loader' },
241+
{ loader: 'sass-loader' }`);
242+
assert.fileContent('conf/webpack/Base.js', `{ loader: 'css-loader' },
243+
{ loader: 'postcss-loader' },
244+
{ loader: 'sass-loader' }`);
245+
assert.fileContent('conf/webpack/Base.js', `{
246+
loader: 'css-loader',
247+
query: cssModulesQuery
248+
},
249+
{ loader: 'postcss-loader' },
250+
{ loader: 'less-loader' }`);
251+
assert.fileContent('conf/webpack/Base.js', `{ loader: 'css-loader' },
252+
{ loader: 'postcss-loader' },
253+
{ loader: 'less-loader' }`);
254+
assert.fileContent('conf/webpack/Base.js', `{
255+
loader: 'css-loader',
256+
query: cssModulesQuery
257+
},
258+
{ loader: 'postcss-loader' },
259+
{ loader: 'stylus-loader' }`);
260+
assert.fileContent('conf/webpack/Base.js', `{ loader: 'css-loader' },
261+
{ loader: 'postcss-loader' },
262+
{ loader: 'stylus-loader' }`);
251263
});
252264

253265
it('should append the postcss function to the base config', () => {
@@ -259,10 +271,10 @@ describe('react-webpack:app with PostCSS support', () => {
259271

260272
assert.file([
261273
'src/actions/README.md',
262-
'src/index.js',
274+
'src/client.js',
263275
'src/components/App.js',
264276
'src/components/app.css',
265-
'src/favicon.ico',
277+
'src/static/favicon.ico',
266278
'src/images/yeoman.png',
267279
'src/index.html',
268280
'src/sources/README.md',

0 commit comments

Comments
 (0)