Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4,963 changes: 4,258 additions & 705 deletions package-lock.json

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
{
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,ts,tsx}": [
"prettier-standard",
"git add"
]
},
"scripts": {
"test": "lerna run test",
"test": "npm run format && lerna run test",
"format": "prettier-standard 'packages/**/*.{js,ts,tsx}'",
"postinstall": "lerna bootstrap && link-parent-bin"
},
"devDependencies": {
"ava": "^0.22.0",
"husky": "^0.14.3",
"lerna": "2.0.0-beta.30",
"link-parent-bin": "^0.1.3",
"standard": "^10.0.3"
"lint-staged": "^7.0.2",
"prettier-standard": "^8.0.0"
}
}
36 changes: 19 additions & 17 deletions packages/assets/__tests__/css-modules.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { createConfig, match } from '@webpack-blocks/core'
import { css } from '../lib/index'

test('css.modules() works', t => {
const config = createConfig({}, [
css.modules()
])
const config = createConfig({}, [css.modules()])

t.deepEqual(config.module.rules, [
{
Expand All @@ -14,7 +12,8 @@ test('css.modules() works', t => {
{
loader: 'style-loader',
options: {}
}, {
},
{
loader: 'css-loader',
options: {
importLoaders: 1,
Expand Down Expand Up @@ -44,7 +43,8 @@ test('css.modules() works with options and match()', t => {
{
loader: 'style-loader',
options: {}
}, {
},
{
loader: 'css-loader',
options: {
importLoaders: 1,
Expand All @@ -70,19 +70,21 @@ test('style-loader can take options', t => {
t.deepEqual(config.module.rules, [
{
test: /\.css$/,
use: [{
loader: 'style-loader',
options: {
hmr: true
}
}, {
loader: 'css-loader',
options: {
importLoaders: 1,
localIdentName: '[name]--[local]--[hash:base64:5]',
modules: true
use: [
{
loader: 'style-loader',
options: {
hmr: true
}
},
{
loader: 'css-loader',
options: {
importLoaders: 1,
localIdentName: '[name]--[local]--[hash:base64:5]',
modules: true
}
}
}
]
}
])
Expand Down
38 changes: 20 additions & 18 deletions packages/assets/__tests__/css.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { createConfig, match } from '@webpack-blocks/core'
import { css } from '../lib/index'

test('css() works', t => {
const config = createConfig({}, [
css()
])
const config = createConfig({}, [css()])

t.deepEqual(config.module.rules, [
{
Expand All @@ -14,7 +12,8 @@ test('css() works', t => {
{
loader: 'style-loader',
options: {}
}, {
},
{
loader: 'css-loader',
options: {}
}
Expand All @@ -40,7 +39,8 @@ test('css() works with options and match()', t => {
{
loader: 'style-loader',
options: {}
}, {
},
{
loader: 'css-loader',
options: {
minimize: true
Expand All @@ -63,15 +63,17 @@ test('style-loader can take options', t => {
t.deepEqual(config.module.rules, [
{
test: /\.css$/,
use: [{
loader: 'style-loader',
options: {
hmr: true
use: [
{
loader: 'style-loader',
options: {
hmr: true
}
},
{
loader: 'css-loader',
options: {}
}
}, {
loader: 'css-loader',
options: {}
}
]
}
])
Expand All @@ -98,9 +100,7 @@ test('style-loader can be disabled', t => {
})

test('deprecated css(<fileType>) still works', t => {
const config = createConfig({}, [
css('text/x-sass')
])
const config = createConfig({}, [css('text/x-sass')])

t.deepEqual(config.module.rules, [
{
Expand All @@ -109,7 +109,8 @@ test('deprecated css(<fileType>) still works', t => {
{
loader: 'style-loader',
options: {}
}, {
},
{
loader: 'css-loader',
options: {}
}
Expand All @@ -131,7 +132,8 @@ test('deprecated css(<fileType>, { exclude }) still works', t => {
{
loader: 'style-loader',
options: {}
}, {
},
{
loader: 'css-loader',
options: {}
}
Expand Down
14 changes: 3 additions & 11 deletions packages/assets/__tests__/file.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { createConfig, match } from '@webpack-blocks/core'
import { file } from '../lib/index'

test('file() works with match', t => {
const config = createConfig({}, [
match('*.jpg', [
file()
])
])
const config = createConfig({}, [match('*.jpg', [file()])])

t.deepEqual(config.module.rules, [
{
Expand Down Expand Up @@ -48,9 +44,7 @@ test('file() works with options and match()', t => {
})

test('deprecated file(<fileType>) still works', t => {
const config = createConfig({}, [
file('image')
])
const config = createConfig({}, [file('image')])

t.deepEqual(config.module.rules, [
{
Expand All @@ -66,9 +60,7 @@ test('deprecated file(<fileType>) still works', t => {
})

test('deprecated file(<fileType>, { exclude }) still works', t => {
const config = createConfig({}, [
file('image', { exclude: /node_modules/ })
])
const config = createConfig({}, [file('image', { exclude: /node_modules/ })])

t.deepEqual(config.module.rules, [
{
Expand Down
14 changes: 3 additions & 11 deletions packages/assets/__tests__/url.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@ import { createConfig, match } from '@webpack-blocks/core'
import { url } from '../lib/index'

test('url() works with match', t => {
const config = createConfig({}, [
match('*.jpg', [
url()
])
])
const config = createConfig({}, [match('*.jpg', [url()])])

t.deepEqual(config.module.rules, [
{
Expand Down Expand Up @@ -48,9 +44,7 @@ test('url() works with options and match()', t => {
})

test('deprecated url(<fileType>) still works', t => {
const config = createConfig({}, [
url('image')
])
const config = createConfig({}, [url('image')])

t.deepEqual(config.module.rules, [
{
Expand All @@ -66,9 +60,7 @@ test('deprecated url(<fileType>) still works', t => {
})

test('deprecated url(<fileType>, { exclude }) still works', t => {
const config = createConfig({}, [
url('image', { exclude: /node_modules/ })
])
const config = createConfig({}, [url('image', { exclude: /node_modules/ })])

t.deepEqual(config.module.rules, [
{
Expand Down
84 changes: 54 additions & 30 deletions packages/assets/lib/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,42 @@ module.exports.modules = cssModules
* @see https://github.com/webpack-contrib/css-loader
*/
function css (fileType, options = {}) {
if (fileType && typeof fileType === 'object' && Object.keys(options).length === 0) {
if (
fileType &&
typeof fileType === 'object' &&
Object.keys(options).length === 0
) {
options = fileType
fileType = null
}
if (fileType || options.exclude || options.include) {
console.warn(`css(): You are using the deprecated 'fileType' parameter, 'options.exclude' or 'options.include'. Use match() instead.`)
console.warn(
`css(): You are using the deprecated 'fileType' parameter, 'options.exclude' or 'options.include'. Use match() instead.`
)
}

const cssOptions = _.omit(options, ['exclude', 'include', 'styleLoader'])
const loaders = [{ loader: 'css-loader', options: cssOptions }]

if (options.styleLoader !== false) {
loaders.unshift({ loader: 'style-loader', options: options.styleLoader || {} })
loaders.unshift({
loader: 'style-loader',
options: options.styleLoader || {}
})
}

return (context, util) => util.addLoader(
Object.assign(
{
test: /\.css$/,
use: loaders
},
// for API backwards compatibility only
synthesizeMatch(context.fileType(fileType || 'text/css'), options),
context.match
return (context, util) =>
util.addLoader(
Object.assign(
{
test: /\.css$/,
use: loaders
},
// for API backwards compatibility only
synthesizeMatch(context.fileType(fileType || 'text/css'), options),
context.match
)
)
)
}

/**
Expand All @@ -50,37 +60,51 @@ function css (fileType, options = {}) {
* @see https://github.com/webpack-contrib/css-loader
*/
function cssModules (fileType, options = {}) {
if (fileType && typeof fileType === 'object' && Object.keys(options).length === 0) {
if (
fileType &&
typeof fileType === 'object' &&
Object.keys(options).length === 0
) {
options = fileType
fileType = null
}
if (fileType || options.exclude || options.include) {
console.warn(`css.modules(): You are using the deprecated 'fileType' parameter, 'options.exclude' or 'options.include'. Use match() instead.`)
console.warn(
`css.modules(): You are using the deprecated 'fileType' parameter, 'options.exclude' or 'options.include'. Use match() instead.`
)
}

const defaultCssOptions = {
modules: true,
importLoaders: 1,
localIdentName: String(process.env.NODE_ENV) === 'production'
? '[hash:base64:10]'
: '[name]--[local]--[hash:base64:5]'
localIdentName:
String(process.env.NODE_ENV) === 'production'
? '[hash:base64:10]'
: '[name]--[local]--[hash:base64:5]'
}
const cssOptions = Object.assign(defaultCssOptions, _.omit(options, ['exclude', 'include', 'styleLoader']))
const cssOptions = Object.assign(
defaultCssOptions,
_.omit(options, ['exclude', 'include', 'styleLoader'])
)
const loaders = [{ loader: 'css-loader', options: cssOptions }]

if (options.styleLoader !== false) {
loaders.unshift({ loader: 'style-loader', options: options.styleLoader || {} })
loaders.unshift({
loader: 'style-loader',
options: options.styleLoader || {}
})
}

return (context, util) => util.addLoader(
Object.assign(
{
test: /\.css$/,
use: loaders
},
// for API backwards compatibility only
synthesizeMatch(context.fileType(fileType || 'text/css'), options),
context.match
return (context, util) =>
util.addLoader(
Object.assign(
{
test: /\.css$/,
use: loaders
},
// for API backwards compatibility only
synthesizeMatch(context.fileType(fileType || 'text/css'), options),
context.match
)
)
)
}
Loading