String
+PostHTML Loader
+
+**Kind**: global function
+**Returns**: String
- html HTML
+**Requires**: module:loader-utils
, module:schema-utils
, module:posthtml
, module:posthtml-load-config
+**Version**: 1.0.0
+**Author**: Michael Ciniawsky String
| HTML |
+
diff --git a/README.md b/README.md
index 9657289..2abc27e 100644
--- a/README.md
+++ b/README.md
@@ -1,112 +1,244 @@
-# PostHTML Loader
+ ![]() + Michael Ciniawsky + |
+
+ ![]() + Ivan Demidov + |
+
{{ foo }}
diff --git a/test/fixtures/options/config/posthtml.config.js b/test/fixtures/options/config/posthtml.config.js new file mode 100644 index 0000000..52eec8c --- /dev/null +++ b/test/fixtures/options/config/posthtml.config.js @@ -0,0 +1,7 @@ +module.exports = (ctx) => ({ + to: 'delete.html', + from: 'delete.html', + plugins: [ + ctx.options.plugin ? require('../../plugin')() : false + ] +}) diff --git a/test/fixtures/options/parser/fixture.js b/test/fixtures/options/parser/fixture.js new file mode 100644 index 0000000..fc67d60 --- /dev/null +++ b/test/fixtures/options/parser/fixture.js @@ -0,0 +1 @@ +import html from './fixture.ssml' diff --git a/test/fixtures/options/parser/fixture.ssml b/test/fixtures/options/parser/fixture.ssml new file mode 100644 index 0000000..e115573 --- /dev/null +++ b/test/fixtures/options/parser/fixture.ssml @@ -0,0 +1 @@ +div Hello diff --git a/test/fixtures/plugin.js b/test/fixtures/plugin.js new file mode 100644 index 0000000..6896202 --- /dev/null +++ b/test/fixtures/plugin.js @@ -0,0 +1,15 @@ +'use strict' + +module.exports = function plugin (options) { + options = Object.assign({}, options) + + return function (tree) { + tree.walk((node) => { + if (node.tag === 'div') node.tag = 'section' + + return node + }) + + return tree + } +} diff --git a/test/fixtures/posthtml.config.js b/test/fixtures/posthtml.config.js new file mode 100644 index 0000000..e2b0f4b --- /dev/null +++ b/test/fixtures/posthtml.config.js @@ -0,0 +1,5 @@ +module.exports = { + plugins: [ + require('./plugin')() + ] +} diff --git a/test/helpers/compiler.js b/test/helpers/compiler.js new file mode 100644 index 0000000..9add1dd --- /dev/null +++ b/test/helpers/compiler.js @@ -0,0 +1,67 @@ +'use strict' + +const path = require('path') +const del = require('del') +const webpack = require('webpack') +const MemoryFS = require('memory-fs') + +const modules = (config) => { + return { + rules: config.rules + ? config.rules + : config.loader + ? [ + { + test: config.loader.test || /\.txt$/, + use: { + loader: path.resolve(__dirname, '../../lib'), + options: config.loader.options || {} + } + } + ] + : [] + } +} + +const plugins = config => ([ + new webpack.optimize.CommonsChunkPlugin({ + names: ['runtime'], + minChunks: Infinity + }) +].concat(config.plugins || [])) + +const output = (config) => { + return { + path: path.resolve( + __dirname, + `../outputs/${config.output ? config.output : ''}` + ), + filename: '[name].js', + chunkFilename: '[name].chunk.js' + } +} + +module.exports = function (fixture, config, options) { + config = { + devtool: config.devtool || 'sourcemap', + context: path.resolve(__dirname, '..', 'fixtures'), + entry: `./${fixture}`, + output: output(config), + module: modules(config), + plugins: plugins(config) + } + + options = Object.assign({ output: false }, options) + + if (options.output) del.sync(config.output.path) + + const compiler = webpack(config) + + if (!options.output) compiler.outputFileSystem = new MemoryFS() + + return new Promise((resolve, reject) => compiler.run((err, stats) => { + if (err) reject(err) + + resolve(stats) + })) +} diff --git a/test/index.js b/test/index.js deleted file mode 100644 index 4ec629e..0000000 --- a/test/index.js +++ /dev/null @@ -1,89 +0,0 @@ -const test = require('ava') -const webpack = require('webpack') -const path = require('path') -const fs = require('fs') -const node = require('when/node') -const customElements = require('posthtml-custom-elements') -const exp = require('posthtml-exp') -const sugarml = require('sugarml') -const fixtures = path.join(__dirname, 'fixtures') - -test('basic', (t) => { - return webpackCompile('basic', [customElements()]) - .then(({outputPath, src}) => { - t.truthy(src.match(/