Skip to content

Commit 1f3a7af

Browse files
committed
feat: add insertVendor
1 parent 109b808 commit 1f3a7af

File tree

6 files changed

+43
-24
lines changed

6 files changed

+43
-24
lines changed

.syncignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{**/*.js.map,**/node_modules/**,src/**,package.json,package-lock.json,**/build/**,**/config/**,**/static/**,**/test/**,**/widget/**,postcss.config.js,README.md}
1+
{**/*.js.map,**/node_modules/**,src/**,package.json,package-lock.json,**/build/**,**/config/**,**/static/**,**/test/**,**/widget/**,**/dist/**,postcss.config.js,README.md}

build/generate.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,16 @@ const INDEXFILE = resolve('index.html')
1212
const CONFIGXML = resolve('config.xml')
1313
const TO = resolve('widget')
1414

15+
16+
function insertVendor() {
17+
const cssVendor = `<link href=./static/css/vendor.css rel=stylesheet>`
18+
const jsVendor = `<script type=text/javascript src=./static/js/vendor.js></script>`
19+
glob.sync(`${FROME}/*.html`).forEach((pathname) => {
20+
let tempContent = fs.readFileSync(pathname).toString();
21+
fs.writeFileSync(pathname, tempContent.replace(/<link/, `${cssVendor}<link`).replace(/<script/, `${jsVendor}<script`))
22+
})
23+
}
24+
1525
function getSource () {
1626
let source = []
1727
let dir = []
@@ -26,6 +36,7 @@ function getSource () {
2636
}
2737

2838
function copyFile() {
39+
insertVendor()
2940
let { source, dir } = getSource()
3041
dir.forEach(e => fs.mkdirSync(`${TO}${e}`))
3142
source.forEach(e => fs.copyFileSync(e.path, `${TO}${e.name}`))

build/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ exports.cssLoaders = function (options) {
6363
postcss: generateLoaders(),
6464
less: generateLoaders('less'),
6565
sass: generateLoaders('sass', { indentedSyntax: true }),
66-
// scss: generateLoaders('sass'),
66+
scss: generateLoaders('sass'),
6767
// stylus: generateLoaders('stylus'),
6868
// styl: generateLoaders('stylus')
6969
}

build/webpack.dev.conf.js

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,19 @@ const devWebpackConfig = merge(baseWebpackConfig, {
3030
devServer: {
3131
clientLogLevel: 'warning',
3232
historyApiFallback: {
33-
rewrites: [{
34-
from: /.*/,
35-
to: path.posix.join(config.dev.assetsPublicPath, 'index.html')
36-
}]
33+
rewrites: [
34+
{ from: /.*/, to: path.posix.join(config.dev.assetsPublicPath, 'index.html') }
35+
]
3736
},
3837
hot: true,
3938
contentBase: false, // since we use CopyWebpackPlugin.
4039
compress: true,
4140
host: HOST || config.dev.host,
4241
port: PORT || config.dev.port,
4342
open: config.dev.autoOpenBrowser,
44-
overlay: config.dev.errorOverlay ?
45-
{
46-
warnings: false,
47-
errors: true
48-
} :
49-
false,
43+
overlay: config.dev.errorOverlay
44+
? { warnings: false, errors: true }
45+
: false,
5046
publicPath: config.dev.assetsPublicPath,
5147
proxy: config.dev.proxyTable,
5248
quiet: true, // necessary for FriendlyErrorsPlugin
@@ -63,11 +59,13 @@ const devWebpackConfig = merge(baseWebpackConfig, {
6359
filename: utils.assetsPath('[name].css')
6460
}),
6561
// copy custom static assets
66-
new CopyWebpackPlugin([{
67-
from: path.resolve(__dirname, '../static'),
68-
to: config.dev.assetsSubDirectory,
69-
ignore: ['.*']
70-
}])
62+
new CopyWebpackPlugin([
63+
{
64+
from: path.resolve(__dirname, '../static'),
65+
to: config.dev.assetsSubDirectory,
66+
ignore: ['.*']
67+
}
68+
])
7169
]
7270
})
7371

@@ -88,9 +86,9 @@ module.exports = new Promise((resolve, reject) => {
8886
compilationSuccessInfo: {
8987
messages: [`Your application is running here: http://${devWebpackConfig.devServer.host}:${port}`]
9088
},
91-
onErrors: config.dev.notifyOnErrors ?
92-
utils.createNotifierCallback() :
93-
undefined
89+
onErrors: config.dev.notifyOnErrors
90+
? utils.createNotifierCallback()
91+
: undefined
9492
}))
9593

9694
resolve(devWebpackConfig)

build/webpack.prod.conf.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const webpackConfig = merge(baseWebpackConfig, {
2525
devtool: config.build.productionSourceMap ? config.build.devtool : false,
2626
output: {
2727
path: config.build.assetsRoot,
28-
filename: utils.assetsPath('js/[name].[chunkhash].js')
28+
filename: utils.assetsPath('js/[name].js')
29+
// filename: utils.assetsPath('js/[name].[chunkhash].js')
2930
// chunkFilename: utils.assetsPath('js/[id].[chunkhash].js')
3031
},
3132
optimization: {
@@ -54,7 +55,8 @@ const webpackConfig = merge(baseWebpackConfig, {
5455
}),
5556
// extract css into its own file
5657
new MiniCssTextPlugin({
57-
filename: utils.assetsPath('css/[name].[contenthash].css')
58+
filename: utils.assetsPath('css/[name].css')
59+
// filename: utils.assetsPath('css/[name].[contenthash].css')
5860
}),
5961
// Compress extracted CSS. We are using this plugin so that possible
6062
// duplicated CSS from different components can be deduped.

config/index.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@
33
// see http://vuejs-templates.github.io/webpack for documentation.
44

55
const path = require('path')
6+
const glob = require('glob')
7+
function getHtmlName() {
8+
let html = []
9+
glob.sync(path.resolve(__dirname, '../node_modules/.temp/*.js')).forEach((pathname) => {
10+
html.push(path.resolve(__dirname, pathname.replace(/[\S\s]*\/.temp/g, '../dist').replace(/\.js$/, '.html')))
11+
})
12+
return html
13+
}
614

715
module.exports = {
816
dev: {
@@ -45,12 +53,12 @@ module.exports = {
4553

4654
build: {
4755
// Template for index.html
48-
index: path.resolve(__dirname, '../dist/index.html'),
56+
index: getHtmlName(),
4957

5058
// Paths
5159
assetsRoot: path.resolve(__dirname, '../dist'),
5260
assetsSubDirectory: 'static',
53-
assetsPublicPath: '',
61+
assetsPublicPath: './',
5462

5563
/**
5664
* Source Maps

0 commit comments

Comments
 (0)