')
+ .replace('', '')
+ }
+};
+
+const md = require('markdown-it')('default', {
+ html: true,
+ breaks: true,
+ highlight: renderHighlight,
+})
+md.use(require('markdown-it-anchor'), {
+ level: 2,
+ slugify: slugify,
+ permalink: true,
+ permalinkBefore: true,
+}).use(require('markdown-it-container'), 'demo', {
+
+ validate: function (params) {
+ return params.trim().match(/^demo\s*(.*)$/)
+ },
+ render: function (tokens, idx) {
+ if (tokens[idx].nesting === 1) {
+ const summaryContent = tokens[idx + 1].content
+ const summary = fetch(summaryContent, 'summary')
+ const summaryHTML = summary ? md.render(summary) : ''
+
+ const content = tokens[idx + 2].content
+ const html = fetch(content, 'template')
+ const script = fetch(content, 'script') || ''
+ const style = fetch(content, 'style') || ''
+ const code = tokens[idx + 2].markup + tokens[idx + 2].info + '\n' + content + tokens[idx + 2].markup
+ const codeHtml = code ? md.render(code) : ''
+
+ let jsfiddle = { html: html, script: script, style: style }
+ jsfiddle = md.utils.escapeHtml(JSON.stringify(jsfiddle))
+ // opening tag
+ return `
+
+ ${html}
+ ${summaryHTML}
+ ${codeHtml}
+
+
+
+
+ `
+ } else {
+ return '\n'
+ }
+ },
+})
+md.renderer.rules.table_open = function () {
+ return '
'
+}
+md.renderer.rules.fence = wrap(md.renderer.rules.fence)
+
+module.exports = {
+ entry: {
+ index: [
+ './examples/index.js',
+ ],
+ },
+ module: {
+ rules: [
+ {
+ test: /\.md/,
+ use: [
+ {
+ loader: 'vue-markdown-loader',
+ options: Object.assign(md, { wrapper: 'section', preventExtract: true }),
+ },
+ ],
+ },
+ {
+ test: /\.vue$/,
+ loader: 'vue-loader',
+ },
+ {
+ test: /\.js$/,
+ loader: 'babel-loader', exclude: /node_modules/,
+ },
+ {
+ test: /\.(png|jpg|gif|svg)$/,
+ loader: 'file-loader',
+ options: {
+ name: '[name].[ext]?[hash]',
+ },
+ },
+ ],
+ },
+ resolve: {
+ extensions: ['.js', '.vue'],
+ alias: {
+ 'vue$': 'vue/dist/vue.esm.js',
+ 'antd': path.join(__dirname, 'components'),
+ },
+ },
+}
diff --git a/webpack.config.js b/webpack.config.js
index 0bc6addc2..ab71254d6 100644
--- a/webpack.config.js
+++ b/webpack.config.js
@@ -1,13 +1,10 @@
const path = require('path')
// const webpack = require('webpack')
const HtmlWebpackPlugin = require('html-webpack-plugin')
+const merge = require('webpack-merge')
+const baseWebpackConfig = require('./webpack.base.config')
-module.exports = {
- entry: {
- index: [
- './examples/index.js',
- ],
- },
+module.exports = merge(baseWebpackConfig, {
output: {
path: path.resolve(__dirname, './dist'),
publicPath: '/',
@@ -15,21 +12,6 @@ module.exports = {
},
module: {
rules: [
- {
- test: /\.vue$/,
- loader: 'vue-loader',
- },
- {
- test: /\.js$/,
- loader: 'babel-loader', exclude: /node_modules/,
- },
- {
- test: /\.(png|jpg|gif|svg)$/,
- loader: 'file-loader',
- options: {
- name: '[name].[ext]?[hash]',
- },
- },
{
test: /\.less$/,
use: [
@@ -43,15 +25,15 @@ module.exports = {
},
],
},
+ {
+ test: /\.css$/,
+ use: [
+ 'style-loader',
+ 'css-loader',
+ ],
+ },
],
},
- resolve: {
- extensions: ['.js', '.vue'],
- alias: {
- 'vue$': 'vue/dist/vue.esm.js',
- 'antd': path.join(__dirname, 'components'),
- },
- },
devServer: {
port: 3000,
historyApiFallback: {
@@ -66,12 +48,11 @@ module.exports = {
hints: false,
},
devtool: '#source-map',
-}
-
-module.exports.plugins = (module.exports.plugins || []).concat([
- new HtmlWebpackPlugin({
- template: 'examples/index.html',
- filename: 'index.html',
- inject: true,
- }),
-])
+ plugins: [
+ new HtmlWebpackPlugin({
+ template: 'examples/index.html',
+ filename: 'index.html',
+ inject: true,
+ }),
+ ],
+})
diff --git a/webpack.prod.config.js b/webpack.prod.config.js
index 4c23f740c..1f4c8cd9f 100644
--- a/webpack.prod.config.js
+++ b/webpack.prod.config.js
@@ -3,18 +3,15 @@ const webpack = require('webpack')
const ExtractTextPlugin = require('extract-text-webpack-plugin')
const WebpackChunkHash = require('webpack-chunk-hash')
const HtmlWebpackPlugin = require('html-webpack-plugin')
+const merge = require('webpack-merge')
+const baseWebpackConfig = require('./webpack.base.config')
const modulePlugin = new ExtractTextPlugin({
filename: '[name].[chunkhash].css',
allChunks: true,
})
-module.exports = {
- entry: {
- index: [
- './examples/index.js',
- ],
- },
+module.exports = merge(baseWebpackConfig, {
output: {
path: path.resolve(__dirname, './dist'),
publicPath: './',
@@ -23,21 +20,6 @@ module.exports = {
},
module: {
rules: [
- {
- test: /\.vue$/,
- loader: 'vue-loader',
- },
- {
- test: /\.js$/,
- loader: 'babel-loader', exclude: /node_modules/,
- },
- {
- test: /\.(png|jpg|gif|svg)$/,
- loader: 'file-loader',
- options: {
- name: '[name].[ext]?[hash]',
- },
- },
{
test: /\.less$/,
use: modulePlugin.extract({
@@ -51,47 +33,50 @@ module.exports = {
],
}),
},
+ {
+ test: /\.css$/,
+ use: modulePlugin.extract({
+ fallback: 'style-loader',
+ use: [
+ {
+ loader: 'css-loader',
+ },
+ ],
+ }),
+ },
],
},
- resolve: {
- extensions: ['.js', '.vue'],
- alias: {
- 'vue$': 'vue/dist/vue.esm.js',
- 'antd': path.join(__dirname, 'components'),
- },
- },
-}
-// http://vue-loader.vuejs.org/en/workflow/production.html
-module.exports.plugins = (module.exports.plugins || []).concat([
- new webpack.DefinePlugin({
- 'process.env': {
- NODE_ENV: '"production"',
- },
- }),
- new webpack.optimize.CommonsChunkPlugin({
- name: 'manifest',
- minChunks: Infinity,
- }),
- new webpack.optimize.CommonsChunkPlugin({
- name: 'vender',
- minChunks: function (module) {
- return module.context && ~module.context.indexOf('node_modules')
- },
- }),
- new webpack.optimize.UglifyJsPlugin({
- compress: {
- warnings: false,
- },
- }),
- new HtmlWebpackPlugin({
- template: './examples/index.html',
- inject: true,
- minify: { collapseWhitespace: true },
- production: true,
- }),
- new webpack.LoaderOptionsPlugin({
- minimize: true,
- }),
- modulePlugin,
- new WebpackChunkHash({ algorithm: 'md5' }),
-])
+ plugins: [
+ new webpack.DefinePlugin({
+ 'process.env': {
+ NODE_ENV: '"production"',
+ },
+ }),
+ new webpack.optimize.CommonsChunkPlugin({
+ name: 'manifest',
+ minChunks: Infinity,
+ }),
+ new webpack.optimize.CommonsChunkPlugin({
+ name: 'vender',
+ minChunks: function (module) {
+ return module.context && ~module.context.indexOf('node_modules')
+ },
+ }),
+ new webpack.optimize.UglifyJsPlugin({
+ compress: {
+ warnings: false,
+ },
+ }),
+ new HtmlWebpackPlugin({
+ template: './examples/index.html',
+ inject: true,
+ minify: { collapseWhitespace: true },
+ production: true,
+ }),
+ new webpack.LoaderOptionsPlugin({
+ minimize: true,
+ }),
+ modulePlugin,
+ new WebpackChunkHash({ algorithm: 'md5' }),
+ ],
+})