|
|
@@ -1,6 +1,7 @@
|
|
|
const path = require('path')
|
|
|
const nodeResolve = require('rollup-plugin-node-resolve')
|
|
|
-const { renderBanner, isRelPath, isScssPath, TEMPLATE_PLUGIN, SOURCEMAP_PLUGINS, WATCH_OPTIONS, onwarn } = require('./rollup-util')
|
|
|
+const sass = require('rollup-plugin-sass')
|
|
|
+const { renderBanner, isRelPath, isScssPath, TEMPLATE_PLUGIN, SOURCEMAP_PLUGINS, WATCH_OPTIONS, onwarn, watchSubdirSassIncludes } = require('./rollup-util')
|
|
|
const { pkgStructs } = require('./pkg-struct')
|
|
|
|
|
|
|
|
|
@@ -12,6 +13,7 @@ module.exports = function(isDev) {
|
|
|
|
|
|
function buildPkgConfig(pkgStruct, isDev) {
|
|
|
let banner = renderBanner(pkgStruct.jsonObj)
|
|
|
+ let anyCss = false
|
|
|
|
|
|
return {
|
|
|
input: path.join('tmp/tsc-output', pkgStruct.srcDir, 'main.js'),
|
|
|
@@ -19,15 +21,34 @@ function buildPkgConfig(pkgStruct, isDev) {
|
|
|
file: path.join(pkgStruct.distDir, 'main.js'),
|
|
|
format: 'esm',
|
|
|
banner,
|
|
|
- sourcemap: isDev
|
|
|
+ sourcemap: isDev,
|
|
|
+ intro() {
|
|
|
+ if (anyCss) {
|
|
|
+ return 'import \'./main.css\';'
|
|
|
+ }
|
|
|
+ return ''
|
|
|
+ }
|
|
|
},
|
|
|
external(id) {
|
|
|
- return !isRelPath(id) || isScssPath(id)
|
|
|
+ return !isRelPath(id)
|
|
|
},
|
|
|
plugins: [
|
|
|
+ watchSubdirSassIncludes,
|
|
|
nodeResolve(),
|
|
|
+ sass({
|
|
|
+ output: true, // to a .css file
|
|
|
+ }),
|
|
|
TEMPLATE_PLUGIN,
|
|
|
- ...(isDev ? SOURCEMAP_PLUGINS : [])
|
|
|
+ ...(isDev ? SOURCEMAP_PLUGINS : []),
|
|
|
+ {
|
|
|
+ resolveId(id) {
|
|
|
+ if (isScssPath(id) && isRelPath(id)) {
|
|
|
+ anyCss = true
|
|
|
+ return { id: path.join(process.cwd(), pkgStruct.srcDir, id), external: false }
|
|
|
+ }
|
|
|
+ return null
|
|
|
+ }
|
|
|
+ }
|
|
|
],
|
|
|
watch: WATCH_OPTIONS,
|
|
|
onwarn
|