UNPKG

m-vue-tpl

Version:

a command line to generate vue project structure automatically

114 lines (109 loc) 3.08 kB
const path = require('path') const VueLoaderPlugin = require('vue-loader/lib/plugin') const utils = require('./utils') const config = require('../config') const isDev = process.env.NODE_ENV === 'development' function resolve(dir) { return path.join(__dirname, '..', dir) } // create eslint rule const createLintingRule = () => ({ test: /\.(js|vue)$/, loader: 'eslint-loader', enforce: 'pre', include: [resolve('src'), resolve('test')], options: { // print error log more friendly, // but I find it unnecessary. // formatter: require('eslint-friendly-formatter'), // print error log onto the web page(just console.log) so the application is not interrupted // error level: warning emitWarning: !config.dev.showEslintErrorsInOverlay } }) module.exports = { context: path.resolve(__dirname, '../'), entry: path.resolve(__dirname, '../src/index.js'), output: { path: config.build.assetsRoot, filename: 'bundle.js', // publicPath will be added to every resources path as a prefix publicPath: isDev ? config.dev.assetsPublicPath : config.build.assetsPublicPath }, resolve: { // resolve file extension automatically extensions: ['.js', '.vue', '.json'], alias: { '@': resolve('src'), 'assets': resolve('src/assets'), 'components': resolve('src/components'), 'base': resolve('src/base') } }, module: { rules: [ ...(config.dev.useEslint ? [createLintingRule()] : []), { test: /\.vue$/, loader: 'vue-loader' }, { test: /\.css$/, use: ['vue-style-loader', 'css-loader'], }, { test: /\.js$/, loader: 'babel-loader', include: [resolve('src'), resolve('test')], exclude: /node_modules/ }, { test: /\.(ico|png|jpe?g|gif|svg)(\?.*)?$/, use: [ { loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('images/[name].[hash:7].[ext]') } }, ] }, { test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/, loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('medias/[name].[hash:7].[ext]') } }, { test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/, use: [ { loader: 'url-loader', options: { limit: 10000, name: utils.assetsPath('fonts/[name].[hash:7].[ext]') } }, // { // ... other loaders, such as compression // } ] } ] }, plugins: [ // DefinePlugin allow you inject some variables in js environment so that you can call it in js, // but in webpack 4, it doesn't need to specific evidently and it will inject automatically // new webpack.DefinePlugin({ // 'process.env': { // NODE_ENV: isDev ? '"development"' : '"production"' // } // }), new VueLoaderPlugin() ], }