Skip to content
This repository was archived by the owner on Oct 22, 2024. It is now read-only.

Commit 1dd4d88

Browse files
committed
修复build.component.js无法使用问题
1 parent 357ebca commit 1dd4d88

File tree

3 files changed

+82
-11
lines changed

3 files changed

+82
-11
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
node_modules/
33
/dist/
4+
/dist-web/
45
npm-debug.log*
56
yarn-debug.log*
67
yarn-error.log*

build/build.component.js

Lines changed: 79 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,90 @@ const rm = require('rimraf')
88
const path = require('path')
99
const chalk = require('chalk')
1010
const webpack = require('webpack')
11+
const merge = require('webpack-merge')
12+
const ExtractTextPlugin = require('extract-text-webpack-plugin')
13+
const OptimizeCSSPlugin = require('optimize-css-assets-webpack-plugin')
14+
const UglifyJsPlugin = require('uglifyjs-webpack-plugin')
1115
const config = require('../config')
12-
const webpackConfig = require('./webpack.prod.conf')
13-
16+
const vueLoaderConfig = require('./vue-loader.conf')
17+
const env = require('../config/prod.env')
1418
const spinner = ora('building for production...')
1519

20+
config.build.assetsRoot = path.resolve(__dirname, '../dist')
1621
config.build.assetsSubDirectory = '/'
1722

18-
// webpackConfig.output = {
23+
function resolve (dir) {
24+
return path.join(__dirname, '..', dir)
25+
}
26+
27+
const webpackBaseConfig = {
28+
output: {
29+
path: config.build.assetsRoot
30+
},
31+
devtool: config.build.productionSourceMap ? config.build.devtool : false,
32+
resolve: {
33+
extensions: ['.js', '.vue', '.json']
34+
},
35+
module: {
36+
rules: [
37+
{
38+
test: /\.vue$/,
39+
loader: 'vue-loader',
40+
options: vueLoaderConfig
41+
},
42+
{
43+
test: /\.js$/,
44+
loader: 'babel-loader',
45+
include: [resolve('src'), resolve('test'), resolve('node_modules/webpack-dev-server/client')]
46+
}
47+
]
48+
},
49+
plugins: [
50+
new webpack.DefinePlugin({
51+
'process.env': env
52+
}),
53+
54+
new UglifyJsPlugin({
55+
uglifyOptions: {
56+
compress: {
57+
warnings: false
58+
}
59+
},
60+
sourceMap: config.build.productionSourceMap,
61+
parallel: true
62+
}),
63+
64+
new ExtractTextPlugin({
65+
filename: `css/vue-bootstrap-selectpicker.min.css`,
66+
allChunks: true
67+
}),
1968

20-
// }
69+
new OptimizeCSSPlugin({
70+
cssProcessorOptions: config.build.productionSourceMap
71+
? { safe: true, map: { inline: false } }
72+
: { safe: true }
73+
})
74+
]
75+
}
76+
const webpackConfig = [
77+
merge(webpackBaseConfig, {
78+
entry: path.resolve(`./src/components/SelectPicker.vue`),
79+
output: {
80+
filename: 'js/vue-bootstrap-selectpicker.js',
81+
library: 'SelectPicker',
82+
libraryTarget: 'window'
83+
}
84+
}),
85+
merge(webpackBaseConfig, {
86+
entry: path.resolve(`./src/components/index.js`),
87+
output: {
88+
filename: 'js/vue-bootstrap-selectpicker.min.js',
89+
library: 'select-picker',
90+
libraryTarget: 'umd',
91+
umdNamedDefine: true
92+
}
93+
})
94+
]
2195

2296
spinner.start()
2397

@@ -39,10 +113,6 @@ rm(path.join(config.build.assetsRoot, config.build.assetsSubDirectory), err => {
39113
process.exit(1)
40114
}
41115

42-
console.log(chalk.cyan(' Build complete.\n'))
43-
console.log(chalk.yellow(
44-
' Tip: built files are meant to be served over an HTTP server.\n' +
45-
' Opening index.html over file:// won\'t work.\n'
46-
))
116+
console.log(chalk.green(' Build complete.\n'))
47117
})
48118
})

config/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ module.exports = {
4545

4646
build: {
4747
// Template for index.html
48-
index: path.resolve(__dirname, '../dist/index.html'),
48+
index: path.resolve(__dirname, '../dist-web/index.html'),
4949

5050
// Paths
51-
assetsRoot: path.resolve(__dirname, '../dist'),
51+
assetsRoot: path.resolve(__dirname, '../dist-web'),
5252
assetsSubDirectory: 'static',
5353
assetsPublicPath: '/',
5454

0 commit comments

Comments
 (0)