1 | let webpack = require('webpack');
|
2 |
|
3 | process.traceDeprecation = false;
|
4 | process.noDeprecation = true;
|
5 |
|
6 | var pages = require('./plugins/entryFile').getEntryFile().pages;
|
7 |
|
8 | const babelOptions = {
|
9 | presets: [
|
10 | require('babel-preset-env'),
|
11 | require('babel-preset-stage-0'),
|
12 | ],
|
13 | plugins: [
|
14 |
|
15 | require('babel-plugin-syntax-dynamic-import'),
|
16 | require("babel-plugin-transform-class-properties"),
|
17 |
|
18 | require('babel-plugin-syntax-jsx'),
|
19 | require('babel-plugin-transform-vue-jsx')
|
20 | ],
|
21 | compact: 'auto',
|
22 |
|
23 | babelrc:false,
|
24 |
|
25 |
|
26 | };
|
27 |
|
28 |
|
29 |
|
30 |
|
31 | var entryArr = {};
|
32 | if (pages && pages.length > 0) {
|
33 | pages.forEach(function (page) {
|
34 |
|
35 | let entry = {};
|
36 | let key = pages.length == 1 && pages[0] == 'index' && light.options.page != 'index' ? 'app' : page;
|
37 | let mainjs = page == 'index' ? 'app' : page;
|
38 | entry[key] = [`${light.config.dist}/view/${page}.js`];
|
39 |
|
40 |
|
41 | const appFile = `${light.config.dist}/${mainjs}.js`;
|
42 | if(light.util.existsSync(appFile)){
|
43 | entry[key].push(appFile);
|
44 | }
|
45 | entryArr = Object.assign(entryArr, entry)
|
46 | })
|
47 | }
|
48 |
|
49 | let imghash = light.config.plugins && light.config.plugins.toString().indexOf('cachemanifest') > -1;
|
50 |
|
51 | let config = {
|
52 | entry: entryArr,
|
53 | module: {
|
54 | rules: [
|
55 | {
|
56 | test: /\.(less|css)$/,
|
57 | use: [{
|
58 | loader: "style-loader"
|
59 | }, {
|
60 | loader: "css-loader"
|
61 | }, {
|
62 | loader: "less-loader"
|
63 | }]
|
64 | },
|
65 | {
|
66 | test: /\.js$/,
|
67 |
|
68 | exclude: process.env.NODE_ENV === "dev" ? [function (file) {
|
69 | return /(node_modules\/[^(olight)]|bower_components)/ig.test(file)
|
70 | }] : undefined,
|
71 | loader: 'babel-loader',
|
72 | options:babelOptions
|
73 |
|
74 | },
|
75 | {
|
76 | test: /\.(png|jpg|gif|svg|ttf|woff|eot|otf)$/,
|
77 | loader: 'file-loader',
|
78 | options: {
|
79 | name: imghash ? 'lightdist/[name].[ext]' : 'lightdist/[name].[ext]?[hash]'
|
80 | }
|
81 | }
|
82 | ]
|
83 | },
|
84 | resolve: {
|
85 | extensions: ['.js', '.vue', '.json'],
|
86 | modules: [`${__dirname}/node_modules`, "lib/node_modules", "lib", "node_modules",`${__dirname}/..`],
|
87 | alias: {
|
88 | "light": `olight`,
|
89 | 'vue': "vue/dist/vue.esm",
|
90 | "@":light.config.dist
|
91 | }
|
92 |
|
93 | },
|
94 | plugins: [
|
95 | new require('progress-bar-webpack-plugin')({
|
96 | format: ' 编译中 [:bar] ' + require("chalk").green.bold(':percent') + ' (:elapsed 秒)',
|
97 | clear: false
|
98 | }),
|
99 | new webpack.NoEmitOnErrorsPlugin(),
|
100 | new (require("./plugins/loader"))({
|
101 | babel: babelOptions
|
102 | })
|
103 | ],
|
104 | resolveLoader: {
|
105 | modules: [`${__dirname}/node_modules`, "lib/node_modules", "lib", "node_modules",`${__dirname}/..`]
|
106 | }
|
107 | };
|
108 |
|
109 |
|
110 | if(!light.options.watch){
|
111 | config.plugins.push(function(){
|
112 | this.plugin("done", function(stats)
|
113 | {
|
114 | if (stats.compilation.errors && stats.compilation.errors.length)
|
115 | {
|
116 | console.log(stats.compilation.errors.toString().red);
|
117 | process.exit(1);
|
118 | }
|
119 | });
|
120 | })
|
121 | }
|
122 |
|
123 | if (light.options.uglify) {
|
124 | config = require("webpack-merge")({
|
125 | plugins: [
|
126 | new webpack.optimize.UglifyJsPlugin({
|
127 | compress: {
|
128 | warnings: false
|
129 | }
|
130 | })
|
131 | ]
|
132 | }, config)
|
133 | }
|
134 |
|
135 | module.exports = config;
|