diff --git a/README.md b/README.md index cdeed9ba..a9a9cec4 100644 --- a/README.md +++ b/README.md @@ -160,6 +160,8 @@ Use a loader, currently built-in loaders are: - `stylus` (TODO) - `less` (TODO) +They are executed from right to left. + ### loaders Type: `Loader[]` diff --git a/src/loaders.js b/src/loaders.js index 41e48f00..ed51a59e 100644 --- a/src/loaders.js +++ b/src/loaders.js @@ -44,7 +44,15 @@ export default class Loaders { id, sourceMap } - return v => loader.process.call(loaderContext, v) + return v => { + // Only process if it's postcss loader + // Or passed `test` + if (name === 'postcss' || loader.test.test(id)) { + return loader.process.call(loaderContext, v) + } + // Otherwise directly return input value + return v + } }), { code, map }) } diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index f78255bc..4b4b05ee 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -433,6 +433,46 @@ console.log(css, css$1); " `; +exports[`skip-loader: js code 1`] = ` +"'use strict'; + +function __$styleInject(css, ref) { + if ( ref === void 0 ) ref = {}; + var insertAt = ref.insertAt; + + if (!css) { return } + + var head = document.head || document.getElementsByTagName('head')[0]; + var style = document.createElement('style'); + style.type = 'text/css'; + + if (insertAt === 'top') { + if (head.firstChild) { + head.insertBefore(style, head.firstChild); + } else { + head.appendChild(style); + } + } else { + head.appendChild(style); + } + + if (style.styleSheet) { + style.styleSheet.cssText = css; + } else { + style.appendChild(document.createTextNode(css)); + } +} + +var css = \\"body {\\\\n color: red;\\\\n}\\\\n\\"; +__$$styleInject(css); + +var css$1 = \\".bar {\\\\n color: red;\\\\n}\\\\n\\"; +__$$styleInject(css$1); + +console.log(css, css$1); +" +`; + exports[`sourcemap:inline: js code 1`] = ` "'use strict'; diff --git a/test/index.test.js b/test/index.test.js index 728d18f3..5e67d3b2 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -215,3 +215,20 @@ snapshot({ ] } }) + +snapshot({ + title: 'skip-loader', + input: 'simple/index.js', + options: { + use: ['loader'], + loaders: [ + { + name: 'loader', + test: /\.random$/, + process() { + return 'lol' + } + } + ] + } +})