From 13efd50d8042a3ddae60851dab8c9c87fdd9c794 Mon Sep 17 00:00:00 2001 From: Book Pauk Date: Sun, 9 Feb 2020 16:43:36 +0700 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=83=D0=BD=D0=B8=D0=B2=D0=B5=D1=80=D1=81=D0=B0=D0=BB?= =?UTF-8?q?=D1=8C=D0=BD=D1=8B=D0=B9=20includer=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D0=B2=D0=BA=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D1=84?= =?UTF-8?q?=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20=D0=B2=20=D0=B8=D1=81=D1=85?= =?UTF-8?q?=D0=BE=D0=B4=D0=BD=D0=B8=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build/includer.js | 20 ++++++++++++++++++++ build/webpack.base.config.js | 5 +++++ 2 files changed, 25 insertions(+) create mode 100644 build/includer.js 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',