Skip to content

Commit c2a5798

Browse files
committedAug 8, 2019
fix: upgrade tailwind and remove log
1 parent 66b4360 commit c2a5798

File tree

6 files changed

+1152
-2315
lines changed

6 files changed

+1152
-2315
lines changed
 

‎lib/module.js

+14-19
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
const { join } = require('path')
22
const { ensureTemplateFile } = require('./utils')
3-
const logger = require('./logger')
43

54
module.exports = async function (moduleOptions) {
65
const options = {
@@ -10,7 +9,6 @@ module.exports = async function (moduleOptions) {
109
...moduleOptions
1110
}
1211

13-
const isBuild = this.options._build
1412
const configPath = this.nuxt.resolver.resolveAlias(options.configPath)
1513
const cssPath = this.nuxt.resolver.resolveAlias(options.cssPath)
1614

@@ -27,26 +25,23 @@ module.exports = async function (moduleOptions) {
2725
this.options.css.unshift(cssPath)
2826
}
2927

30-
/*
31-
** Set PostCSS config
32-
** It has to be set before `nuxt-purgecss`
33-
** only for `nuxt dev` and `nuxt build` commands
34-
*/
35-
if (isBuild) {
36-
logger.info('postcss-preset-env stage is set to 1 for supporting advanced css features')
28+
// This hooks is called only for `nuxt dev` and `nuxt build` commands
29+
this.nuxt.hook('build:before', async () => {
30+
/*
31+
** Set PostCSS config (before nuxt-purgecss)
32+
*/
3733
this.options.build.postcss.preset.stage = 1 // see https://tailwindcss.com/docs/using-with-preprocessors#future-css-features
3834
this.options.build.postcss.plugins = this.options.build.postcss.plugins || {}
3935
this.options.build.postcss.plugins.tailwindcss = this.options.build.postcss.plugins.tailwindcss || configPath
40-
}
41-
42-
/*
43-
** Add nuxt-purgecss module and set config
44-
** only for `nuxt build` command
45-
*/
46-
if (!this.options.dev && isBuild) {
47-
const purgeCSS = { mode: 'postcss', ...(this.options.purgeCSS || {}) }
48-
await this.requireModule(['nuxt-purgecss', purgeCSS])
49-
}
36+
/*
37+
** Add nuxt-purgecss module and set config
38+
** only for `nuxt build` command
39+
*/
40+
if (!this.options.dev) {
41+
const purgeCSS = { mode: 'postcss', ...(this.options.purgeCSS || {}) }
42+
await this.requireModule(['nuxt-purgecss', purgeCSS])
43+
}
44+
})
5045
}
5146

5247
module.exports.meta = require('../package.json')

‎lib/utils.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const { resolve } = require('path')
22
const { pathExists, copy } = require('fs-extra')
33
const logger = require('./logger')
44

5-
async function ensureTemplateFile(srcDir, from, to) {
5+
async function ensureTemplateFile (srcDir, from, to) {
66
const relativePath = to.replace(srcDir, '~')
77
const fileExists = await pathExists(to)
88

‎test/config.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ const { remove } = require('fs-extra')
55
const { Nuxt, Builder } = require('nuxt-edge')
66
const request = require('request-promise-native')
77
const getPort = require('get-port')
8+
const config = require('../example/nuxt.config')
89
const logger = require('@/logger')
910

10-
const config = require('../example/nuxt.config')
11+
logger.mockTypes(() => jest.fn())
12+
1113
config.dev = false
1214
config.tailwindcss = {
1315
configPath: 'custom/tailwind.js',
@@ -19,8 +21,6 @@ let nuxt, port
1921
const url = path => `http://localhost:${port}${path}`
2022
const get = path => request(url(path))
2123

22-
logger.mockTypes(() => jest.fn())
23-
2424
describe('config', () => {
2525
beforeAll(async () => {
2626
nuxt = new Nuxt(config)

‎test/fail.test.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ require('fs-extra').pathExists = jest.fn().mockImplementation(() => Promise.reso
33
require('fs-extra').copy = jest.fn().mockImplementation(() => Promise.reject(new Error('Error when copy')))
44

55
const { Nuxt, Builder } = require('nuxt-edge')
6+
const config = require('../example/nuxt.config')
67
const logger = require('@/logger')
78

8-
const config = require('../example/nuxt.config')
9+
logger.mockTypes(() => jest.fn())
10+
911
config.dev = false
1012

1113
let nuxt
1214

13-
logger.mockTypes(() => jest.fn())
14-
1515
describe('fail', () => {
1616
beforeAll(async () => {
1717
nuxt = new Nuxt(config)

‎test/ok.test.js

+3-5
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ const { join } = require('path')
44
const { Nuxt, Builder } = require('nuxt-edge')
55
const request = require('request-promise-native')
66
const getPort = require('get-port')
7+
const config = require('../example/nuxt.config')
78
const logger = require('@/logger')
89

9-
const config = require('../example/nuxt.config')
10+
logger.mockTypes(() => jest.fn())
11+
1012
config.dev = false
11-
config._build = true // imitate `nuxt build` comman
1213

1314
let nuxt, port
1415

1516
const url = path => `http://localhost:${port}${path}`
1617
const get = path => request(url(path))
1718

18-
logger.mockTypes(() => jest.fn())
19-
2019
describe('ok', () => {
2120
beforeAll(async () => {
2221
nuxt = new Nuxt(config)
@@ -46,7 +45,6 @@ describe('ok', () => {
4645
})
4746

4847
test('build', () => {
49-
expect(logger.info).toHaveBeenCalledWith('postcss-preset-env stage is set to 1 for supporting advanced css features')
5048
expect(nuxt.options.build.postcss.preset.stage).toBe(1)
5149
expect(nuxt.options.build.postcss.plugins).toBeDefined()
5250
expect(nuxt.options.build.postcss.plugins.tailwindcss).toBe(join(nuxt.options.srcDir, 'tailwind.config.js'))

‎yarn.lock

+1,128-2,284
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)
Please sign in to comment.