UNPKG

5.06 kBJavaScriptView Raw
1const path = require('path')
2
3const ExtractTextPlugin = require('extract-text-webpack-plugin')
4
5const { resolveCwd } = require('./lib/utils')
6
7const getAssetsPath = (_path, config) => {
8 return resolveCwd(config.assetsSubDirectory, _path)
9}
10const resolveCur = function (...p) {
11 return path.resolve(__dirname, ...p)
12}
13
14const getCssLoaders = (env, inVue) => {
15 let styleLoader = inVue ? 'vue-style-loader' : 'style-loader'
16
17 if (env === 'production') {
18 return ExtractTextPlugin.extract({
19 fallback: styleLoader,
20 use: ['css-loader',{
21 loader: 'postcss-loader',
22 options: {
23 config: {
24 path: path.posix.join(__dirname, 'postcss.config.js')
25 },
26 plugins: (loader) => [
27 require('autoprefixer')()
28 ]
29 }
30 }, 'sass-loader']
31 })
32 } else {
33 return [styleLoader, 'css-loader', {
34 loader: 'postcss-loader',
35 options: {
36 config: {
37 path: path.posix.join(__dirname, 'postcss.config.js')
38 },
39 plugins: (loader) => [
40 require('autoprefixer')()
41 ]
42 }
43 }, 'sass-loader']
44 }
45}
46
47module.exports = function (config) {
48 const env = JSON.parse(config.env.NODE_ENV)
49 const tofurc = require('../lib/get-config')()
50 let entries = {
51 app:resolveCwd('src/main.js'),
52 vendor:['vue','vue-router','vuex','vue-moment','es6-promise'],
53 tofu:['i-tofu','tofu-http']
54 }
55
56 let eslintRules = require('./rules')
57 if (tofurc) {
58 if(tofurc.rules){ // enlint规则
59 eslintRules = Object.assign({}, eslintRules, tofurc.rules)
60 }
61
62 if(tofurc.entries){
63 entries = Object.assign({},entries,tofurc.entries);
64 }
65 }
66 // 配置 ESLint 忽略的文件
67 const eslintIgnore = []
68 if (tofurc.eslint && tofurc.eslint.ignore) {
69 tofurc.eslint.ignore.forEach(p => {
70 eslintIgnore.push(path.join('src', p))
71 })
72 }
73
74 return {
75 entry:entries,
76 output: {
77 path: resolveCwd('dist'),
78 filename: '[name].js',
79 chunkFilename: '[name].js',
80 publicPath: config.assetsPublicPath,
81 // library: 'dataAnalysis',
82 // libraryTarget: 'window'
83 },
84 resolveLoader: {
85 modules: [resolveCur("../node_modules"), "node_modules"]
86 },
87 resolve: {
88 modules: [resolveCur("../node_modules"), "node_modules"],
89 extensions: ['.js', '.vue', '.json'],
90 alias: {
91 'vue$': 'vue/dist/vue.common.js'
92 }
93 },
94 module: {
95 rules: [
96 {
97 test: /\.(vue|js(x)?)$/,
98 enforce: 'pre',
99 loader: 'eslint-loader',
100 include: [resolveCwd('src')],
101 options: {
102 ignorePattern: eslintIgnore,
103 formatter: require("eslint-friendly-formatter"),
104 useEslintrc: false,
105 parser: 'babel-eslint',
106 parserOptions: {
107 sourceType: 'module'
108 },
109 env: ['browser'],
110 plugins: [
111 'html'
112 ],
113 rules: eslintRules
114 }
115 },
116 {
117 test: /\.vue$/,
118 loader: 'vue-loader',
119 options: {
120 loaders: {
121 scss: getCssLoaders(env, true)
122 }
123 }
124 },
125 {
126 test: /\.(css|scss)$/,
127 use: getCssLoaders(env)
128 },
129 {
130 test: /\.js(x)?$/,
131 exclude: /node_modules/,
132 use: {
133 loader: 'babel-loader'
134 }
135 },
136 {
137 test: /\.html$/,
138 exclude: [resolveCwd('template.html')],
139 loader: 'vue-html-loader'
140 },
141 {
142 test: /\.(png|jpe?g|gif|svg)(\?.*)?$/,
143 loader: 'url-loader',
144 options: {
145 limit: 10000,
146 name: 'static/img/[name].[hash:7].[ext]'
147 }
148 },
149 {
150 test: /\.(woff2?|eot|ttf|otf)(\?.*)?$/,
151 loader: 'url-loader',
152 options: {
153 limit: 10000,
154 name: 'static/font/[name].[hash:7].[ext]'
155 }
156 }
157 ]
158 }
159 }
160}