diff --git a/build/includer.js b/build/includer.js new file mode 100644 index 00000000..b0b7998d --- /dev/null +++ b/build/includer.js @@ -0,0 +1,20 @@ +const path = require('path'); +const fs = require('fs'); + +exports.default = function includer(source) { + const lines = source.split('\n'); + + let result = []; + for (const line of lines) { + const trimmed = line.trim(); + const m = trimmed.match(/^@@[\s]*?include[\s]*?\(['"](.*)['"]\)/); + if (m) { + const includedFile = path.resolve(path.dirname(this.resourcePath), m[1]); + const fileContent = fs.readFileSync(includedFile, 'utf8'); + result.push(fileContent); + } else { + result.push(line); + } + } + return result.join('\n'); +} \ No newline at end of file diff --git a/build/webpack.base.config.js b/build/webpack.base.config.js index db7b4af7..e4e902f4 100644 --- a/build/webpack.base.config.js +++ b/build/webpack.base.config.js @@ -16,6 +16,11 @@ module.exports = { test: /\.vue$/, loader: "vue-loader" }, + { + test: /\.includer$/, + resourceQuery: /^\?vue/, + use: path.resolve('build/includer.js') + }, { test: /\.js$/, loader: 'babel-loader',