123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- const path = require('path');
- const webpack = require('webpack');
- const CopyWebpackPlugin = require('copy-webpack-plugin');
- const HtmlWebpackPlugin = require('html-webpack-plugin');
- const ExtractTextPlugin = require('extract-text-webpack-plugin');
- const ProgressBarPlugin = require('progress-bar-webpack-plugin');
- const md = require('markdown-it')();
- const slugify = require('transliteration').slugify;
- const striptags = require('./strip-tags');
- const config = require('./config');
- const isProd = process.env.NODE_ENV === 'production';
- const isDev = process.env.NODE_ENV === 'development';
- const isPlay = !!process.env.PLAY_ENV;
- function convert(str) {
- str = str.replace(/(&#x)(\w{4});/gi, function($0) {
- return String.fromCharCode(parseInt(encodeURIComponent($0).replace(/(%26%23x)(\w{4})(%3B)/g, '$2'), 16));
- });
- return str;
- }
- function wrap(render) {
- return function() {
- return render.apply(this, arguments)
- .replace('<code v-pre class="', '<code class="hljs ')
- .replace('<code>', '<code class="hljs">');
- };
- }
- const webpackConfig = {
- entry: isProd ? {
- docs: './examples/entry.js',
- 'element-ui': './src/index.js'
- } : (isPlay ? './examples/play.js' : './examples/entry.js'),
- output: {
- path: path.resolve(process.cwd(), './examples/element-ui/'),
- publicPath: process.env.CI_ENV || '',
- filename: '[name].[hash:7].js',
- chunkFilename: isProd ? '[name].[hash:7].js' : '[name].js'
- },
- resolve: {
- extensions: ['.js', '.vue', '.json'],
- alias: config.alias,
- modules: ['node_modules']
- },
- devServer: {
- host: '0.0.0.0',
- port: 8085,
- publicPath: '/',
- noInfo: true
- },
- module: {
- rules: [
- {
- enforce: 'pre',
- test: /\.jsx?$/,
- exclude: /node_modules|bower_components/,
- loader: 'eslint-loader'
- },
- {
- enforce: 'pre',
- test: /\.vue$/,
- exclude: /node_modules|bower_components/,
- loader: 'eslint-loader'
- },
- {
- test: /\.(jsx?|babel|es6)$/,
- include: process.cwd(),
- exclude: config.jsexclude,
- loader: 'babel-loader'
- },
- {
- test: /\.md$/,
- loader: 'vue-markdown-loader',
- options: {
- use: [
- [require('markdown-it-anchor'), {
- level: 2,
- slugify: slugify,
- permalink: true,
- permalinkBefore: true
- }],
- [require('markdown-it-container'), 'demo', {
- validate: function(params) {
- return params.trim().match(/^demo\s*(.*)$/);
- },
- render: function(tokens, idx) {
- var m = tokens[idx].info.trim().match(/^demo\s*(.*)$/);
- if (tokens[idx].nesting === 1) {
- var description = (m && m.length > 1) ? m[1] : '';
- var content = tokens[idx + 1].content;
- var html = convert(striptags.strip(content, ['script', 'style'])).replace(/(<[^>]*)=""(?=.*>)/g, '$1');
- var script = striptags.fetch(content, 'script');
- var style = striptags.fetch(content, 'style');
- var jsfiddle = { html: html, script: script, style: style };
- var descriptionHTML = description
- ? md.render(description)
- : '';
- jsfiddle = md.utils.escapeHtml(JSON.stringify(jsfiddle));
- return `<demo-block class="demo-box" :jsfiddle="${jsfiddle}">
- <div class="source" slot="source">${html}</div>
- ${descriptionHTML}
- <div class="highlight" slot="highlight">`;
- }
- return '</div></demo-block>\n';
- }
- }],
- [require('markdown-it-container'), 'tip'],
- [require('markdown-it-container'), 'warning']
- ],
- preprocess: function(MarkdownIt, source) {
- MarkdownIt.renderer.rules.table_open = function() {
- return '<table class="table">';
- };
- MarkdownIt.renderer.rules.fence = wrap(MarkdownIt.renderer.rules.fence);
- return source;
- }
- }
- },
- {
- test: /\.json$/,
- loader: 'json-loader'
- },
- {
- test: /\.scss$/,
- loaders: ['style-loader', 'css-loader', 'sass-loader']
- },
- {
- test: /\.html$/,
- loader: 'html-loader?minimize=false'
- },
- {
- test: /\.otf|ttf|woff2?|eot(\?\S*)?$/,
- loader: 'url-loader',
- query: {
- limit: 10000,
- name: path.posix.join('static', '[name].[hash:7].[ext]')
- }
- },
- {
- test: /\.svg(\?\S*)?$/,
- loader: 'url-loader',
- query: {
- limit: 10000,
- name: path.posix.join('static', '[name].[hash:7].[ext]')
- }
- },
- {
- test: /\.(gif|png|jpe?g)(\?\S*)?$/,
- loader: 'url-loader',
- query: {
- limit: 10000,
- name: path.posix.join('static', '[name].[hash:7].[ext]')
- }
- }
- ]
- },
- plugins: [
- new HtmlWebpackPlugin({
- template: './examples/index.tpl',
- filename: './index.html',
- favicon: './examples/favicon.ico'
- }),
- new CopyWebpackPlugin([
- { from: 'examples/versions.json' }
- ]),
- new ProgressBarPlugin(),
- new webpack.LoaderOptionsPlugin({
- minimize: true,
- vue: {
- preserveWhitespace: false
- }
- })
- ]
- };
- if (isProd) {
- webpackConfig.externals = {
- vue: 'Vue',
- 'vue-router': 'VueRouter'
- };
- webpackConfig.module.rules.push(
- {
- test: /\.vue$/,
- loader: 'vue-loader',
- options: {
- extractCSS: true,
- preserveWhitespace: false
- }
- },
- {
- test: /\.css$/,
- loader: ExtractTextPlugin.extract({
- fallback: 'style-loader',
- use: [
- { loader: 'css-loader', options: { importLoaders: 1 } },
- 'postcss-loader'
- ]
- })
- }
- );
- webpackConfig.plugins.push(
- new webpack.optimize.UglifyJsPlugin({
- compress: {
- warnings: false
- },
- output: {
- comments: false
- },
- sourceMap: false
- }),
- new ExtractTextPlugin({
- filename: '[name].[contenthash:7].css'
- }),
- new webpack.DefinePlugin({
- 'process.env.NODE_ENV': JSON.stringify('production')
- }),
- new webpack.optimize.CommonsChunkPlugin({
- name: ['element-ui', 'manifest']
- })
- );
- }
- if (isDev) {
- webpackConfig.module.rules.push(
- {
- test: /\.vue$/,
- loader: 'vue-loader',
- options: {
- preserveWhitespace: false
- }
- },
- {
- test: /\.css$/,
- loaders: ['style-loader', 'css-loader', 'postcss-loader']
- }
- );
- webpackConfig.plugins.push(
- new webpack.HotModuleReplacementPlugin(),
- new webpack.NamedModulesPlugin(),
- new webpack.DefinePlugin({
- 'process.env.NODE_ENV': JSON.stringify('development')
- })
- );
- }
- module.exports = webpackConfig;
|